Beginner's question
Hi guys. I'm fairly new to OpenGL and I drew Myself a cube with only the front and top sides drawing. I have an l-shaped object. When I rotate it(viewing the front only, rotating along the x-axis), the top shows until the two sides seperate. Any Ideas?
Show us the code where you are drawing it, and, if you can, upload a screen shot of it to somewhere and link it to here.
Are you using glOrtho or gluPerspective? Either way increase your near far planes. e.g. 1.0 and 100.0. Other than seeing code thats my best guess.
I agree. Show us some code, and remember to use the source tags: [ source][ /source]. Just remove the spaces because otherwise you would see the box instead...
P.S. And yes, an image would help too.
P.S. And yes, an image would help too.
Here is what it looks like at around 20 degrees
And here when it is more than 20 degrees
source code:
That's about it. Any suggestions.
And here when it is more than 20 degrees
source code:
void Quad(TEXTURECOORD TexCoord){ glColor3f(0.2f, 0.2f, 1.0f); glBegin(GL_QUADS); glTexCoord2fv(TexCoord.Coord1); glVertex3f(-0.5f, -0.5f, 0.5f); glTexCoord2fv(TexCoord.Coord2); glVertex3f(0.5f, -0.5f, 0.5f); glTexCoord2fv(TexCoord.Coord3); glVertex3f(0.5f, 0.5f, 0.5f); glTexCoord2fv(TexCoord.Coord4); glVertex3f(-0.5f, 0.5f, 0.5f); glColor3f(0.2f, 1.0f, 0.2f); glTexCoord2fv(TexCoord.Coord1); glVertex3f(-0.5f, 0.5f, -0.5f); glTexCoord2fv(TexCoord.Coord2); glVertex3f(-0.5f, 0.5f, 0.5f); glTexCoord2fv(TexCoord.Coord3); glVertex3f(0.5f, 0.5f, 0.5f); glTexCoord2fv(TexCoord.Coord4); glVertex3f(0.5f, 0.5f, -0.5f); glEnd();}void DrawQuad(TEXTURECOORD TexCoord, float x, float y, float scalex, float scaley){ glPushMatrix(); glTranslatef(x, y, 0.0f); glScalef(scalex, scaley, 50.0f); Quad(TexCoord); glPopMatrix();}void RenderTerrain(){ TEXTURECOORD TexCoord; glDisable(GL_TEXTURE_2D); glColor3f(1.0f, 0.2f, 0.2f); glPushMatrix(); glRotatef(rot, 1.0f, 0.0f, 0.0f); DrawQuad(TexCoord, 512.0f, 50.0f, 1024.0f, 100.0f); glPopMatrix(); glColor3f(1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_2D);}
That's about it. Any suggestions.
It's hard to tell from that description. One issue is whether you have a depth buffer and have it enabled. If you don't check for errors then you can enable a depth buffer that doesn't exist. An example is requesting a 32 bit buffer when the card only supports 24 bit buffers. Depth buffer issues are going to screw with what appears in front of what. No depth buffer means what you draw overlays what was already there. So that back of the object can appear in front of the front of the object because the back was drawn last.
Then you have culling which has to be specifically enabled. If you enable back face culling, but don't pay attention to your winding then you'll have polygons appear and disappear and seemingly odd times. It can get very confusing to tell what is going on as you rotate an object since if all you can see is the interior of the object it is hard to tell a polygon is missing. Easiest is to just turn off the backface culling and see if it draws right. If it does then set up the keyboard to toggle drawing individual polygons. Figure out which polygons and reverse the order of the vertices for those polygons.
Another is as mentioned above rotating part of the object out of the view frustum. Easiest way to tell that is move the far plane out to like 1000.0 and set the keyboard up so you can zoom in and out. If it's clipping on the near plane or the sides close to the near plane then backing the camera away from the object is about the only thing you can do.
Beyond that any number of errors can cause any number of problems. So there is error checking. Luckily the way OpenGL does errors is that once set an error stays set until read. So you can do sort of a binary search to find just which function is actually failing. There is also a program called GL Intercept that will hook the dll, log the calls made and whether any errors occured in the call. You can download it from GLIntercept.
Then you have culling which has to be specifically enabled. If you enable back face culling, but don't pay attention to your winding then you'll have polygons appear and disappear and seemingly odd times. It can get very confusing to tell what is going on as you rotate an object since if all you can see is the interior of the object it is hard to tell a polygon is missing. Easiest is to just turn off the backface culling and see if it draws right. If it does then set up the keyboard to toggle drawing individual polygons. Figure out which polygons and reverse the order of the vertices for those polygons.
Another is as mentioned above rotating part of the object out of the view frustum. Easiest way to tell that is move the far plane out to like 1000.0 and set the keyboard up so you can zoom in and out. If it's clipping on the near plane or the sides close to the near plane then backing the camera away from the object is about the only thing you can do.
Beyond that any number of errors can cause any number of problems. So there is error checking. Luckily the way OpenGL does errors is that once set an error stays set until read. So you can do sort of a binary search to find just which function is actually failing. There is also a program called GL Intercept that will hook the dll, log the calls made and whether any errors occured in the call. You can download it from GLIntercept.
The problem is that the near clipping of viewport is too far and or the cube it too close to the camera, move the cube a little away from camera and the gap will disappear, i saw this happen in many games (last time in far cry when swimming in water), just set the near clipping value where you use GLUPerspective to zero or less until the gap disappears.
If it is near plane clipping then definately move the cube away from the camera, dont set the near clipping plane to 0 or negative. It at least has to be a positive number. The larger the more precise the buffer. Basicaly, you want to set the near plane as far away from the camera (higher positive numbers) as possible with out clipping scene objects.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement