Drawing pixels from buffer and position (glDrawPixels)

2.1k views Asked by At

Basically I am doing some tests to simulate various window inside a scene. Everything works fine until I try to position better the window that I am drawing inside the scene.

The important code is here:

// camFront = glReadPixels ...

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
//glRasterPos3f(1.0, 0.5, 0.0);  // <-- commented out

// Zooming window
glPixelZoom(0.5, 0.5);      

glDrawPixels(500, 250, GL_RGB, GL_UNSIGNED_BYTE, camFront);  //> camFront is the buffer of the window
glutSwapBuffers();  

Basically when glRasterPos3f is commented out I got my nice window drawn inside my scene:

enter image description here

Now If i try to position that window with glRasterPos3f, the window disappears completly from the scene... Any clues?

1

There are 1 answers

7
user3125280 On BEST ANSWER

One possible The cause of this problem is an invalid rasterpos. The raster pos is set after transforming x,y and z just like any other pixel. This includes the clipping stage.

The easy test is to see if when a bright point (or something more visible) is drawn at your x,y and z it appears on the screen.

Where is (1.0, 0.5, 0.0) in your screen? Is it visible?

The coordinate has to be a visible point that is projected onto screen, becoming a 2d coordinate. Try putting the code before the modelview part, maybe then the coordinate will be where you expected.

Because you reset the matrix with glLoadIdentity, the point (1.0, 0.5, 0.0) will be at the right edge of screen - possibly clipped as too far right or too close to camera.

GLboolean valid;
glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &valid);
if(valid == GL_FALSE) 
    printf("Error");

(The second test is better than drawing something, but won't help tell you where it is being drawn if it is not invalid)