Double Buffering in OpenGL.
Posted: Fri Aug 27, 2010 10:20 pm
Hey guys,
I'm just starting with OpenGL and am confused on how to actually use double buffering in OpenGL with SDL. The book I'm reading uses GLUT, so that doesn't really help at all. I've looked on teh intrawebz and haven't found anything useful yet.
Here is some code I've got so far (please note it is poorly structured and very ugly, as I am just beginning:D)
Thanks you in advance for any and all help :D
I'm just starting with OpenGL and am confused on how to actually use double buffering in OpenGL with SDL. The book I'm reading uses GLUT, so that doesn't really help at all. I've looked on teh intrawebz and haven't found anything useful yet.
Here is some code I've got so far (please note it is poorly structured and very ugly, as I am just beginning:D)
Code: Select all
include <SDL.h>
#include <SDL_opengl.h>
//coordinate variables
void RenderScene()
{
//Clear windows with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//sets current drawing color to red
glColor3f(1.0f, 0.0f, 0.0f);
//draw a rect w/ current color
glRectf(x1, y1, x2, y2);
SDL_GL_SwapBuffers();
}
void SetupRC()
{
glClearColor(0.6f, 0.4f, 0.7f, 1.0f);
}
int main(int argc, char *argv[])
{
//init stuff
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER);
while(event.type != SDL_QUIT)
{
SDL_PollEvent(&event);
key = SDL_GetKeyState(NULL);
RenderScene();
SetupRC();
//window collision stuff
SDL_Delay(45);
}
SDL_Quit();
return 0;
}