PDA

View Full Version : Showing a couple of triangles



franz1999
02-22-2003, 12:18 PM
Very beginner question:

I have a couple of triangles:

(code from display method)

glColor3f(1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(-25.0,-25.0,0.5);
glVertex3f(-25.0,25.0,0.7);
glVertex3f(25.0,25.0,0.9);

glVertex3f(-24.0,-25.0,0.0);
glVertex3f(26.0,25.0,0.0);
glVertex3f(26.0,-25.0,0.0);
glEnd();

If I put in my reshape method the commands:

void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 0.5);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

I can see the two triangles in the middle of the screen. Now I would like to see them with a camera.... I tried:

void reshape(int w, int h)
{
gluLookAt(0.0,0.0,100.0,0.0,0.0,0.0,0.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,1.0,1.5,20.0);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

and I don't see anything http://www.opengl.org/discussion_boards/ubb/frown.gif
Anybody can help me here? I need to position a camera at a reasonable distance, looking at the point (0,0,0). I don't understand the order of method calls... If anybody can explain me how and why I have to follow a specific order I would extremely appreciate it!!!! Thanks!!!!

nexusone
02-22-2003, 12:35 PM
You have two matrix to work with projection and model.

glLookat should be before you start drawing and after you setup the ortho and view port.

gluLookat

glColor3f(1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(-25.0,-25.0,0.5);
glVertex3f(-25.0,25.0,0.7);
glVertex3f(25.0,25.0,0.9);
glVertex3f(-24.0,-25.0,0.0);
glVertex3f(26.0,25.0,0.0);
glVertex3f(26.0,-25.0,0.0);
glEnd();



Originally posted by franz1999:
Very beginner question:

I have a couple of triangles:

(code from display method)

glColor3f(1.0, 1.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(-25.0,-25.0,0.5);
glVertex3f(-25.0,25.0,0.7);
glVertex3f(25.0,25.0,0.9);

glVertex3f(-24.0,-25.0,0.0);
glVertex3f(26.0,25.0,0.0);
glVertex3f(26.0,-25.0,0.0);
glEnd();

If I put in my reshape method the commands:

void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 0.5);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

I can see the two triangles in the middle of the screen. Now I would like to see them with a camera.... I tried:

void reshape(int w, int h)
{
gluLookAt(0.0,0.0,100.0,0.0,0.0,0.0,0.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,1.0,1.5,20.0);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

and I don't see anything http://www.opengl.org/discussion_boards/ubb/frown.gif
Anybody can help me here? I need to position a camera at a reasonable distance, looking at the point (0,0,0). I don't understand the order of method calls... If anybody can explain me how and why I have to follow a specific order I would extremely appreciate it!!!! Thanks!!!!



[This message has been edited by nexusone (edited 02-22-2003).]

franz1999
02-22-2003, 12:40 PM
Ok, forget it. I got it working, thanks!

[This message has been edited by franz1999 (edited 02-22-2003).]