PDA

View Full Version : just an explanation



grimoire
04-18-2004, 06:40 PM
I am following the tutorials on NeHe and was wondering how does the computer determine the size of the plane you are writing. I know you can edit it with glOrtho, but on Lesson1 they don't use this anywhere and they still use glVertex3f how do they know where the limits are that they see on the screen?
#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 Idle(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(&amp;argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_ALP HA|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
window=glutCreateWindow("Zoot Suit Riot");
glutDisplayFunc(Display);
glutFullScreen();
glutIdleFunc(Display);
glutReshapeFunc(Idle);
glutKeyboardFunc(keyboard);
InitGL(640,480);
glutMainLoop();
return 0;
}

plasmonster
04-18-2004, 06:52 PM
It's right there in your Idle() function, the gluPerspective(...) call. That's an unusual location for that call, I might add. Most glut apps deal with the viewport/projection matrix in the reshape() call, but it doesn't really matter, as long as it gets done.

edit: oops - Idle is your reshape function...

grimoire
04-18-2004, 06:53 PM
where would you recommend it then?

grimoire
04-18-2004, 06:55 PM
where would you recommend it then? and how big is it? .1 to 100?

plasmonster
04-18-2004, 06:58 PM
gluPerspective(45.0,(GLfloat)Width/(GLfloat)Height,0.1,100);

in this call, the field of view is 45.0 degrees, the aspect ratio is width/height, and the near plane distance is 0.1, and the far plane distance is 100. Is that what you meant?

ce110ut
04-18-2004, 07:52 PM
I would recommend you put gluPerspective in your reshape function. and yes, the viewing volume you created is from 0.1 to 100.

I hope that helps

-=[ regards ]=-