Advertisement

weird RasterPos

Started by July 17, 2003 11:34 AM
9 comments, last by desertcube 21 years, 7 months ago
I''ve been trying to get the current raster position so I can move to the next line in my text class. The problem is I don''t get the correct position from glGetInteger4v(GL_CURRENT_RASTER_POSITION). Say for example i had the following in my draw function glRasterPos2d(50, 100); int currentPos[4]; glGetIntegerv(GL_CURRENT_RASTER_POSITION, currentPos); glRasterPos4iv(currentPos); I wouldn''t now be in the same place!? Instead of being 100 pixels from the top, I would be 100 pixels from the bottom. To initilise the screen in ortho mode i use: glOrtho(0, screenWidth, screenHeight, 0, -1, 1); Does anyone know what I''m doing wrong!?
Shouldn''t it be :
glGetIntegerv(GL_CURRENT_RASTER_POSITION, & currentPos);

?
Advertisement
no, because currentPos is an array, currentPos is actually a pointer to the first element of that array.
do you call glOrtho on the Projection or the ModelView matrix ?
And did you set matrices to identity before ?
To create the window, i use

glClearColor(0, 0, 0, 0);
glViewport(0, 0, screenWidth, screenHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, screenHeight, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

which allows me to draw starting from the top left of the window. At the begining of my draw routine I call glClear(GL_COLOR_BUFFER_BIT) and glLoadIdentity(). It seems the co-ordinates returned from CURRENT_RASTER_POS are from the bottom left!? Why is this? There is no code between the call to setting the raster pos and then the call to getting it, as I am just trying to get it to give me the correct results!!
Thnx for your help
If the current raster position is stored in clip coordinates, then expect coordintaes to be within the [-1,+1] range. (or [-w,+w] if the fourth coordinate is not one).
Advertisement
What is the coordinates returned by glGet ?
And have you tried glGetFloatv instead of glGetIntegerv ?
It makes no difference whether i use floats or integers. At 800 by 600 res, it returns the correct x, 50, but says y is 500, 600 - 100. It is very confusing!
I don''t know about clip co-ordinates, but everything works fine, only in the wrong place! I need glGet so I can increase the y co-ordinate when i do a new line. At the moment I am storing this value, but it would be nice to be able to just reset x to 0 and increment y by the line''s height.
Quoting MSDN on glGetIntegerv
quote:

GL_CURRENT_RASTER_POSITION
The params parameter returns four values: the x, y, z, and w components of the current raster position. The x, y, and z components are in window coordinates , and w is in clip coordinates.


So the values you get makes sense. The window is 600 pixels high and you place it 100 pixel from the top (since that is where world Y=100 ends up if you place the origin in the upper corner), which translated to the screen Y=500, since that origin is in the lower corner.

In short, placing the raster position, getting the raster position, and feeding it back to glRasterPos gives you the same raster position if and only if the origin in world space is in the lower left corner and there is a one to one mapping between world and screen coordinates.
thanks brother bob, your explanation makes sense. But what are clip co-ordinates? Is there an easy way to convert to/from them them with window co-ordinates?

This topic is closed to new replies.

Advertisement