Archived

This topic is now archived and is closed to further replies.

Kris2456

How do you use Ortho?

Recommended Posts

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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
No, i turned off a culling, ages ago. Before i started this project. I think its something to do with ortho mode...

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Only know how to do it in VC6...sorry. You could try a forum search in the ''General Programming forum''...

Share this post


Link to post
Share on other sites
No matter, jus tell me how to do it VS6, ill see if i can salvage anything from it.

What i really want is what to write in the file, where should i put my functions i want to use in my project.

Share this post


Link to post
Share on other sites