0

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
    is the new position possibly culled? this would cause said symptoms – user3125280 Dec 29 '13 at 15:29
  • @user3125280: I am trying many different values for glRaster.. even glRaster(0,0,0) hides that window =/ –  Dec 29 '13 at 15:31
  • glRasterPos3f(1.0, 0.5, 0.0, 1.0); is the last coordinate not a divisor in 3 argument call? EDIT: no, in three argument call third argument is z, not w – user3125280 Dec 29 '13 at 15:31
  • Do you mean glRasterPos3f(1.0, 0.5, 1.0); (3 inputs)? Anyway tried, it does not appear. (doesn't compile with 4 arguments) –  Dec 29 '13 at 15:32
  • 1
    @link: Do you really need to use `glDrawPixels()` at all. Beside the fact that it is deprecated, it has also always been a very ineffcicent path. To me, this looks more like you want different to viewports and/or render-to-texture. – derhass Dec 29 '13 at 15:34
  • glRasterPos3f(1.0, 0.5, 0.0, -1.0); ? it appears the new coordinate (once transformed) is not valid, and so is "clipped' like a normal vertex. see if you can draw a point or something at those coordinates – user3125280 Dec 29 '13 at 15:35
  • Well I don't explicitly need DrawPixels, but now performance aren't a prolbem. I simply don't get how to position a window with DrawPixels. EDIT: why do you keep writing RasterPos with 4 arguments... it doesn't compile... –  Dec 29 '13 at 15:36

1 Answers1

2

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)

user3125280
  • 2,779
  • 1
  • 14
  • 23
  • do you mean I need to use void `glGetBooleanv` ? It doesn't compile your code (also please note I am using C) – dynamic Dec 29 '13 at 15:49
  • Ok I tried your code. When I use glRaster (with whatever values) I got the error. When I comment out glRaster I don't get the error – dynamic Dec 29 '13 at 15:52
  • noted - error is a placeholder for your error handling code - just printf("Invalid Raster Position\"); or something – user3125280 Dec 29 '13 at 15:52
  • @llnk the x,y and z must be a visible point in your scene - try (0.5,0.5,0.5) – user3125280 Dec 29 '13 at 15:57
  • Hm yes that's the problem. But at this point how can I know which glRaster position can I use ? (tried with .5, .5, .5 - not working) – dynamic Dec 29 '13 at 15:58
  • @llnk maybe (0.0, 0.0, 3.0) or something in the center - how do you set the veiwport? (i think?) – user3125280 Dec 29 '13 at 16:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44101/discussion-between-user3125280-and-llnk) – user3125280 Dec 29 '13 at 16:06