beginning openl

This is a discussion on beginning openl within the Game Programming forums, part of the General Programming Boards category; I am starting opengl and I understand everything in the code below except for how they got the coordinates I ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    beginning openl

    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;
    }

  2. #2
    Banned
    Join Date
    May 2004
    Posts
    129
    basically, in that tutorial, they use 45 degrees because the tangent of 45 degrees is 1, that means that if you move down the z axis (actually, you are wrong about this, gl by default uses right hand coordinate system, negative z axis you are looking down, x axis off to right) by 1 unit then that means that your top and bottom boundaries are also bounded by 1 unit (this is because that gluperspective function makes 45 degrees the fovy, to solve for fovx you multiply by aspect ratio).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-06-2008, 07:54 PM
  2. Replies: 15
    Last Post: 05-13-2006, 10:28 PM
  3. writing to the beginning of a file
    By cloudy in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2006, 02:47 PM
  4. writing to the beginning of the file
    By Jules in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2004, 02:31 AM
  5. Replies: 2
    Last Post: 05-10-2002, 05:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21