Jump to content
  • Advertisement
Sign in to follow this  
PeteUK

OpenGL [SOLVED] XYZ axes in lower left corner

This topic is 3432 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to have XYZ axes of fixed position/length in the lower-left corner of the display. Googling for help found someone else who had posed the same question on the opengl.org forum: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=248059. The 2nd reply really appealed to me and it seems to work ok apart from when I pan or zoom into/out of a point. The axes then disappear! Here's a fragment of my code. (I use CML for the math library).
void drawAxes()
{
	glViewport(10,10,80,80);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0,0.0,1.0,1.0,-1.0,1.0);

	// Strip translation
	Matrix4 mv = view;
	mv(3,0) = 0.0f;
	mv(3,1) = 0.0f;
	mv(3,2) = 0.0f;
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(mv.data());

	// Axes
	glPushAttrib(GL_CURRENT_BIT);
	glPushAttrib(GL_LINE_BIT);
	glColor3ub(255,255,0);
	glLineWidth(2.0f);
	const float len = 0.5f;
	Vector3 axesOrigin(0.0f,0.0f,0.0f);
	glBegin(GL_LINES);
	glVertex3fv(axesOrigin.data());
	glVertex3f(axesOrigin[0] + len,axesOrigin[1],axesOrigin[2]);
	glVertex3fv(axesOrigin.data());
	glVertex3f(axesOrigin[0],axesOrigin[1] + len,axesOrigin[2]);
	glVertex3fv(axesOrigin.data());
	glVertex3f(axesOrigin[0],axesOrigin[1],axesOrigin[2] + len);
	glEnd();

	// Axes labels
	glRasterPos3f(axesOrigin[0] + len,axesOrigin[1],axesOrigin[2]);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'x');
	glRasterPos3f(axesOrigin[0],axesOrigin[1] + len,axesOrigin[2]);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'y');
	glRasterPos3f(axesOrigin[0],axesOrigin[1],axesOrigin[2] + len);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'z');

	glPopAttrib();
	glPopAttrib();

	// Restore viewport, projection and modelview matrices
	glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(proj.data());
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(view.data());
}
drawAxes() is called from the display() function:
void display()
{
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	glColor3f(1,1,1);

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(view.data());
	drawAxes();

	glutWireTeapot(200.0);

	glutSwapBuffers();
}
Anyone any ideas what I need to do ensure the axes don't disappear? Thanks in advance, Pete [Edited by - PeteUK on July 22, 2009 8:12:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
Just noticed my glOrtho() call wasn't quite right. Now updated to:


glOrtho(-0.5,0.5,-0.5,0.5,-1.0,1.0);


But that hasn't helped the problem :(

Pete

Share this post


Link to post
Share on other sites
Changed:

// Strip translation
Matrix4 mv = view;
mv(3,0) = 0.0f;
mv(3,1) = 0.0f;
mv(3,2) = 0.0f;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(mv.data());

to:

// Strip translation
Matrix4 mv = view;
mv.data()[12] = 0.0f;
mv.data()[13] = 0.0f;
mv.data()[14] = 0.0f;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(mv.data());


and it works. I had assumed the first block was writing to the matrix but it wasn't. Very embarassing and I'm off to read the CML docs a bit closer!

Pete

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!