OpenGL background color not working

I have a game that I am making but for some reason the background color for OpenGL isn't working.

Code:

Render code (this is in an infinite loop):
1
2
3
4
5
6
7
8
9
10
inline void drawGame_(unsigned long interval) {
	glClearColor(0.0, 0.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glLoadIdentity();

	glFlush();
	HDC* hdc = gethDC();
	SwapBuffers(*hdc);
}


Code that creates the window:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{

   hInst = hInstance;

   hWnd = CreateWindowEx(0, szWindowClass, szTitle, WS_BORDER | 
		WS_SYSMENU | WS_VISIBLE,
		GetSystemMetrics(SM_CXSCREEN)/2-(GAME_WINDOW_WIDTH/2),
		GetSystemMetrics(SM_CYSCREEN)/2-(GAME_WINDOW_HEIGHT/2),
		GAME_WINDOW_WIDTH, GAME_WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


Enable OpenGL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;

    *hDC = GetDC( hWnd );

    ZeroMemory( &pfd, sizeof( pfd ) );
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
                  PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    iFormat = ChoosePixelFormat( *hDC, &pfd );
    SetPixelFormat( *hDC, iFormat, &pfd );

    *hRC = wglCreateContext( *hDC );
    wglMakeCurrent( *hDC, *hRC );
}


All this shows is a black screen even though it should be a blue screen because of glClearColor(0.0, 0.0, 1.0, 1.0);

Any ideas why it is only showing a black screen?
We need to see more of your program. We don't know what order you're calling these functions in, if or when your lpfnWndProc callback is calling your "drawgame__()" function. I want to assume that hWnd is global, but why then are you passing it into your "EnableOpenGL()" function? There are a few more confusing things that need to be cleared up.
I believe when you use glClearColor(0.0,0.0,1.0,1.0); it using RGBA try putting alpha to 0.0
Topic archived. No new replies allowed.