Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: perspective projection

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    13

    perspective projection

    Hello,

    I am trying to create perspective projection
    I started with drawing a line with help from
    the gluPerspective-command, but then I found out
    that that is forbidden in this assignment

    It's like this:
    *load a file with coords
    *draw the figure with perspective projection
    *use flat shading, painter's algorithm etc

    I am not sure whether or not to use gluOrtho2D
    as replacement for gluPerspective or what to do.

    Everything is to be made "by hand" ..
    For example how can make this line in display
    visible ->

    OG Regards

    Code :
    /********* GLUT callbacks ***********/
    void display()
    {
        /* Draw a grid on the screen */
        int x, y, w, h;
     
        w = glutGet(GLUT_WINDOW_WIDTH);
        h = glutGet(GLUT_WINDOW_HEIGHT);
     
        /* Clear the screen */
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     
     //   glClear(GL_COLOR_BUFFER_BIT);
     
        /* Set color to light grey */
        glColor3f(0, 1.0, 0);
     
        glBegin(GL_LINES);
     
     
        glVertex3f(-2.0f, 2.0f, 0.0f);
        glVertex3f(2.0f, -2.0f, 0.0f);
     
        glEnd();
     
        /* Force the commands to complete */
        glFlush();
     
     
    }
     
    void idle()
    {
        /* Update the GUI */
        if(!tickGUI())
        {
            /* The GUI window has been closed */
            exit(EXIT_SUCCESS);
        }
    }
     
    void reshape(int width, int height)
    {
        /* Setup the viewport and transformations that must be used for
           the project */
        glViewport(0, 0, width, height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0, width, height, 0);
     //gluPerspective(44.0f, width/height, 0.2f, 255.0f);
     //  gluOrth
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, -128.0f); 
    }

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: perspective projection

    Don't ask people on this forum to do your homework.
    Read the OpenGL programming guide, search for redbook.pdf on the web.
    Check Appendix F "Homogeneous Coordinates and Transformation Matrices"

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    13

    Re: perspective projection

    I don't want anyone to do my homework
    I just want to know which part of the code
    to work on to draw something in 3D in pp

    OG regards

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: perspective projection

    but then I found out that that is forbidden in this assignment
    That sounded like homework.
    gluPerspective calls glFrustum internally.
    Look up the formulas in the cited programming guide and replace gluPerspective.
    If that's not what you're asked for in the assignment, all you need should be explained in exactly that book.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2005
    Location
    India
    Posts
    2

    Re: perspective projection

    Opengl uses three Pipelened matrix state. The first one is model view matrix, second is Projection matrix, third is Texture matrix. Programmer has options to load this 4X4 matrix contents. You have to load the appropiate values in the projection matrix. The details of the matrix contents is given in Principles of Computer Graphics using OPENGL by HILL
    Kamakhya

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •