PDA

View Full Version : getting the raster pos



David Doria
12-05-2008, 08:55 AM
As a demo, I did this:


GLenum error;
int rasterpos[2];

glRasterPos2i(10,20);

glGetIntegerv(GL_CURRENT_RASTER_POSITION, rasterpos);

cout << "raster pos x: " << rasterpos[0] << " y: " << rasterpos[1] << endl;

error = glGetError();

cout << gluErrorString(error) << endl;

I expected 10, 20 to be the rasterpos (as I just set it!) but it tells me 0,0. It also says "no error" - that was the only thing I knew to check.

Anyone know what's wrong?

Thanks!
Dave

trinitrotoluene
12-05-2008, 10:29 AM
Maybe that will not solve your problem, but when you ask for GL_CURRENT_RASTER_POSITION, the function return you an array of 4 elements and you pass an array of only two elements. Can you check for GL_CURRENT_RASTER_POSITION_VALID? If it's false, the current raster position is undefined.

David Doria
12-05-2008, 11:51 AM
why is the raster position 4-valued? isn't it just x and y?

Dave

trinitrotoluene
12-05-2008, 12:09 PM
why is the raster position 4-valued? isn't it just x and y?
Because it is written here (http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml). Look for GL_CURRENT_RASTER_POSITION in the page.

arekkusu
12-05-2008, 01:30 PM
The raster position you specify is transformed by the MVP, just like calling glVertex.
Probably, the transformed rasterpos is a tiny float value, and you see zero because you're getting it as ints.

If you want to set the rasterpos in integer window coordinates, use glWindowPos.

But really, you shouldn't use any of these functions, they are deprecated in GL3.

David Doria
12-05-2008, 01:31 PM
what functions do I use instead of these deprecated ones?

arekkusu
12-05-2008, 08:17 PM
If you're using glRasterPos for glDrawPixels, create a texture and draw a quad with it instead.

David Doria
12-06-2008, 10:41 AM
ah got it - setting a 2d raster pos (glRasterPos2i) didn't make any sense when I was not in some simple orthographic mode.

The problem now is how do you get the text to always show up on top of everything else?




DrawCube();
printtext3d(x,y,z);


void printtext3d(const int x, const int y, const int z)
{
glRasterPos3i(x,y,z);

glColor3f(1.0f, 1.0f, 1.0f);

string TextString = "hello";
for (int i=0; i < TextString.size(); i++)
{
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, TextString[i]);
}

}


doesn't it project the 3d point onto the image to determine the window coordinates to draw the text? If so, then the text doesn't really have a "depth" because it's now 2d. But if I choose a 3d point that is behind the cube, the text is covered by the cube even though I draw the text after the cube. How do you make the text in the front no matter what?

Thanks,
Dave

arekkusu
12-06-2008, 11:02 AM
Disable depth testing, and draw the text last.

David Doria
12-06-2008, 11:04 AM
ah, i tried disabling depth testing, but then the cube got messed up - but I just draw everything with depth testing enabled, and then disable it only before drawing the text!

Thanks!
Dave