OpenGl et le Zbuffer

Résolu
cs_User8 Messages postés 30 Date d'inscription jeudi 24 juillet 2008 Statut Membre Dernière intervention 13 novembre 2012 - 10 juil. 2009 à 11:46
cs_User8 Messages postés 30 Date d'inscription jeudi 24 juillet 2008 Statut Membre Dernière intervention 13 novembre 2012 - 15 juil. 2009 à 09:58
Bonjour,

Sous Opengl, je souhaiterai pouvoir colorier des objets 3d en fonction du Zbuffer mais jusqu'à maintenant toutes mes tentatives sont restées infructueuses. 

Voila ou j'en suis (pas bien loin)

var
   depth : array of  GlFloat;
   rgb   : array of  GlFloat;
begin
  setlength(depth,w*h);
  setlength(rgb,3*w*h);

  glReadPixels (0, 0, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, depth);

  for i := 0 to (W * H)-1 do
  begin
     rgb[3*i]:=depth[i];
     rgb[3*i+1]:=depth[i];
     rgb[3*i+2]:=depth[i];
  end;

  glRasterPos2i(0, 0);
  glDrawPixels(w, h, GL_RGB, GL_FLOAT, rgb);
end;

Mais lorsque je lance la fonction je ne vois rien apparaitre. Je ne suis pas sur de passer correctement les arguments depth et rgb. Quelqu'un pourrait-il m'eclairer?

Merci d'avance

2 réponses

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
10 juil. 2009 à 20:34
var
   i,WH  : integer;
   depth : pAGlFloat;
   rgb   : pAGlFloat;
begin
  WH := w*h;
  depth := AllocMem(WH);
  rgb   := AllocMem(3*WH);
  try
    glReadPixels(0, 0, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, Depth);

    for i := 0 to (WH)-1 do
    begin
      rgb^[3*i] := depth^[i];
      rgb^[3*i+1]:=depth^[i];
      rgb^[3*i+2]:=depth^[i];
    end;

    glRasterPos2i(0, 0);
    glDrawPixels(w, h, GL_RGB, GL_FLOAT, rgb);

  finally
    FreeMem(depth);
    FreeMem(rgb);
  end;
end;

<hr width="100%" size="2" />
3
cs_User8 Messages postés 30 Date d'inscription jeudi 24 juillet 2008 Statut Membre Dernière intervention 13 novembre 2012
15 juil. 2009 à 09:58
Merci pour la réponse FOxi.

Sinon voici une autre variante:

var
   depth : array of  GlFloat;
   rgb   : array of  GlFloat;
begin
  setlength(depth,w*h);
  setlength(rgb,3*w*h);

  glReadPixels (0, 0, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, @depth[0]);

  for i := 0 to (W * H)-1 do
  begin
     rgb[3*i]:=depth[i];
     rgb[3*i+1]:=depth[i];
     rgb[3*i+2]:=depth[i];
  end;

  glRasterPos2i(0, 0);
  glDrawPixels(w, h, GL_RGB, GL_FLOAT, @rgb[0]);
end;
3
Rejoignez-nous