Thread: Opengl question

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    51

    Opengl question

    Before I begin I apologize if I put this in the wrong place. But I'm pretty sure that this is the right place.

    Anyways I'm just starting to learn OpenGl and I was wondering about this code.
    Code:
    	glTranslatef(0.0f,0.0f,-6.0f);					// Move Left 1.5 Units And Into The Screen 6.0
    	glBegin(GL_TRIANGLES); // Drawing Using Triangles
    		glColor3f(1.0f,0.0f,0.0f);			// Set The Color To Red
    		glVertex3f( 0.0f, 1.0f, -10.0f);				// Top
    		glVertex3f(-1.0f,-1.0f, -10.0f);				// Bottom Left
    		glVertex3f( 1.0f,-1.0f, -10.0f);				// Bottom Right
    
    		glColor3f(0.0f,1.0f,0.0f);			// Set The Color To green
    		glVertex3f( 0.0f, 1.0f, -10.0f);				// Top
    		glVertex3f(-1.0f,-1.0f, -10.0f);				// Bottom Left
    		glVertex3f( 1.0f,-1.0f, -10.0f);				// Bottom Right
    	glEnd();							// Finished Drawing The Triangle
    Anyways if I understand glTranslate correctly then thats basically the starting point for any drawing you decide to do? So the second part of the code should just cover up the first?

    Thanks for reading this

  2. #2
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    Quote Originally Posted by Shadowwoelf View Post
    Anyways if I understand glTranslate correctly then thats basically the starting point for any drawing you decide to do?
    That's probably the best way to think about it when you're starting out. It's actually a bit more complicated than that, glTranslate shifts the entire coordinate system. Like I said though, for simple cases, think of it as though it moves a cursor that defines where you will draw.

    And yes, the second triangle should cover up the first, unless you have some depth buffer weirdness going on.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    51
    Okay I think I understand Gltranslate finally. So when you change the x position your moving the entire coordinates to that one spot so really when you begin to draw you start at (0,0) even though technically youd be drawing a (1,0). Then with the rotating an object you simply change the point of view your drawing from and not the coordinates. But since you changed point of view you have to reset it using glLoadIdentity so that the other objects wont be affected by how the point of view was changed.

    Is that basically right?

  4. #4
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    Quote Originally Posted by Shadowwoelf View Post
    Okay I think I understand Gltranslate finally. So when you change the x position your moving the entire coordinates to that one spot so really when you begin to draw you start at (0,0) even though technically youd be drawing a (1,0). Then with the rotating an object you simply change the point of view your drawing from and not the coordinates. But since you changed point of view you have to reset it using glLoadIdentity so that the other objects wont be affected by how the point of view was changed.

    Is that basically right?
    Basically, yes.

    What glTranslate, glRotate, and glScale actually do is alter the transformation matrix. The transformation matrix is applied to everything you draw in order to determine how it should appear. glLoadIdentity resets the transformation matrix to an identity matrix, which doesn't modify any of your points. If you've ever done matrix math, some of that should make sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Question
    By Halo3Master in forum Game Programming
    Replies: 16
    Last Post: 10-02-2007, 02:40 AM
  2. OpenGL Camera Question
    By Astra in forum Game Programming
    Replies: 2
    Last Post: 03-25-2007, 01:53 PM
  3. Help me Understand (OpenGL Question)
    By Shamino in forum Game Programming
    Replies: 0
    Last Post: 05-06-2005, 05:29 AM
  4. OpenGL Question
    By Shamino in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2005, 02:35 PM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM