Beginning problem with vc++ and opengl

Started by
2 comments, last by Brother Bob 17 years, 5 months ago
Hey guys, ive got vc++ 6.0 and im using their opengl libraries...i created a new win32 app (as per Genesis I : Windows Game Programming guide) but im having trouble drawing anything to the screen...the window shows up fine and all the menu funtionality works ( set up pixel format, proper window styles for opengl, the rendering context ect), but all my gl function calls dont show up in the window..someone take a look please, thanks! I haave the main loop going infinitly, and as long as there is no message in the queue, I draw a scene, something like this (in main):

while (!done) {
   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
      if (msg.message == WM_QUIT) {
         done = TRUE;
      } else {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   } else {
      //printf("Hello, World!");
      DrawScene();
   }
}

and DrawScene is like:

glClearColor(0.0, 0.0, 1.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 

	glBegin(GL_POLYGON);
	glVertex2f(-0.5, -0.5);
	glVertex2f(-0.5, 0.5);
	glVertex2f(0.5, 0.5);
	glVertex2f(0.5, -0.5);
	glEnd();

	glFlush();

why isn't anything showing up? [Edited by - dj_unforgetable on November 18, 2006 10:59:53 PM]
Advertisement
don't forget to call SwapBuffers(HDC) at the end. u don't need to call glFlush().
Why do I need to swap buffers if im only drawing a single frame?
But you said in your first post you draw the scene over and over again as long as there are no other messages in the loop. That means you're drawing it several times, not just once.

But then again, swapping buffers have nothing to do whether you're only drawing a single image or not. It has to do whether your application is double buffered, and to what buffer you draw.

Concider this. You have a front and a back buffer. The front buffer is what's shown on the screen and the back buffer is where you draw. As long as you're not swapping the buffers, what you draw will always be in the back buffer. Swap the buffers and the back buffer is now the front buffer.

So if you requested a double buffered pixel format, you must swap buffers no matter how many, or few, images you draw.

This topic is closed to new replies.

Advertisement