Jump to content
  • Advertisement
Sign in to follow this  
AdamGL

OpenGL Beginner's question

This topic is 4869 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 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?

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Here is what it looks like at around 20 degrees
Image hosted by Photobucket.com

And here when it is more than 20 degrees
Image hosted by Photobucket.com

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.

Share this post


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

Share this post


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

Share this post


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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!