Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi OpenGl Rendercontex schützen (https://www.delphipraxis.net/115690-opengl-rendercontex-schuetzen.html)

EWeiss 16. Jun 2008 13:11


OpenGl Rendercontex schützen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Ich setze auf einen OpenGl Rendercontex eine Progressbar auf
Leider zerstört meine function die Zorder der Plugins und verändert auch diverse andere Dinge
Gibt es eine möglichkeit die vom Plugin zu schützen wenn ich meine drüber setze ?

Delphi-Quellcode:
procedure DrawPosition;
Var
    x1,x2,
  x12,x21,
  z1,y1,
  y2,x,y,hd : GLfloat;
  d1,d2    : GLfloat;
  overdraw : GLfloat;

begin

  glMatrixMode(GL_PROJECTION); //--> zerstört die z order
  glLoadIdentity;
  gluPerspective(45, BassBoxInfo^.w / BassBoxInfo^.h, 1, 1000.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  d1 := 0.05;
  d2 := 0.01;
  overdraw := 0.03;

   glDepthMask(ByteBool(GL_FALSE));
   glDisable(GL_LIGHTING);
   glEnable(GL_BLEND);
   glBlendFunc(GL_ONE, GL_ONE);

   glBindTexture(GL_TEXTURE_2D, BarTexture);
   glColor4f( 1.0, 1.0, 1.0, 0.0);

   z1  := -4.0;
   y1  := -1.65;
   y2  := y1 + d1 - d2 + overdraw;
   x1  := -2.21;
   x2  := 2.20;
   x12 := x1 + (d1 - d2) * 0.3;
   x21 := x2 - (d1 - d2) * 0.3;

   glBegin(GL_QUADS);

      glTexCoord2f(0.0, 0.0);
      glVertex3f(x1, y2, z1);
      glTexCoord2f(1.0, 0.0);
      glVertex3f(x1, y1, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(1.0, 1.0);
      glVertex3f(x2, y1, z1);
      glTexCoord2f(0.0, 1.0);
      glVertex3f(x2, y2, z1);

   glEnd();

   glBindTexture(GL_TEXTURE_2D, PeaksTexture);

   hd :=(d1 - d2) * 4.0;
   x :=(x2 - x1) * CurrentPositionPart + x1;
   y :=(y2 + y1) * 0.5;

   glBegin(GL_QUADS);
  glTexCoord2f(0.0, 0.0);
  glVertex3f(x - hd, y - hd, z1);
  glTexCoord2f(0.0, 1.0);
  glVertex3f(x - hd, y + hd, z1);
  glTexCoord2f(1.0, 1.0);
  glVertex3f(x + hd, y + hd, z1);
  glTexCoord2f(1.0, 0.0);
  glVertex3f(x + hd, y - hd, z1);
  glEnd();

  glDepthMask(ByteBool(GL_TRUE));
 //   glDisable(GL_BLEND); --> zerstört das GL_Blend vom Plugin

end;
gruss Emil

littleDave 16. Jun 2008 13:25

Re: OpenGl Rendercontex schützen
 
Anscheindend setzt du ein Attribut, was später nicht mehr zurückgesetzt wird. Du kannst die Attribute zwischenspeichern und später wieder zurücksetzen. Versuchs mal mit diesem Code:

Delphi-Quellcode:
glPushAttrib(GL_ALL_ATTRIB_BITS);
try
  // Render Code
finally
  glPopAttrib;
end;
Das gleiche gibts auch für Matrizen: glPushMatrix und glPopMatrix
Bei den Matrizen wird nur die aktuell benutze Matrix gespeichert. Von daher würde ein Beispiel-Code so aussehen:

Delphi-Quellcode:
var iMatrixMode : integer;
begin
  glGetIntegerv(GL_MATRIX_MODE, @i);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix;
  try
    // Render Code
  finally
    glMatrixMode(GL_PROJECTION);
    glPopMatrix;
    glMatrixMode(iMatrixMode);
  end;
end;
(ungetestet, da Delphi im Moment nicht offen)

EWeiss 16. Jun 2008 13:30

Re: OpenGl Rendercontex schützen
 
Danke

Werde mal schaun ob ich damit zurecht komme.

EDIT:
Damit komme ich zurecht da die Matrix nur einmal verwendet wird
Delphi-Quellcode:
procedure HoldMatrixMode;
var
  iMatrixMode : integer;
begin
  glGetIntegerv(GL_MATRIX_MODE, @iMatrixMode);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix;
  try
    DrawPosition;
  finally
    glMatrixMode(GL_PROJECTION);
    glPopMatrix;
    glMatrixMode(iMatrixMode);
  end;
end;
Hier habe ich ein Problem
Delphi-Quellcode:
glPushAttrib(GL_ALL_ATTRIB_BITS);
try
  // Render Code
finally
  glPopAttrib;
end;
weiss nicht wo ich ansetzen soll da mehrere Attribute verändert werden
innerhalb der Drawposition

meinst du das so ?
Delphi-Quellcode:
glPushAttrib(GL_ALL_ATTRIB_BITS);
try
// RenderCode   
  glDepthMask(ByteBool(GL_FALSE));
  glDisable(GL_LIGHTING);
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE);
finally
  glPopAttrib;
end;
wie sieht das mit
Delphi-Quellcode:
glBindTexture(GL_TEXTURE_2D, BarTexture);
aus?

gruss Emil

littleDave 16. Jun 2008 13:58

Re: OpenGl Rendercontex schützen
 
Zitat:

Zitat von EWeiss
meinst du das so ?
Delphi-Quellcode:
glPushAttrib(GL_ALL_ATTRIB_BITS);
try
// RenderCode   
  glDepthMask(ByteBool(GL_FALSE));
  glDisable(GL_LIGHTING);
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE);
finally
  glPopAttrib;
end;

Genau so ist es richtig. Nach dem glBlendFunc solltest du natürlich noch rendern, sonst ist der ganze Aufwand ja umsonst. Nachdem du dann alles gerendert hast, kannst du dann mit glPopAttrib die ganzen Sachen wieder zurücksetzen.

Zitat:

Zitat von EWeiss
wie sieht das mit
Delphi-Quellcode:
glBindTexture(GL_TEXTURE_2D, BarTexture);
aus?

Ich glaub die übergebenen Werte werden NICHT wieder hergestellt. Ich bin mir gerade auch nicht ganz sicher, was glPushAttrib alles speichert. Aber probieren geht in diesem Fall schneller als alles nachzuschlagen ;-)

EWeiss 16. Jun 2008 14:05

Re: OpenGl Rendercontex schützen
 
Zitat:

Genau so ist es richtig. Nach dem glBlendFunc solltest du natürlich noch rendern, sonst ist der ganze Aufwand ja umsonst. Nachdem du dann alles gerendert hast, kannst du dann mit glPopAttrib die ganzen Sachen wieder zurücksetzen.
und da ist mein Problem
Was Rendern `? (keine dumme frage)
Ich befinde mich innerhalb DrawPosition

kann ja nun nicht wieder DrawPosition innerhalb Drawposition aufrufen.
wäre eine endlose sache.

zur veranschaulichung
Delphi-Quellcode:
procedure DrawPosition;
Var
    x1,x2,
  x12,x21,
  z1,y1,
  y2,x,y,hd : GLfloat;
  d1,d2    : GLfloat;
  overdraw : GLfloat;

begin

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45, BassBoxInfo^.w / BassBoxInfo^.h, 1, 1000.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  d1 := 0.05;
  d2 := 0.01;
  overdraw := 0.03;

  // PushAttrib
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  try
    // RenderCode
    glDepthMask(ByteBool(GL_FALSE));
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
  finally
    glPopAttrib;
  end;

   glBindTexture(GL_TEXTURE_2D, BarTexture);
   glColor4f( 1.0, 1.0, 1.0, 0.0);

   z1  := -4.0;
   y1  := -1.65;
   y2  := y1 + d1 - d2 + overdraw;
   x1  := -2.21;
   x2  := 2.20;
   x12 := x1 + (d1 - d2) * 0.3;
   x21 := x2 - (d1 - d2) * 0.3;

   glBegin(GL_QUADS);

      glTexCoord2f(0.0, 0.0);
      glVertex3f(x1, y2, z1);
      glTexCoord2f(1.0, 0.0);
      glVertex3f(x1, y1, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(1.0, 1.0);
      glVertex3f(x2, y1, z1);
      glTexCoord2f(0.0, 1.0);
      glVertex3f(x2, y2, z1);

   glEnd();

   glBindTexture(GL_TEXTURE_2D, PeaksTexture);

   hd :=(d1 - d2) * 4.0;
   x :=(x2 - x1) * CurrentPositionPart + x1;
   y :=(y2 + y1) * 0.5;

   glBegin(GL_QUADS);
  glTexCoord2f(0.0, 0.0);
  glVertex3f(x - hd, y - hd, z1);
  glTexCoord2f(0.0, 1.0);
  glVertex3f(x - hd, y + hd, z1);
  glTexCoord2f(1.0, 1.0);
  glVertex3f(x + hd, y + hd, z1);
  glTexCoord2f(1.0, 0.0);
  glVertex3f(x + hd, y - hd, z1);
  glEnd();

  // PushAttrib
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  try
    glDepthMask(ByteBool(GL_TRUE));
      glDisable(GL_BLEND);
  finally
    glPopAttrib;
  end;

end;
EDIT:
Bei Plugins ohne Texturen wird bei mir die Texture für die Bar nicht angezeigt! Hmmmm
Ach so der aufruf der RenderFunktion

Delphi-Quellcode:
procedure ProgressBarRender;
begin
    if (PosCounter = 0) then
    begin
      CurrentLength := BassBoxInfo.MediaLength;
      if (CurrentLength = 0) then
        CurrentLength := 1;

      CurrentPosition :=
        Round(1000 * Bass_ChannelBytes2Seconds(BB_VisDataThread.Stream,
        Bass_ChannelGetPosition(BB_VisDataThread.Stream, BASS_POS_BYTE)));

      If not (PlayState = 0) and not (CurrentPosition = -1)Then
      begin
        CurrentPositionPart := (CurrentPosition / 1000) / CurrentLength;
        if (CurrentPositionPart > 1) then
          CurrentPositionPart := 1;
    end else
      CurrentPositionPart := 0;
    end;
      PosCounter := (PosCounter +1) and 3;

    HoldMatrixMode;
end;
gruss Emil

littleDave 16. Jun 2008 14:15

Re: OpenGl Rendercontex schützen
 
Delphi-Quellcode:
procedure DrawPosition;
Var
    x1,x2,
  x12,x21,
  z1,y1,
  y2,x,y,hd : GLfloat;
  d1,d2    : GLfloat;
  overdraw : GLfloat;

begin

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45, BassBoxInfo^.w / BassBoxInfo^.h, 1, 1000.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  d1 := 0.05;
  d2 := 0.01;
  overdraw := 0.03;

  // PushAttrib
  glPushAttrib(GL_ALL_ATTRIB_BITS);
  try
    // RenderCode
    glDepthMask(ByteBool(GL_FALSE));
    glDisable(GL_LIGHTING);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
   
    // <---------- FINALLY WEG GEMACHT
   
    // Rendern
   glBindTexture(GL_TEXTURE_2D, BarTexture);
   glColor4f( 1.0, 1.0, 1.0, 0.0);

   z1  := -4.0;
   y1  := -1.65;
   y2  := y1 + d1 - d2 + overdraw;
   x1  := -2.21;
   x2  := 2.20;
   x12 := x1 + (d1 - d2) * 0.3;
   x21 := x2 - (d1 - d2) * 0.3;

   glBegin(GL_QUADS);

      glTexCoord2f(0.0, 0.0);
      glVertex3f(x1, y2, z1);
      glTexCoord2f(1.0, 0.0);
      glVertex3f(x1, y1, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(0.0, 0.3);
      glVertex3f(x12, y2, z1);
      glTexCoord2f(1.0, 0.3);
      glVertex3f(x12, y1, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(0.0, 0.7);
      glVertex3f(x21, y2, z1);
      glTexCoord2f(1.0, 0.7);
      glVertex3f(x21, y1, z1);
      glTexCoord2f(1.0, 1.0);
      glVertex3f(x2, y1, z1);
      glTexCoord2f(0.0, 1.0);
      glVertex3f(x2, y2, z1);

   glEnd();

   glBindTexture(GL_TEXTURE_2D, PeaksTexture);

   hd :=(d1 - d2) * 4.0;
   x :=(x2 - x1) * CurrentPositionPart + x1;
   y :=(y2 + y1) * 0.5;

   glBegin(GL_QUADS);
  glTexCoord2f(0.0, 0.0);
  glVertex3f(x - hd, y - hd, z1);
  glTexCoord2f(0.0, 1.0);
  glVertex3f(x - hd, y + hd, z1);
  glTexCoord2f(1.0, 1.0);
  glVertex3f(x + hd, y + hd, z1);
  glTexCoord2f(1.0, 0.0);
  glVertex3f(x + hd, y - hd, z1);
  glEnd();
 
  // <--------- TRY - BLOCK WEG GEMACHT
 
  finally
    glPopAttrib;
  end;

end;

EWeiss 16. Jun 2008 14:31

Re: OpenGl Rendercontex schützen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Danke ;)

Bei mir ging ein licht auf und habe es genauso geändert wie du es mir gezeigt hast.

JEtzt habe ich nur noch ein Problem mit den Texturen ..
Hier mal der Code von einer der Plugins was es beim Rendern macht.

Komme nicht dahinter warum mir die Texture nicht angezeigt wird.

Es geht nur um den OpenGl Kram das andere kannst du ignorieren ;)

Delphi-Quellcode:
    CASE %BBP_RENDER
         '// Draw the scene using BBP.LeftPeak and BBP.RightPeak
         LOCAL nLValue, nRValue, RGBColor AS LONG
         LOCAL pulse AS DOUBLE, R1, G1, B1, R2, G2, B2 AS BYTE

         nLValue = (BBP.Lpeak / 700)
         nRValue = (BBP.Rpeak / 768)

         rXangle = rXangle + 0.3 '// grDXangle
         rYangle = rYangle + 0.5 '// grDYangle
         rZangle = rZangle + 0.7 '// grDZangle

         pulse = Max(nLValue, nRValue) / 7

         '// Pulsating section
         CALL glMatrixMode(%GL_PROJECTION)
         Call glLoadIdentity
         Call gluPerspective(35# - pulse, 1.25, 0.1, 150#)
         CALL glMatrixMode(%GL_MODELVIEW)
         '// Velocity section
         pulse = Abs(pulse / 4)
         rXangle = rXangle + pulse '// grDXangle
         rYangle = rYangle + pulse '// grDYangle
         rZangle = rZangle + pulse '// grDZangle

         '// Very important we must reassign BBP.RC to the new BBP.DC
         '// Note: don't use permanent DC, this produce better and smoother display
         Call wglMakeCurrent(BBP.DC, BBP.rc)

         CALL glClear(%GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT)

         Call glLoadIdentity
         Call gluLookAt(0#, 0#, 5#, 0#, 0#, 0#, 0#, 1#, 0#)
         Call glRotated(rXangle, 1#, 0#, 0#)
         Call glRotated(rYangle, 0#, 1#, 0#)
         Call glRotated(rZangle, 0#, 0#, 1#)

         '// Draw Diamond
         RGBColor = LevelColr(nLValue)
         R2 = BBP_GetRValue(RGBColor)
         G2 = BBP_GetGValue(RGBColor)
         B2 = BBP_GetBValue(RGBColor)

         RGBColor = LevelColr(nRValue)
         R1 = BBP_GetRValue(RGBColor)
         G1 = BBP_GetGValue(RGBColor)
         B1 = BBP_GetBValue(RGBColor)

         '// Up
         CALL glBegin(%GL_TRIANGLE_FAN)
         Call glColor3ub(R2, G2, B2): Call glVertex3d(0#, 1.414, 0#)
         Call glColor3ub(R1, G1, B1): Call glVertex3d(1#, 0#, 1#)
         Call glColor3ub(0, 0, 0):    Call glVertex3d(1#, 0#, -1#)

         Call glColor3ub(R1, G1, B1): Call glVertex3d(-1#, 0#, -1#)
         Call glColor3ub(0, 0, 0):    Call glVertex3d(-1#, 0#, 1#)
         Call glColor3ub(R1, G1, B1): Call glVertex3d(1#, 0#, 1#)
         Call glEnd

         '// Down
         CALL glBegin( %GL_TRIANGLE_FAN)
         Call glColor3ub(R2, G2, B2): Call glVertex3d(0#, -1.414, 0#)
         Call glColor3ub(R1, G1, B1): Call glVertex3d(1#, 0#, 1#)
         Call glColor3ub(64, 64, 64): Call glVertex3d(-1#, 0#, 1#)

         Call glColor3ub(R1, G1, B1): Call glVertex3d(-1#, 0#, -1#)
         Call glColor3ub(64, 64, 64): Call glVertex3d(1#, 0#, -1#)
         Call glColor3ub(R1, G1, B1): Call glVertex3d(1#, 0#, 1#)
         Call glEnd
gruss Emil

littleDave 16. Jun 2008 14:43

Re: OpenGl Rendercontex schützen
 
Das hat mehrere Gründe glaub ich:
  • Ich finde kein glBindTexture
  • ich finde kein glEnable(GL_TEXTURE_2D)
  • es werden keine Texturkoordinaten zwischen "CALL glBegin(%GL_TRIANGLE_FAN)" und "Call glEnd" übergeben (glTexCoord fehlt)

EWeiss 16. Jun 2008 14:51

Re: OpenGl Rendercontex schützen
 
Zitat:

Zitat von littleDave
Das hat mehrere Gründe glaub ich:
  • Ich finde kein glBindTexture
  • ich finde kein glEnable(GL_TEXTURE_2D)
  • es werden keine Texturkoordinaten zwischen "CALL glBegin(%GL_TRIANGLE_FAN)" und "Call glEnd" übergeben (glTexCoord fehlt)

glBindTexture existiert
Delphi-Quellcode:
    // <---------- FINALLY WEG GEMACHT
   
    // Rendern
   glBindTexture(GL_TEXTURE_2D, BarTexture);
   glColor4f( 1.0, 1.0, 1.0, 0.0);
das fehlt
Delphi-Quellcode:
glEnable(GL_TEXTURE_2D)
Das Plugin selbst übergibt keine Texture das macht meine Render Funktion
Nehme an es liegt an der fehlenden glEnable(GL_TEXTURE_2D)

werd es testen ..

EDIT:
Das funktioniert jetzt ;)
Nur noch zwei kleine probleme
Die Bar setzt sich nicht immer hundert prozent an das OpenGl Window.

Delphi-Quellcode:
procedure ResizeGLwindow(handle : HWND; X, Y, W, H: Integer);

begin

   SetWindowPos(handle,
                     0,
                     0,
                     0,
                     W,
                     H,
                     SWP_NOZORDER);

    glViewport(X, Y, W, H);
    BassBoxInfo^.Msg         := BBP_SIZE;
    BassBoxInfo^.ParentWindow := Handle;

    BbpPluginFunc(BassBoxInfo^);

    BassBoxInfo^.x := X;
    BassBoxInfo^.y := Y;
    BassBoxInfo^.w := W;
    BassBoxInfo^.h := H;

end;
befinden sich in BassBoxInfo^.

Das andere Problem die Bar Flacker bei den Plugins welche keine Texture haben
Wie kann man das verhindern ?

Gruss Emil

littleDave 16. Jun 2008 15:01

Re: OpenGl Rendercontex schützen
 
Zitat:

Zitat von EWeiss
Die Bar setzt sich nicht immer hundert prozent an das OpenGl Window.

Was meinst du damit? ein Beispiel-Screenshot würde helfen.

Zitat:

Zitat von EWeiss
befinden sich in BassBoxInfo^.

Sinn dieser Aussage :?::?:

Zitat:

Zitat von EWeiss
Das andere Problem die Bar Flacker bei den Plugins welche keine Texture haben
Wie kann man das verhindern ?

Was meinst du mit "Flackern"?


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:15 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz