PDA

View Full Version : glClearColor() does not work



whiack
05-26-2016, 01:53 PM
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?

Hermannicus
05-26-2016, 04:20 PM
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));

Dark Photon
05-26-2016, 08:09 PM
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.

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

mhagain
05-27-2016, 12:47 AM
What's "m_fn"? Is it some kind of wrapper around OpenGL? If so, your problem could be in the implementation of that wrapper.

whiack
05-27-2016, 07:29 AM
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()

whiack
05-27-2016, 07:30 AM
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));

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.

whiack
05-27-2016, 07:31 AM
What's "m_fn"? Is it some kind of wrapper around OpenGL? If so, your problem could be in the implementation of that wrapper.

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

whiack
05-27-2016, 07:32 AM
Is your system framebuffer double-buffered? If so, you'll need to call wglSwapBuffers before you can see what you've drawn.

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

whiack
05-27-2016, 01:13 PM
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()