PDA

View Full Version : how to use gluLookAt?



pipiloo
02-01-2002, 02:44 AM
excuse me for this silly question. i have just started learnling openGL.

at first, i defined the following funciton:

void myTriangle(void) {
glBegin(GL_LINE_LOOP);
glVertex2f(0,50);
glVertex2f(50,-50);
glVertex2f(-50,-50);
glEnd();
return;
}

in the function display, i drawed a red triangle, using void myTriangle(void):

void CALLBACK display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
myTriangle();
// gluLookAt(0,0,0, 0,0,-100, 0,100,0);
// gluLookAt(0,0,0, 0,0,-100, 100,0,0);
glFlush();
return;
}

since the coordinate of the bottom-left point of screen is(0,0),
i can see only a part of my red triangle.

then, i tried to change the position of my eyes by using the function gluLookAt.
after the first // is the default setting of my eyes.
i tried to rotate my head to the right( 90 degree ) by deleting the second //.
it does not work. http://www.opengl.org/discussion_boards/ubb/frown.gif
i dont know why,if you know, please tell me.thanks a lot.

below is the whole program, i have compiled run it successfully in VC6,windows2K.

================all the source codes==============
# include <windows.h>
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glaux.h>

void myTriangle(void) {
glBegin(GL_LINE_LOOP);
glVertex2f(0,50);
glVertex2f(50,-50);
glVertex2f(-50,-50);
glEnd();
return;
}

void myinit(void) {
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
return;
}


void CALLBACK display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
myTriangle();
gluLookAt(0,0,0, 0,0,-100, 100,0,0);
glFlush();
return;
}


int main(int argc,char ** argv) {
auxInitDisplayMode(AUX_SINGLE|AUX_RGB);
auxInitPosition(0,0,200,200);
auxInitWindow("hello world");
myinit();
auxMainLoop(display);
return 0;
}

zeraiam
02-01-2002, 03:15 PM
Hi
You should call glLoadIdentity() before gluLookAt(...). When you call gluLookAt, you multiply the modelview matrix by your desired matrix. Calling glLoadIdentity previously sets it to identity.
I think you should draw the triangle after setting up the matrix too.

pipiloo
02-02-2002, 07:54 AM
hi.
thanks a lot to your help.
i have modified my program according to your advice.
now it works in this computer.
But it does not work in my own computer.


[This message has been edited by pipiloo (edited 02-02-2002).]