Results 1 to 7 of 7

Thread: cannot view perspective?

  1. #1
    Member Newbie
    Join Date
    Nov 2001
    Location
    malaysia
    Posts
    36

    cannot view perspective?

    i make maze program..
    it work just fine...
    but, i'm facing problem when want to make a perspective view? the code i make is, when pressing button f1, we can look from perspective view.. but when i press f1, the perspective view is appear but just a glance.. maybe about one second..after that it back to normal view.. i put glutpostredisplay but still cannot solve the problem.. can you help me..
    apit

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: cannot view perspective?

    Hi !

    No I cannot help you no one can help you unless you at least post a piece of code that shows what you are trying to do.

    I wild guess is that you have code somewhere that setup the projection for you and this code gets called al the time, so when you change the projection this code will change it back for you, sorry, that's the best I can do without seeing the code.

    Mikael


    [This message has been edited by mikael_aronsson (edited 08-16-2003).]

  3. #3
    Member Newbie
    Join Date
    Nov 2001
    Location
    malaysia
    Posts
    36

    Re: cannot view perspective?

    this is the code ::

    case GLUT_KEY_F1 :
    {
    //perspective view
    glutSetWindow(subWindowLeft);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(11.0f,12.0f,11.0f, 5.0f,0.0f,5.0f, 0.0f,1.0f,0.0f);
    glutPostRedisplay();
    renderScene(subWindowLeft);

    glutSetWindow(subWindowRight);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(11.0f,12.0f,11.0f, 5.0f,0.0f,5.0f, 0.0f,1.0f,0.0f);
    glutPostRedisplay();
    renderScene(subWindowRight);
    }
    break;
    //Aerial view
    case GLUT_KEY_F2:
    {
    glutSetWindow(subWindowLeft);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(5.0f,10.0f,5.0f, 5.0f,0.0f,5.0f,
    0.0f,0.0f,-1.0f);
    glutPostRedisplay();
    renderScene(subWindowLeft);
    }
    break;

    glutSetWindow(subWindowRight);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(5.0f,10.0f,5.0f, 5.0f,0.0f,5.0f,
    0.0f,0.0f,-1.0f);
    glutPostRedisplay();
    renderScene(subWindowRight);
    }
    break;
    apit

  4. #4
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: cannot view perspective?

    Hi !

    Ok, the problem is that you should not put any rendering code in the keybord callback, just set a variable and call glutPostRedisplay(), then use the variable in your display callback to render in the correct way.

    All your rendering code should be placed in the display callback, glutPostRedisplay() will then call that display function a little later (not when you call glutPostRedisplay).

    Mikael


    [This message has been edited by mikael_aronsson (edited 08-19-2003).]

  5. #5
    Member Newbie
    Join Date
    Nov 2001
    Location
    malaysia
    Posts
    36

    Re: cannot view perspective?

    just set the variable?
    that mean i just put variable and then call the glutpostredisplay function...

    case GLUT_KEY_F2:
    {
    glutSetWindow(subWindowLeft);
    renderScene();
    glutPostRedisplay();
    renderScene(subWindowLeft);
    }
    break;

    is it like the code above?
    apit

  6. #6
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: cannot view perspective?

    Hi !

    No, you cannot put any OpenGL rendering function calls in the keyboard callback, you should instead:

    int viewmode = 0;

    keyboard_callback()
    switch( key) {
    case GLUT_KEY_F1:
    viewmode = 0;
    glutPostRedisplay();
    break;
    case GLUT_KEY_F2:
    videmode = 1;
    glutPostRedisplay();
    break;
    }}

    And then in your display callback:

    display_callback()
    {
    ...
    if( viewmode == 0)
    ...set perpsective mode...
    else
    ...set orthographic mode...
    // put your rendering code here
    }

    Mikael

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    23

    Re: cannot view perspective?

    Yeah, this is a common mistake when people dong properly seperate their code. Your rendering sequence should be its own entity. Your keyboard sequence should be its own entity. You want to set a bool that is initially true, that so that when the scene is rendered it evaluates this bool, and if it is true it is rendered w/o perspective calculations. In your keyboard sequence you want to set a line like this

    if(F1 is hit)then
    {
    perspective(bool) = !perspective;
    }

    that way the next time you go through your render sequence it will do the perspective calculations. Also make sure you initialize your bool in some other segment of code so it does not get reset to the initial value every time you enter a new frame.

    Make sense?

Similar Threads

  1. can not get right perspective view of model
    By steven25000 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-11-2011, 12:07 PM
  2. perspective from field of view
    By vankirkc in forum OpenGL: General
    Replies: 0
    Last Post: 07-09-2011, 06:38 PM
  3. Perspective View
    By thesidisticme in forum OpenVG
    Replies: 3
    Last Post: 05-12-2010, 12:00 PM
  4. perspective view problem
    By angelwarrior in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-16-2008, 03:17 PM
  5. problem with perspective view
    By steve_j in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 04-22-2005, 03:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean