Another day, another long session trying to get something mundane finished. Despite getting decent FPS ( ~300-400 ) I knew that was partially to do with the fact that everything was so simple right now. Once we have more complicated geometry with more entities flying around I expect it will drop like a rock.
And so it was with that in mind that I began converting my terrain rendering from Immediate mode OpenGL commands to Vertex Arrays.
For those of you who do not know, Immediate mode is where, every frame, I spell out every bit of geometry information one piece at a time. Imagine watching a YouTube video without it pre-buffering. The video would stop and studder constantly because it was waiting for YouTube HQ to send each frame one at a time. This is Immediate Mode OpenGL.
Vertex Arrays act more like the buffered YouTube video we all know and love. You go ahead and figure out what you want to draw, then queue it up in an array. Then instead of feeding OpenGL the scene one piece at a time, you just give it the array and let it go to town.
Well, it worked… mostly. I am seeing much faster render times now, sometimes hitting 1000 fps! ( And that’s probably low considering I force the render sequence to wait at least 1 millisecond before starting the next frame. ) However, it isn’t perfect yet: Not all of my faces are pointing the right way ( Damn right handed coordinate system ) and it’s all being rendered with a single texture.
Eh? One texture? Why? Well, it turns out that you can’t swap textures in and out in the middle of a Vertex List. You must draw the whole list with whatever texture you started with.
Fortunately, this should not be a major problem. Every modern video card supports textures up to 2048×2048, so I can combine all my tile textures ( which are 64×64 ) into a single texture file and just adjust the Texture Coordinates u and v accordingly. This would give me room for 1024 individual textures! So I guess this is tomorrow night’s work.