Flickering when my polygon is drawn

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(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&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.

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

Ah, I just went through GLUT, this is great. Thanks for the help!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.