just an explanation

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(&argc,argv);
        glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_ALPHA|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;
}

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…

where would you recommend it then?

where would you recommend it then? and how big is it? .1 to 100?

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?

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 ]=-