DGL
https://delphigl.com/forum/

glreadpixels with delphi?
https://delphigl.com/forum/viewtopic.php?f=19&t=2811
Seite 1 von 1

Autor:  noeska [ Mo Mai 03, 2004 18:53 ]
Betreff des Beitrags:  glreadpixels with delphi?

I am still trying to select faces and vertexes. For now i am trying to use the backbuffer for it. 24bit truecolor would give me enough colours for selecting them. But i am a bit puzzled on the glreadpixels command as it seems to write its data into pointer like structure.

-Are there any delphi tutorials or examples on the usage of it?

-When reading out only 1 pixel the date returned like a pointer to an array of byte allowing me to result[0] is red result[1] = green and result[2] = blue???

Autor:  Mars [ Mo Mai 03, 2004 20:33 ]
Betreff des Beitrags: 

Here is the code I use for occlusion testing of single pixels, your code would be very similar:
Code:
  1. // return if a point in world space is occluded by on-screen geometry
  2.  
  3. function PointIsOccluded(p: TVec) : boolean;
  4.  
  5.   var
  6.     viewport: TVector4i;
  7.     mvmatrix, projmatrix: TMatrix4d;
  8.     winx, winy, winz: GLdouble;
  9.     bufferZ: float;
  10.  
  11.   begin
  12.     glGetIntegerv (GL_VIEWPORT, addr(viewport));
  13.     glGetDoublev (GL_MODELVIEW_MATRIX, addr(mvmatrix));
  14.     glGetDoublev (GL_PROJECTION_MATRIX, addr(projmatrix));
  15.     // project world space onto screen
  16.     gluProject(p.x, p.y, p.z, mvmatrix, projmatrix, viewport, @winx, @winy, @winz);
  17.       // read back pixel from depth buffer
  18.       glReadPixels(round(winx), round(winy),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, @bufferZ);
  19.     result := bufferZ < winZ;
  20.   end;
  21.  


The last parameter in glReadPixels is a pointer to an array of your own, which is filled by the GL (in this special case of mine, it's a single float value, since I only read back the depth component of one pixel - more interesting (but not for this topic) would be the rectangular version, which is used to brighten/darken light flares, if a light source is partially occluded).

Autor:  noeska [ Mo Mai 03, 2004 21:42 ]
Betreff des Beitrags: 

i figured out the data returned

for var i need to use:
pixel: array [0..2] of GLubyte;

and the reading goes with: glreadpixels(....,@pixel);

But now an other problem appeared. I need to disable lighting. And use glcolor3f to provide a color for mesh (or face etc.) But that does not appear to work as my meshes all turn white. Hmm... Better return to the redbook again...

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/