How do you use Ortho?

Started by
9 comments, last by Kris2456 19 years, 10 months ago
Ok, short question how do u use ortho. I found something on it at www.gametutorials.com but i havnt managed to get it to work: here is my code:

void OrthoMode(int left, int top, int right, int bottom)
{
	// Switch to our projection matrix so that we can change it to ortho mode, not perspective.

	glMatrixMode(GL_PROJECTION);						

	// Push on a new matrix so that we can just pop it off to go back to perspective mode

	glPushMatrix();									
	
	// Reset the current matrix to our identify matrix

	glLoadIdentity();								

	//Pass in our 2D ortho screen coordinates.like so (left, right, bottom, top).  The last

	// 2 parameters are the near and far planes.

	glOrtho( left, right, bottom, top, -1, 1 );	
	
	// Switch to model view so that we can render the scope image

	glMatrixMode(GL_MODELVIEW);								

	// Initialize the current model view matrix with the identity matrix

	glLoadIdentity();										
}



void PerspectiveMode()										// Set Up A Perspective View

{

	// Enter into our projection matrix mode

	glMatrixMode( GL_PROJECTION );							

	// Pop off the last matrix pushed on when in projection mode (Get rid of ortho mode)

	glPopMatrix();											

	// Go back to our model view matrix like normal

	glMatrixMode( GL_MODELVIEW );							

	// We should be in the normal 3D perspective mode now

}

void DrawRadar()
{
OrthoMode(0, 600, 800, 0);
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glColor3f(0.5,0.5,1.0);
glVertex2f(-0.2,0.2);
glVertex2f(0.2,0.2);
glVertex2f(0.2,-0.2);
glVertex2f(-0.2,-0.2);
glEnd();
glBegin(GL_POINTS);
glColor3f(1.0,0.0,0);
glVertex2f(g_Camera.m_vPosition.x/10,g_Camera.m_vPosition.z/10);
glEnd();
glColor3f(1.0,1.0,1.0);
glEnable(GL_TEXTURE_2D);
PerspectiveMode();
}
and my drawGLScene() code:

int DrawGLScene(GLvoid)									// Here''s Where We Do All The Drawing

{   
    POINT pt;
    GetCursorPos(&pt);
    GLfloat tiery = (float)(400 - pt.x)/35;
    GLfloat tierx = (float)(300 - pt.y)/35;
    crossx = (float)(pt.x/800);
    crossy = (float)(pt.y/800);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer											// Done Drawing The Triangle

    
    glLoadIdentity();
   	glEnable(GL_LIGHT1);
    glTranslatef(0, -0.3, tiez);
    glRotatef(tiery,0,1,0);
    glRotatef(tierx,1,0,0);
    TieFighter();
    glBegin(GL_TRIANGLES);
    glColor3f(1,0,0);
    glNormal3f(0.0f,0.0f,0.0f);
    glVertex3f(crossx,crossy,-6);
    glVertex3f(crossx-0.03,crossy-0.03,-6);
    glVertex3f(crossx+0.03,crossy-0.03,-6);
    glColor3f(1,1,1);
    glEnd();
    glPushMatrix();
    glTranslatef(-0.1, 0, -0.01);
    DrawParticles(TexID[1],1.0f,1.0f,1.0f,50.0,0.03);
    glTranslatef(0.2, 0, 0);
    DrawParticles(TexID[1],1.0f,1.0f,1.0f,50.0,0.03);
    glPopMatrix();
//I DRAW RADAR HERE

    glPushMatrix();
    glLoadIdentity();
    DrawRadar();
    glPopMatrix();
            //                   //                //

    gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,	
			  g_Camera.m_vView.x,	  g_Camera.m_vView.y,     g_Camera.m_vView.z,	
			  g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);

//........ETC

when i try it out, there is no radar, everything is like it was before. Anyone have an idea? ----------------- "Here lies a toppled God, His fall was not a small one, We but built his pedastle, A narrow, and a tall one" Frank Herbert (Dune:Messiah)
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Advertisement
Try disabling the light before drawing the 2D stuff.
Nope, no change. I think it might be beacuse its not in the frustum...
Anyone else have any suggestions?
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
quote:Original post by Kris2456

glBegin(GL_QUADS);
glColor3f(0.5,0.5,1.0);
glVertex2f(-0.2,0.2);
glVertex2f(0.2,0.2);
glVertex2f(0.2,-0.2);
glVertex2f(-0.2,-0.2);
glEnd();


That''s from your radar drawing function. If you are using back-face culling, it will be culled because the vertices are given in clockwise order, so try either rearranging them or turning off backface culling to see if that helps.
No, i turned off a culling, ages ago. Before i started this project. I think its something to do with ortho mode...
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Your radar quad is too small (0.4 pixels wide on a 640 width screen). It is also positioned at the very top left of the screen. If you''re lucky, you''ll see a whitish blue dot at the very top left of your screen.

Try make your quad something like this
glBegin(GL_QUADS);glColor3f(0.5f, 0.5f, 1.0f);glVertex2f(0.0f,   200.0f);glVertex2f(200.0f, 200.0f);glVertex2f(200.0f, 0.0f);glVertex2f(0.0f,   0.0f);glEnd();
do unto others... and then run like hell.
SWEET, so thast what it was. I didnt kno that each 1.0f was a pixel, lol. Thanks for that.

Beacuse i have it finished. I was wondering if i copuld put it in a DLL file. Does anyone know ow to do this on Dev-C++.

Thanks again...
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Kris, that''s what the parameters of glOrtho mean:

left = left coordinate of your viewport
right = right coordinate of your viewport
bottom = bottom coordinate of your viewport
top = top coordinate of your viewport

If your viewport is mapped exactly to your screen (using glViewport) then you will have vertex coordinates as exactly your pixel coordinates ... useful eh? :D

Cheers

do unto others... and then run like hell.
yeh, thx. Do u have any idea bout the .DLL one tho?
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Only know how to do it in VC6...sorry. You could try a forum search in the ''General Programming forum''...
do unto others... and then run like hell.

This topic is closed to new replies.

Advertisement