slight modification to nehes tutorial 2
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,
Baldur
October 23, 2000 06:22 PM
there''s a few things to consider here.
First, it''s a good idea to post your source code, regardless if you just cut and pasted and changed a couple numbers, it''s just easier to spot what went wrong.
Now... when you translate the object there''s some things to consider.
See, when you translate and draw the first object then translate again, you aren''t translated from the origin anymore, you''re just moving from the previous point. Like you drew the object at 0,0,0, said move it left 2 and back 2, then you drew the second object and translated again left 4 and back 4. Well you''d think the second object would be 2 left and 2 back from the first object, but it isn''t, it''s 4 left and 4 back, or 6 left and 6 back from the origin. Understand?
glLoadIdentity will reset the model matrix so you are translating from 0,0,0 again.
What will happen to you ALOT is that your objects won''t appear on the screen, you just get the lonely blackness and then start a drinking habit.
A big trick to debugging this is to set your viewport (temporarily) to include an incredible amount of space, more than you would ever need. This way almost anything you would ever draw will be there (if only a tiny spec) just to help you figure out if it drew the object in the world at all.
In short, I am willing to bet that you moved your second square to a position that isn''t within the viewport and that it lies outside of your point of view. It''s prolly there but just clipped.
To remedy this, translate only a tiny bit left or right (not the z unless you reset the model view matrix with glLoadIdentity) and draw the second box. You should see it. If not then make extra sure that you have glBegin and glEnd in the correct place.
So post your source code if you still can''t get it working, and just remember you are learning this so prepare yourself for frustration!!! (And some kick ass graphics)
First, it''s a good idea to post your source code, regardless if you just cut and pasted and changed a couple numbers, it''s just easier to spot what went wrong.
Now... when you translate the object there''s some things to consider.
See, when you translate and draw the first object then translate again, you aren''t translated from the origin anymore, you''re just moving from the previous point. Like you drew the object at 0,0,0, said move it left 2 and back 2, then you drew the second object and translated again left 4 and back 4. Well you''d think the second object would be 2 left and 2 back from the first object, but it isn''t, it''s 4 left and 4 back, or 6 left and 6 back from the origin. Understand?
glLoadIdentity will reset the model matrix so you are translating from 0,0,0 again.
What will happen to you ALOT is that your objects won''t appear on the screen, you just get the lonely blackness and then start a drinking habit.
A big trick to debugging this is to set your viewport (temporarily) to include an incredible amount of space, more than you would ever need. This way almost anything you would ever draw will be there (if only a tiny spec) just to help you figure out if it drew the object in the world at all.
In short, I am willing to bet that you moved your second square to a position that isn''t within the viewport and that it lies outside of your point of view. It''s prolly there but just clipped.
To remedy this, translate only a tiny bit left or right (not the z unless you reset the model view matrix with glLoadIdentity) and draw the second box. You should see it. If not then make extra sure that you have glBegin and glEnd in the correct place.
So post your source code if you still can''t get it working, and just remember you are learning this so prepare yourself for frustration!!! (And some kick ass graphics)
To illustrate the fact you were probably offscreen...
I took lesson 2 and changed the draw routine to:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-3.0f,0.0f,-6.0f);
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
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
return TRUE; // Keep Going
}
... and it worked fine, although when I just took the existing routine, copied the translation before the square, and then copied the square drawing code, I saw no difference because it was offscreen.
Hope this helps,
Iain
Edited by - IainC on October 23, 2000 7:29:10 PM
I took lesson 2 and changed the draw routine to:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-3.0f,0.0f,-6.0f);
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
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
return TRUE; // Keep Going
}
... and it worked fine, although when I just took the existing routine, copied the translation before the square, and then copied the square drawing code, I saw no difference because it was offscreen.
Hope this helps,
Iain
Edited by - IainC on October 23, 2000 7:29:10 PM
[size="2"]www.coldcity.com code, art, life
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement