Every time I've tried to be brutal to OpenGL it still manages to do what I want. So far I'm impressed.
My next attempt is trying to write to my own buffer (like an old DirectDraw software rasterizer). Please note I have no professional intentions of writing this way, but just want to see if it works.
GLubyte *back_buffer = new GLubyte[1280 * 800 * 32]; // 32-bit color back buffer in software
My stupid draw function
void drawPixel(const int x, const int y)
{
back_buffer[y * SCREEN_WIDTH + x] = 0xFF; // draw something white here
}
Then, while rendering...
// write to software double buffer
glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, back_buffer);
// draw to the buffer
for (int i = 0; i < 1000; i++)
drawPixel(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT);
// throw the buffer onto the color buffer
glRasterPos2f(0.0f, 0.0f);
glDrawPixels(SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, back_buffer);
Why am I getting a blank screen?