glClearColor() does not work

I’m using mingGW in Windows. The basic code as follows colour is {1, 0, 0 , 1} which should be red. However, when I run my code there is no error but the window just show white.

GL_EXEC(m_fn->m_glClearColor(colour[0], colour[1], colour[2], colour[3]));
GL_EXEC(m_fn->m_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

Here is the default color, I think it should be white by default, just the clearColor doesn’t work.
wc.hbrBackground =
(HBRUSH)(COLOR_WINDOW+1);// Default color

Conditions:

  1. I have created two windows(hWnd)
  2. I have created one hRC, the windows will share hRC by GetDC() and the wglMakeCurrent()
  3. I have load a lot of process address, Fonts, programs and shaders.
  4. This is the beginning of the code, I just created two windows, then I want to glClearColor() on one of them.

What would be wrong in my code?

Have you tried to run it like this?

GL_EXEC(m_fn->m_glClearColor(1.0f, 0.0f, 0.0f, 1.0f));
GL_EXEC(m_fn->m_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

Is your system framebuffer double-buffered? If so, you’ll need to call wglSwapBuffers before you can see what you’ve drawn.

What’s “m_fn”? Is it some kind of wrapper around OpenGL? If so, your problem could be in the implementation of that wrapper.

I have done some experiments on my code, the problem is that when I have only one hRC to share with both hWnd, the second window doesn’t show anything. If I redefine the hRC with hRC = wglCreateContext(hDC) (the hDC is has the same format with previous one) then the second window will do just fine. The order of the code is like below:

hWnd1 = CreateWindow()
hDC1 = GetDC(hWnd1)
hDC1 setup pfd
hRC = wglCreateContext(hDC1)
ReleaseDC(hWnd1,hDC1)
ShowWindo(hWnd1, 5)
GetDC()
MakeCurrent(hDC1, hRC)
ReleaseDC()
Draw()

hWnd2 = CreateWindow()
hDC2 = GetDC(hWnd2)
hDC2 setup pfd

hRC = wglCreateContext(hDC1) //if I redefine here, it will show the cleared color, otherwise, just whit screen

ReleaseDC(hWnd2,hDC2)
ShowWindo(hWnd2, 5)
GetDC()
MakeCurrent(hDC2, hRC)
ReleaseDC()
Draw()

[QUOTE=Hermannicus;1282677]Have you tried to run it like this?

GL_EXEC(m_fn->m_glClearColor(1.0f, 0.0f, 0.0f, 1.0f));
GL_EXEC(m_fn->m_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));

[/QUOTE]

Yes, I have tried. And it still not working. I think it might be something about my createWindow setting. I have update the post. Please have a look.

The m_fn is working fine in Linux, so I assume it will also work on Windows

Yes, after swapBuffer, there still nothing on the window. :frowning:

I have solved the problem by storing one hDC and hWnd per window and only have one hRC. After createWindow, ShowWindow, I set up hDC pfd, then makecurrent before clearcolor. Also after clearColor() I need glFlush()