Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Drawing with OpenGL

  1. #11

    Drawing with OpenGL

    Kool! Thanks! I can't try it out now, but I sure will soon!

    Btw, that thing with the GL and GLU units in FPC is quite interesting! Now I'm warned! lol

    Also, when reading that other thread, I learned about GluUnProject, which is the opposite of what I asked, right?
    I hadn't even asked cos I thought it was not possible to do that, since a point in the screen is an infinite line in a 3D matrix...

    But obviously (and fortunately!) ppl are a lot smarter, and they found a way! I saw it requires to input the window coordinates plus a Z coordinate.
    So that Z coordinate, is it the depth out of the screen (so negative for into the screen) regardless of the transformations you have made to your matrix; is it like the depth buffer you talked about, in which case I guess it would be positive into the screen, right?; or is it the z coordinate of your matrix?
    If it's the latter, then what if you rotate the matrix so that the z axis is 'parallel' to the screen, wouldn't that make it undefined?

    thanks for this extended help!

  2. #12

    Drawing with OpenGL

    The winZ coordinate that must be passed to gluUnProject is a depth buffer value. You can get it by using glRedPixels with GL_DEPTH_COMPONENT parameter:
    Code:
    glReadPixels(screenX,screenY,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@wz);
    Another possibility that can be used for picking objects, is to call gluUnproject with minimal and maximal values of depth buffer which are zero and one. As a result you get two points from which you construct a ray and see if it intersects any objects.

  3. #13
    The right one is this dear
    Procedure Matrix_to_Win; var model, proj, Winx,Winy,Winz : PGLdouble; Matrixx,Matrixy,Matrixz : real; view : PGLint; begin {view := 0; model := GL_MODELVIEW; proj := GL_PROJECTION;} Winx := 0; Winy := 0; Winz := 0; Matrixx := 0; Matrixy := 0; Matrixz := 0; glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetIntegerv(GL_VIEWPORT, view); gluProject(Matrixx, Matrixy, Matrixz, model, proj, view, Winx, Winy, Winz); end;

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •