Click here to Skip to main content
13,049,814 members (75,339 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi there,
I have an openGL application that works nice: moving the scene, panning, zooming etc works well. Now I like to display a small coordinate system marker (3 arrows) in the bottom/left corner of the view area - which stays there, no matter how the scene is moved, panned or zoomed. I guess I need to tie an OGL object on raster coordinates, but what I tried is either not visible, or is still moved with the scene.

Can please anyone point me into the right direction ? thank you
Posted 17-Apr-12 13:15pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


I haven't used the function myself, though it seems that gluUnproject would be a function you need to use.

using gluUnproject - NeHe[^][^]

I guess you'd just (arbitrarily?) select a depth, then substitute the mouse coords for the known desired coords of your coord system marker. (using the nehe example)
matthiasD42 18-Apr-12 2:14am
Hi, thanks, gluUnproject() works well - but I'm experiencing a funny behaviour: my GL scene is scaled into -1 ... +1 coordinates and my coordinate system marker arrows have length of 0.1. The depth winZ=0 creates a huge arrow, only the base part is visible. Changing winZ towards 1.0 shows a very exponential behaviour: the optimum values for winZ=0.9997 - its ok for my, but I'd like understand this, is this because depth is related to the perspective of my view ?
thanks again, Matthias
enhzflep 18-Apr-12 2:38am
Hi. Great!
Sorry, I'm not sure of the answer and am a little hazy to really think the problem through at the moment.

However, since the screen-coords depend on a 1/Z relationships somewhere (in the viewing transofrm) it seems that this is likely the case. Recalling the old demo-effect of a 3d star-field, at a great distance from the camera the stars will be grouped around the center of the screen. The changes in screen x,y as compared to the change in 3d z pos is the greatest when objects are closest to the camera. That is to say, as they draw nearer, the stars creep creep slowly towards the edges of the screen. As the distance from the camera decreases, the stars move more and more rapidly towards the screen edge.

Perhaps it would be worth considering drawing the axis-marker without perspective? It seems that this is the default (only?) behaviour for 3d content creation programs - e.g Blender, Maya, 3DS Max
It sure would make positioning it dead easy - just draw at ~(-0.8, -0.8, arbitraryZ) and you'd still have 0.1 units (5% of screen width) between the marker and the edge of the screen.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can do it with drawing lines (glBegin(GL_LINES)) . You should do it after drawing all other scene data. And also make sure that your scene transformations will not effect the axis drawing.

it will be like this

DrawScene() // All scene drawing goes here.
glTranslatef( adjust the coordinates such that axis are at correct position)
DrawAxis() // draw axis will use lines.

This will work. One more thing , don't mix up Opengl with GDI.
if you still want to modifu frame buffer use glDrawPixels

Hopes this helps

Madhan Mohan Reddy 15-Apr-13 7:38am
Hey , I am getting infinite lines for my coordinate system.. can anybody tell me why ?

code snippet
double[] m = new double[16];
gl.GetDoublev(gl.MODELVIEW_MATRIX, m);
gl.Translated(CurrentViewPortData.clipX - dd * 0.8, CurrentViewPortData.clipY - dd * 0.8, CurrentViewPortData.sphereRadius * 49.0);

gl.Color3f(1.000000f, 0.000000f, 0.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(1, 0, 0);
gl.Color3f(0.000000f, 1.000000f, 0.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(0, 1, 0);
gl.Color3f(0.000000f, 0.000000f, 1.000000f);
gl.Vertex3d(0, 0, 0);
gl.Vertex3d(0, 0, 1);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 18 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100