Jump to content
  • Advertisement
Sign in to follow this  

[OpenGL] glRotatef causing rendering errors?

This topic is 3891 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

Hi, I have what seems a very simple problem, and am a total OpenGL beginner, so be gentle :-) To learn the basics, I have a class (C++) which draws a cube. I then create multiple instances of this class (currently < 10) to position cubes around the 3D space with different colors, lighting properties and rotations. My problem is with rotation - as soon as I add what I think is the proper rotation code, I get random/intermittent rendering bugs (most often in that some cubes aren't displayed at all). My setup code is:
   glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
   //allow the native colour of polygons to be shown under lighting
   glEnable (GL_COLOR_MATERIAL);

And my code looks like this for each render pass:
   glFrustum(-1 * aspectRatio, 1 * aspectRatio, -1, 1, 1, 1000);

   //translate everything "into" the screen...

   //iterate through the cube instances, calling their render routines (see below)...
   SwapBuffers (*hDC);

A cube's rendering process looks like this:
   //so it rotates our cube around the cube's centre, not the screen centre, translate to our drawing position, then draw the cube centred
   //3 rotation factors, for x, y and z
   glRotatef(xRotation, 1.0f, 0.0f, 0.0f);
   glRotatef(yRotation, 0.0f, 1.0f, 0.0f);
   glRotatef(zRotation, 0.0f, 0.0f, 1.0f);
   glColor3f(redAmount, greenAmount, blueAmount);
   //draw cube...



But, as I said, as soon as I add the above glRotatef rotation code, I get intermittent and seemingly random rendering errors, like things disappearing entirely, or even the background ("clear color") changing color. Comment it out and everything's fine again. I figure it's not glRotatef on its own which is causing this, so am I doing something hugely wrong here? PS: The rotation does actually "work", when it's possible to see it, so the cubes are rotated to the correct angles.

Share this post

Link to post
Share on other sites
I just started having this issue as well. Oddly enough, the same code compiles and runs fine on my OS X machine- i get funky behavior only when using VC++ 2005. Also, if i switch from the Release to Debug configuration in VC++ the behavior goes away, but my objects do not rotate properly anymore.

Share this post

Link to post
Share on other sites
Are you defining any lights at all? If not, you shouldn't enable lighting.

Apart from that, your code looks fine... I don't know if lighting could cause such bugs.

Share this post

Link to post
Share on other sites
I did indeed define one light - apologies for not including that code, but since the errors only started once I introduced the rotation, I assumed that was not the problem. I've tried removing all the lighting code, and it still does weird things....

If I was getting this kind of behaviour in non-OpenGL program logic, I'd be looking for some kind of memory issue like a bad pointer, but since it only affects the OpenGL display, I'm confused.

Detroit's comment made me wonder if my compiler was doing something screwy, so I checked that out, and I'm fairly sure it's not to blame.

Anyway, it's helpful to know that my code appears correct to someone with more knowledge on this than me [grin] I'll go for some more violent debugging on it...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!