Archived

This topic is now archived and is closed to further replies.

beginner's problem

This topic is 6010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
...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.. =(

Share this post


Link to post
Share on other sites
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 .

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. =)

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Good news! It works now! Yay! I noticed that everything went R E A L L Y slow when I tried the screen.draw() in the loop, and realized it''s ''cause I put it in the wrong spot...hehe.. whoops! But it''s working soundly, now.

Also, if you set the window.hbrBackground to the BLACK_BRUSH, OpenGL *can* still change that value. But I set it back to NULL, just ''cause I''m a scared sissy. =)

Thanks everybody... only a few more months until my engine rivals the power of Wolfenstein... especially with me at the coding helm....

Onward with progress. =)

Share this post


Link to post
Share on other sites