Problem with glClear...

Started by
5 comments, last by Landsknecht 22 years, 3 months ago
I am reading the Prima book now and am having a heck of a difficulty. I am working on the first example that uses OGL. All it does is put a rotating triangle on the screen. I am using asserts sprinkled around the code to test stuff. Ecerything works just fine except the frame rate is avout 1 frame every 2-3 seconds... When I profiled the code - it seems the bottleneck is the glClear call... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Why would that call take up SO much time? I mean, this call is made at least once per frame, right? Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
Advertisement
glClear isn''t exactly free, but it shouldn''t cause that kind of slowdown unless something else is wrong. What video card do you have? Have you modified any of the pixel format code?
It does kill some time. Only solutions I can think of would be to turn your pixel bits down, or not use the depth-buffer and draw your objects from the farthest back to the closest.
If you are drawing to the entire screen/window then you actually don''t need to clear the color buffer.
ah yes, a simpler solution is a new video card or computer hehe
cha cha cha
Nope - aint the hardware...

1.1gHz Thunderbird
GeForce2MX 32mb

I am leaning toward it being a typo in the book. Got the red book and am comparing notes. Thanks for the ideas though.

Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
GOT IT!!! Well, this was kinda silly. I was trying to pull the OGL code out into a class... While doing this I didn''t realize that you actually create a second DC for your window. Ending up with one DC that CreateWindowEx returns and another DC that is tweaked by the WGL functions.

I had compacted the 2 DC''s into a single. The bug didn''t rear its head until the code hit the glClear function... I guess it was trying to clear a buffer that did not exist. I changed my code so that I used the DC''s like I was supposed to and it suddenly worked!

Thanks for the response guys!

Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
You can set up your WNDCLASS structure with the CS_OWNDC flag, so then your window will keep the same DC always.

- Pete
I will have to try that. The tutorial on NeHe''s site shows that, but I didn''t know what it was for. Thanks.

Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.

This topic is closed to new replies.

Advertisement