beginner's problem
Hello! I''m working on creating some separate ("generic") files to use for a few projects I have in mind, but have come to a really easy sounding obstacle.
I can''t get the OpenGL window to clear itself or change the background color to black. In fact, whatever is on my screen at the time is what shows up in the OpenGL window. It works pretty much like a "screen capture" utility, but without a save feature...
At any rate, I''m wonder how to overcome that. I have 2 files thus far... The main one for WinMain and for user input (using Win32 stuff), and the other OpenGL class for creating the window and supposedly clearing out the window and making the background black. For a better glimpse at how this is working, this is how I create the actual window from the main file:
screen.makeOGLWindow(WINDOW_TITLE, WIDTH, HEIGHT, COLOR_DEPTH, false, &hWnd, &hdc, &hrc, WndProc);
Anyway... that''s the problem. Window shows up, but it never clears.
Any ideas?
Are you calling glClear(GL_COLOR_BUFFER_BIT); ?
Have you set the clear colour?
Have you set the clear colour?
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
Yeah...I''m calling both:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f,0.0f,0.0f,1.0f);
But for some reason... still doesn''t work.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f,0.0f,0.0f,1.0f);
But for some reason... still doesn''t work.
You need to set the clear color before clearing it, and you have to clear it in the main render loop ibelive.
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
--------------------------
Whats a pretty girl like you doing in a dirty mind like mine?
Those who dance are considered insane by those who cannot hear the music.
...tried setting the color to black first, then clearing...no such luck. The code is loosely based on NeHe''s examples, only in different files. I believe he has something like:
InitGL(); in his function that has CreateWindow(), and it works.
I also call my init() function from the CreateWindow() function, but it doesn''t get the job done.
Here''s the last part of my makeWindow() function:
ShowWindow(*hWnd,SW_SHOW);
SetForegroundWindow(*hWnd);
SetFocus(*hWnd);
initOGLWindow();
My initOGLWindow() does the colors and clearing.... not working.. =(
InitGL(); in his function that has CreateWindow(), and it works.
I also call my init() function from the CreateWindow() function, but it doesn''t get the job done.
Here''s the last part of my makeWindow() function:
ShowWindow(*hWnd,SW_SHOW);
SetForegroundWindow(*hWnd);
SetFocus(*hWnd);
initOGLWindow();
My initOGLWindow() does the colors and clearing.... not working.. =(
Did you set a background brush for your window class? The absence of one usually generates the problem you speak of. Try inserting wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); before you call RegisterClassEx() (if you haven''t) and see the difference. It''s happened to me many times
.

As terminate said, you have to clear for every frame, not only when the window is initialized (e.g. in the Draw() just before putting anything from the current frame on the screen)
"Everything is relative." -- Even in the world of computers.
"Everything is relative." -- Even in the world of computers.
everything is relative. -- even in the world of computers... so PUSH BEYOND THE LIMITS OF SANITY!
quote:
Original post by Oluseyi
Did you set a background brush for your window class? The absence of one usually generates the problem you speak of. Try inserting wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); before you call RegisterClassEx() (if you haven''t) and see the difference. It''s happened to me many times.
Actually, I tried doing that and it worked great... but I didn''t want to do it because I''m not sure if I''ll be able to change the background from black if I do it that way. Can I still change the background using OGL functions if I set the hbrBackground to BLACK_BRUSH?
Thanks for the help everybody. =)
Honestly, I don''t know - I''ve never used OpenGL (I''ll use it soon, so please - no preachments
). However, you can do so with DirectX graphics, so imagine you can with OGL. Give it a try and let''s know what happens.

quote:
Original post by Ionut Costica
As terminate said, you have to clear for every frame, not only when the window is initialized (e.g. in the Draw() just before putting anything from the current frame on the screen)
Hey, I made a draw() function that simply does:
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
and put screen.draw() in the main program loop... it still doesn''t work. Do I need something else if I''m going to do it this way? Setting the .hbrBackground to BLACK_BRUSH seems to do the job, but I''m a little leery of doing it that way... all the example I''ve seen set that background to NULL.
But still... I feel like I''m "close," but even my draw() function in the loop doesn''t fill the window...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement