PDA

View Full Version : Flickering when my polygon is drawn



Jordan Eng
06-24-2004, 08:04 PM
When I compile the following code in VC++ under Windows XP my polygon flickers constantly as it is being drawn. Any suggestions?


#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

void DrawScene()
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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();
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;

auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
auxInitPosition (0, 0, 500, 500);
auxInitWindow ("moo");

while(GetMessage(&amp;Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&amp;Msg);
DispatchMessage(&amp;Msg);

if(Msg.wParam == WM_QUIT)
{
return 0;
}
else
{
DrawScene();
}
}
return Msg.wParam;
}All help is greatly appreciated, I know this seems like a beginner question, but I thought the problem might be with my windows implementation.

It only flickers when I do something like moving the cursor.

plasmonster
06-24-2004, 09:43 PM
Try a double buffer:
auxInitDisplayMode (AUX_DOUBLE | AUX_RGBA);

With a single buffer, you get to watch the frame's construction (interesting, but unsightly).

Also, I suggest you prefer GLUT over the antiquated AUX. You can grab it here

http://www.xmission.com/~nate/glut.html

Jordan Eng
06-25-2004, 10:44 PM
Ah, I just went through GLUT, this is great. Thanks for the help!