I am starting opengl and I understand everything in the code below except for how they got the coordinates I understand that when you start off by defaul you are looking down the z axis, but how did they know har far to translate and the coordinate numbers themselves??Code:#include <GL/gl.h> #include <GL/glut.h> #include <GL/glu.h> #include <unistd.h> #include <stdlib.h> int window; void Display(void){ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-1.5,0.0,-6.0); glBegin(GL_POLYGON); glVertex3f(0.0,1.0,0.0); glVertex3f(1.0,-1.0,0.0); glVertex3f(-1.0,-1.0,0.0); glEnd(); glTranslatef(3.0,0.0,0.0); glBegin(GL_QUADS); glVertex3f(-1.0,1.0,0.0); glVertex3f(1.0,1.0,0.0); glVertex3f(1.0,-1.0,0.0); glVertex3f(-1.0,-1.0,0.0); glEnd(); glutSwapBuffers(); } void keyboard(unsigned char key,int x,int y){ usleep(100); if(key==27){ glutDestroyWindow(window); exit(0); } } void reshape(int Width,int Height){ if(Height==0) Height=1; glViewport(0,0,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(GLfloat)Width/(GLfloat)Height,0.1,100.0); glMatrixMode(GL_MODELVIEW); } void InitGL(int Width,int Height){ glClearColor(0.0,0.0,0.0,0.0); glClearDepth(1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,(GLfloat)Width/(GLfloat)Height,0.1,100); glMatrixMode(GL_MODELVIEW); } int main(int argc,char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_ALPHA); glutInitWindowSize(640,480); glutInitWindowPosition(0,0); window=glutCreateWindow("Yellow Ledbetter"); glutDisplayFunc(Display); glutFullScreen(); glutIdleFunc(Display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); InitGL(640,480); glutMainLoop(); return 0; }



LinkBack URL
About LinkBacks


