A while back I made some pixely games like this and I used glRectf to do this. I’ll post the exact code below, it’s simple. I remember changing it to vertex arrays later and actually saw a large decrease in performance. I wasn’t sure if this was because I was using FloatBuffers wrong (they were specifically what seemed the slowest to me) or if it’s simply faster to a bunch of rect calls.
Since I’ve done almost all of my more complex OpenGL work within iPhone and have had access to C arrays, I’m a noob when it comes to leveraging float buffers the correct way.
So, what are recommendations for doing this?
GL11.glDisable(GL11.GL_TEXTURE_2D);
//Draw each pixel.
for (int i = 0; i < pixels.length; i++)
{
for (int j = 0; j < pixels[0].length; j++)
{
if (pixels[i][j] >= 0)
{
Color c = Globals.NES_COLOR_PALETTE[pixels[i][j]];
GL11.glColor4ub(c.getRedByte(), c.getGreenByte(), c.getBlueByte(), c.getAlphaByte());
GL11.glRectf((x+i)*scale.x, (y+j)*scale.y, (x+i+1)*scale.x, (y+j+1)*scale.y);
}
}
}
FYI looking at that not sure why I didn’t just do a glScale call beforehand - maybe I had a reason maybe I didn’t.
And in an ideal world, I could draw every single pixel individually, rather than using FBOs or anything to store unchanging values. Sort of like some voxel games (may or may not) do it.