Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:25:29+00:00 2026-06-14T00:25:29+00:00

I have a car draw at (0,0) and some obstacles set up but right

  • 0

I have a car draw at (0,0) and some obstacles set up but right now my main concern is switching from glPerspective to glOrtho and vice-versa. All that i get when i switch from perspective to ortho is a black screen.

void myinit(){
    glClearColor(0.0,0.0,0.0,0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60,ww/wh,1,100);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-5,5,3,backcarx,topcarx,0,0,0,1);
}

void menu(int id){
    /*menu selects if you want to view it in ortho or perspective*/
    if(id == 1){
        glClear(GL_DEPTH_BUFFER_BIT);
        glViewport(0,0,ww,wh);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-2,100,-2,100,-1,1);
        glMatrixMode(GL_MODELVIEW);
        glutPostRedisplay();
    }
    if(id == 2){
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60,ww/wh,1,100);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        viewx = backcarx - 10;
        viewy = backcary - 10;
        gluLookAt(viewx,viewy,viewz,backcarx,topcarx,0,0,0,1);
    }
}

i’ve tried using the clear depth buffer and still doesnt work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:25:31+00:00Added an answer on June 14, 2026 at 12:25 am

    Your mental roadblock lies here:

    void myinit(){
        glClearColor(0.0,0.0,0.0,0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(60,ww/wh,1,100);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(-5,5,3,backcarx,topcarx,0,0,0,1);
    }
    

    OpenGL is not initialized! Yes, there are operations done only occasionally, like loading textures. But in general OpenGL is a state based drawing system. Which means, that you set all your drawing related stuff right before you use it. That code in the “myinit” function actually belongs into the display function. And once you have it there, it get’s trivial to do the switching: Set a enumerating variable and setup the right projection at before drawing depending on the value of the variable.

    As a general rule: OpenGL drawing operations – and setting transformation state belongs into that set of operations – belong into drawing code only. Hence your “menu” function makes no sense at all. It’s an event handler. Event handlers deal with input, they don’t generate output. In a event handler you change the value of variables and then you flag that output is to be performed.


    Update due to comment:

    typedef enum ProjectionType_t { Ortho, Perspective } ProjectionType;
    
    ProjectionType projection;
    
    void onMenu(int entry)
    {
        swtich(entry) {
        case ...:
            projection = Ortho; break;
        case ...:
            projection = Perspective; break;
        }
    
        glutPostRedisplay();
    }
    
    void display(void)
    {
        glClear(...);
    
        glViewport(...);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        switch(projection) {
        case Ortho:
            glOrtho(...); break;
    
        case Perspective:
            gluPerspective(...); break;
        }    
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        ...
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to have a car travel from 0 to offscreen. But I can
Let's say I have a Car interface. Each Car has a set of parts
I have 3 car rental agencies. Each agency requires the data in XML, but
I have a car rental application I am writing. I am having some issue.
I have a QWidget in which I use a QPainter object to draw some
I have car diagnostic device ELM327 with usb port connection, but Mint can't recognize
I have Car (table cars ) method that has_many owners (table owners ). How
I have Car and Rental models conntected OneToMany relation: @Entity public class Rental {
I have a Car object which contains a latitude field and a longitude field.
One car must have one owner, and an owner can have many cars.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.