getting the raster pos

As a demo, I did this:

GLenum error;
int rasterpos[2];


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?


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.

why is the raster position 4-valued? isn’t it just x and y?


why is the raster position 4-valued? isn’t it just x and y?

Because it is written here. Look for GL_CURRENT_RASTER_POSITION in the page.

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.

what functions do I use instead of these deprecated ones?

If you’re using glRasterPos for glDrawPixels, create a texture and draw a quad with it instead.

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?


void printtext3d(const int x, const int y, const int 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?


Disable depth testing, and draw the text last.

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!