Advertisement

slight modification to nehes tutorial 2

Started by October 23, 2000 02:40 PM
3 comments, last by baldurk 24 years, 1 month ago
I have slightly modified NeHes OpenGL tutorial 2 I have tried to add another square, adding in a glTranslate statement to make sure I don`t just draw over the square that is already there and it doesn`t work, I don`t get! it compiles fine but doesn`t draw anything! I have (in case you are wondering) just copied the glBegin(), glVertex3f() and glEnd() statements from the code for the original square, changing the coordinates appropriately. I am a newbie OpenGL programmer. Is there anything obviously wrong? please help me Thanks
"changing the coordinates appropriately" ?
Not sure I understand but if you are translating to a new location, as I understand it you shouldn''t have to change the (glVertex3f()) coords at all. Other than that, are you translating too far away and the box is drawn offscreen?
Hard to say, can you post your DrawGLScene() function?



____________________________________________________

"Two wrongs do not make a right; it usually takes 3 or more."

____________________________________________________
"Two wrongs do not make a right; it usually takes 3 or more."
Some mistakes are too much fun to only make once.
Never anger a dragon, for you are crunchy and you go well with brie.

Advertisement
here it is Ratheous:

{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad

// me from here on
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glBegin(GL_POLYGON); // Draw A Quad
glVertex3f(-1.0f, 2.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 2.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
return TRUE; // Keep Going
}
oops, the anonymous poster was me
First of all, as Ratheous said, you do not need to change the cordinates of the quad. Keep them the same. Accomplish all movement through translations and rotations, using the calls to glTranslate*() and glRotate*(). Also, you are likely translating your polygon off the screen...all calls to glRotate or glTranslate are cumulative unless you (a) push the matrix on the stack and call glLoadIdentity or (b) call glLoadIdentity to destroy the current matrix. Even though you may think that you''re only translating 3 units on X with the call glTranslatef(3.0,0.0,0.0), you are actually translating (-1.5+3.0+3.0)=4.5 units on X. If you wanted to keep all of your code seperate, you should do:

// nehe''s code here
// start your code:
glLoadIdentity(); // clear out the current modelview matrix
glTranslatef( 3.0,2.0,-6.0 ); // +3 units on X,+2 on Y,-6 on Z
glBegin( GL_QUADS ); // start drawing quads
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad

Keep in mind that you may have to play with the various translation values to get our polygon to show up. Also, I would recommend reading the chapter in the OpenGL Red Book (there is a link to it in the Programming resources section of this site, in the OpenGL category) on transformations to familiarize yourself with the way OpenGL''s transformation system works. Hope this helps.

Liquid

This topic is closed to new replies.

Advertisement