Jump to content
  • Advertisement

Archived

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

Ronin Magus

OpenGL opengl newb question

This topic is 5896 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 just started going through nehe's opengl tutorials this afternoon. After reading through the first tutorial and getting my window up and running, and reading the second on displaying triangles with much success, I decided to experiment a little bit Anyways, I changed his DrawScene code to:
        

bool DrawScene()
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();

   glTranslatef(x, y, z);

   glBegin(GL_TRIANGLES);
      glVertex3f(0.0, 1.0, 0.0);
      glVertex3f(-1.0, -1.0, 0.0);
      glVertex3f(1.0, -1.0, 0);
   glEnd();

   return true;
}
  
    
Straight out of the second tutorial, except for the addition of X, Y, Z to glTranslatef. Now, in my message handling routine, I added code to change the x value when the left arrow is pressed:
  
            
         if(keys[VK_ESCAPE])
            exitloop = true;
         else if(keys[VK_LEFT])
            x -= .01;
        
I intended to have the left arrow key move the triangle on the screen a smidgeon to the left. However, when I press the left arrow key the triangle disappears entirely. What have I done wrong? Any ideas? I still don't quite understand OpenGL's coordinate system (well I understand geometric coordinate planes but I don't quite understand yet how OpenGL represents/interacts with them) http://roninmagus.hopto.org [edited by - Ronin Magus on July 29, 2002 10:09:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
You're too close to the polygon so it gets snippet out of the scene. Set the z value for your glVertex3f calls to -1.0f to move it back a bit, for example, and you'll see a huge polygon right in front of you. Also, make sure that you've initialised the x,y and z variables to 0.0f.

The original code probably had a translate call in there to move the objects further away before the glBegin call.

EDIT: you can also consider reducing the amount you change x by (for example, to 0.001

[edited by - Alimonster on July 29, 2002 10:16:17 PM]

Share this post


Link to post
Share on other sites
Thank you! But unfortunately that's not the problem, at least in this case.

I tinkered around with it for a little bit, and I was coming back to post my mistake when I saw your post.

It seems the error wasn't in my coordinate placement, but a simple logic error.. I had misplaced an if statement

But it's working great now, and I'm a happy camper!

http://roninmagus.hopto.org

[edited by - Ronin Magus on July 29, 2002 10:26:02 PM]

Share this post


Link to post
Share on other sites
congratulations. welcome to the world of interactive 3d graphics =)

a2k

Share this post


Link to post
Share on other sites

  • 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!