LWJGL 3D Terrain: Modernizing the code
by
, October 5th, 2012 at 02:23 AM (15201 Views)
In my last post I was able to achieve fairly decent results by creating a static display list and off-loading the drawing code to GPU.
There's just one problem: This code utilizes features which are "deprecated" and can only be used when running under a backwards compatibility context. Most notably I'm utilizing the direct mode rendering. Starting with OpenGL 3 (I think it's actually 3.3), OpenGL moved to essentially a purely shader-based model.
So once again, I'm re-writing my code to compensate for the changes. This time the changes are much more significant because basically anything involved with actually drawing stuff has changed. There's no longer the default lighting, default modelview and projection matrices, and as stated before rendering is handled using shaders rather than a direct mode rendering.
So the first question is what is a shader? From what I understand a shader is a small program which runs on the GPU to describe how to render something. It's not as general purpose as CUDA or OpenCL, but it could be thought of as the pre-cursor to these languages (indeed, many early GPU-accelerated computations were implemented using shaders). OpenGL's shader language is known as GLSL which is a C-like programming language.
There are different types of shaders and I'm still trying to work my way through the two most basic ones, vertex shaders and fragment shaders.
Here's the latest screenshot of what I have:
Most of the original functionality is back. The most notable missing feature is lighting and shadows. I'm planning on implementing Phong Lighting to provide fairly decent results while still being simple and computationally fast. Once again the color mapping has changed.
Another point is I took a performance hit when porting over to shader-based rendering (1024x1024 height map being used again). I'm not too worried at this point because it's still decently fast and I haven't really spent any time optimizing my render code.