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 6 of 6

Thread: Two-point vanishing perspective opengl

  1. #1
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    3

    Two-point vanishing perspective opengl

    Hello!
    I'm trying to create a 2 point vanishing view on a house I've created but I can't get it right. I managed to get the isometric view by using

    gluLookAt(dist, dist, dist,0.0, 0.0, 0.0,0.0, 1.0, 0.0);

    where dist is sqrt(1/3.0). When I try to set up the 2 point vanishing projection I'm doing something very wrong. Now my object is from -3 to 3 on x-axis ,-3 to 3 on y-axis and -6 to 6 on z-axis. This code

    c = 0;
    gluLookAt(3.0, 0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    works by setting the translatef range to 0, then goes to the right front corner ,on flat level(y=0) and looks at it sideways. now this gives me the dimetric just fine. but when I try to add perspective , the object gets so warped I cant even understand what went wrong. Here:

    c = 0;
    gluPerspective(90, 1, 0.1, 20);
    gluLookAt(5.0, 0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

    I've trying changing fov,znear,zfar , the order of the commands, but I just can't get it to work.

  2. #2
    Intern Newbie
    Join Date
    Dec 2013
    Posts
    45
    Which matrices are you applying them on? gluPerspective should be used on the GL_PROJECTION matrix and gluLookAt should be used on the GL_MODELVIEW matrix.

  3. #3
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    3
    Ah, this might be it. I m modifying the view from a right click menu , which changes a value called view ( = 0,1 or 2) and i call if checks in the display function that creates the object.
    void display() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);


    glLoadIdentity();
    glOrtho(-100, 100, -100, 100, 0, -5000);
    if (isometric == 1){gluLookAt(dist, dist, dist, 0.0, 0.0, 0.0,0.0, 1.0, 0.0);}
    if (isometric == 2){ c = 0; gluPerspective(90, 1, 0.1, 20); gluLookAt(3.0, 0, 6.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); }
    glTranslatef(0.0f, 0.0f, c);
    glRotatef(angle, rx, ry, rz);

    glBegin(GL_QUADS);
    ...

    and the other is

    void optionmenu(int id)
    {
    if (id == 1) { isometric = 0; angle = 0; rx = 0; ry = 0; rz = 0; glutPostRedisplay();; }
    if (id == 2) { isometric = 0; angle = 90; rx = 1; ry = 0; rz = 0; glutPostRedisplay();; }
    if (id == 3) { isometric = 0; angle = -90; rx = 0; ry = 1; rz = 0; glutPostRedisplay();; }
    if (id == 4) { isometric = 1; angle = 0; rx = 0; ry = 0; rz = 0; glutPostRedisplay(); }
    if (id == 5) { isometric = 2; angle = 0; rx = 0; ry = 0; rz = 0; glutPostRedisplay(); }

    so indeed i have my gluPerspective in my GL_MODELVIEW.
    how would i change the perspective with the menu right click?
    Should i do an if at the begining or end of display by calling glMatrixMode(GL_PROJECTION); set the perspective and then call GL_MODELVIEW again?

  4. #4
    Intern Newbie
    Join Date
    Dec 2013
    Posts
    45
    If I understand your setup correctly, you should probably split up your if blocks kinda like this:
    Code :
    if(isometric == 1)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(...);
        glMatrixMode(GL_MODELVEW);
        glLoadIdentity();
        gluLookAt(...);
    }
    if(isometric == 2)
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(...);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(...);
    }
    And then set up everything else from there. You may want to look at OpenGL 3.3 instead of the fixed function pipeline, it is a lot more customization.

  5. #5
    Newbie Newbie
    Join Date
    Jan 2014
    Posts
    3
    thanks , The picture appears to be getting some perspective but only the front face is appearing now ( just the square of the house and the roof in perspective, the rest of the house is invisible o.O).
    Which on second try it worked because i had to first use gluLookAt and then translate and i swapped them and it worked.

    Thanks a lot

  6. #6
    Intern Newbie
    Join Date
    Dec 2013
    Posts
    45
    No problem enjoy!

Posting Permissions

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