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:

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

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

didnt work, here is the code and the reSize function

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

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.

}

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).]

thanks a lot, that worked