Results 1 to 5 of 5

Thread: perspective to ortho?

  1. #1
    Member Contributor
    Join Date
    May 2003
    Posts
    50

    perspective to ortho?

    im currently working on an fps, and i want to draw the HUD but i dont know how to change from pers to ortho... here is my source so far:

    Code :
    int InitGL(GLvoid)										
    {
    	BuildFont();					
    	if ((!LoadTGA(&textures[0],"data/Font.tga"))
    		)			
    	{
    		return FALSE;											
    	}
    	glEnable(GL_TEXTURE_2D);
    	glShadeModel(GL_FLAT);						
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				
    	glClearDepth(1.0f);								
    	glEnable(GL_DEPTH_TEST);							
    	glDepthFunc(GL_LEQUAL);							
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	//glPolygonMode(GL_FRONT, GL_LINE);
    	//glPolygonMode(GL_BACK, GL_LINE);
     
    	level_0.Load("level.txt");
     
    	return TRUE;									
    }
     
    int DrawGLScene(GLvoid)							
    {
    	CalculateFrameRate();
    	speed = kSpeed * g_FrameInterval;
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
    	glLoadIdentity();			
    	Keyboard();
    	mcamera.drawCamera();
    	level_0.Render();
    	fps();
    	return TRUE;										
    }
    this is based on the nehe code, would i have to change any functions like glresize and stuff?

    just please explain how to go from pers to ortho, thanks a lot

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: perspective to ortho?

    Somewhere you probably set perspective as follows:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(blah, blah, blah);
    gluPerspective(blah, blah, blah);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    To switch to glOrtho:

    glPushMatrix();//assuming you need to return to previous matrix after doing whatever
    glMatrixMode(GL_PERSPECTIVE);
    glLoadIdentity();
    glOrtho(blah, blah, blah);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    draw stuff
    draw more stuff
    glPopMatrix();//assuming you pushed the previous matrix and you actually need to do more drawing in perspective

  3. #3
    Member Contributor
    Join Date
    May 2003
    Posts
    50

    Re: perspective to ortho?

    didnt work, here is the code and the reSize function
    Code :
    int InitGL(GLvoid)										
    {
    	BuildFont();					
    	if ((!LoadTGA(&textures[0],"data/Font.tga"))
    		)			
    	{
    		return FALSE;											
    	}
    	glEnable(GL_TEXTURE_2D);
    	glShadeModel(GL_FLAT);						
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				
    	glClearDepth(1.0f);								
    	glEnable(GL_DEPTH_TEST);							
    	glDepthFunc(GL_LEQUAL);							
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	//glPolygonMode(GL_FRONT, GL_LINE);
    	//glPolygonMode(GL_BACK, GL_LINE);
     
    	level_0.Load("level.txt");
     
    	return TRUE;									
    }
     
    int DrawGLScene(GLvoid)							
    {
    	CalculateFrameRate();
    	speed = kSpeed * g_FrameInterval;
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
    	glLoadIdentity();			
    	Keyboard();
    	mcamera.drawCamera();
    	level_0.Render();
    	fps();
    	glPushMatrix();
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(0.0f,1024,768,0.0f,-1.0f,1.0f);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
     
    	glPopMatrix();
    	return TRUE;										
    }
     
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
    {
    	if (height==0)										// Prevent A Divide By Zero By
    	{
    		height=1;										// Making Height Equal One
    	}
     
    	glViewport(0,0,width,height);						// Reset The Current Viewport
     
    	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
    	glLoadIdentity();									// Reset The Projection Matrix
     
    	// Calculate The Aspect Ratio Of The Window
    	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
     
    	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
    	glLoadIdentity();									// Reset The Modelview Matrix
    }

    i just get a blank screen

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: perspective to ortho?

    First if you look at your code, perspective is only called on resize, now if never change your perspective that would work fine.
    But you don't, you change it to ortho in the drawscene routine and since resize is only called on window resize ortho mode is the only thing being used, except of one pass after a resize and perspective is used.

    You need to move your perspective setup from the resize routine and put it in the display routine so it is called every time.

    void Drawscene(void)
    {

    // Setup perspective
    // Draw stuff


    // change to ortho
    // Draw head display.

    }

    Code :
    int InitGL(GLvoid)										
    {
    	BuildFont();					
    	if ((!LoadTGA(&textures[0],"data/Font.tga"))
    		)			
    	{
    		return FALSE;											
    	}
    	glEnable(GL_TEXTURE_2D);
    	glShadeModel(GL_FLAT);						
    	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				
    	glClearDepth(1.0f);								
    	glEnable(GL_DEPTH_TEST);							
    	glDepthFunc(GL_LEQUAL);							
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	//glPolygonMode(GL_FRONT, GL_LINE);
    	//glPolygonMode(GL_BACK, GL_LINE);
     
    	level_0.Load("level.txt");
     
    	return TRUE;									
    }
     
    int DrawGLScene(GLvoid)							
    {
    	CalculateFrameRate();
    	speed = kSpeed * g_FrameInterval;
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
    	glLoadIdentity();			
    	Keyboard();
    	mcamera.drawCamera();
    	level_0.Render();
    	fps();
    	glPushMatrix();
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(0.0f,1024,768,0.0f,-1.0f,1.0f);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
     
    	glPopMatrix();
    	return TRUE;										
    }
     
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
    {
    	if (height==0)										// Prevent A Divide By Zero By
    	{
    		height=1;										// Making Height Equal One
    	}
     
    	glViewport(0,0,width,height);						// Reset The Current Viewport
     
    	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
    	glLoadIdentity();									// Reset The Projection Matrix
     
    	// Calculate The Aspect Ratio Of The Window
    	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
     
    	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
    	glLoadIdentity();									// Reset The Modelview Matrix
    }

    i just get a blank screen[/B]<HR></BLOCKQUOTE>



    [This message has been edited by nexusone (edited 05-08-2003).]

  5. #5
    Member Contributor
    Join Date
    May 2003
    Posts
    50

    Re: perspective to ortho?

    thanks a lot, that worked

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2015, 07:35 AM
  2. Ortho and Perspective
    By Richard145 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 04-30-2007, 10:59 AM
  3. ortho + perspective + ortho
    By mithun_daa in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-09-2004, 07:54 AM
  4. Perspective vs. Ortho
    By stout in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-26-2003, 12:05 AM
  5. changing from perspective to ortho back to perspective
    By crappy04 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-19-2001, 09:03 AM

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