Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 16:55

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: 2D - Problem mit Animationen
BeitragVerfasst: Mo Jun 26, 2006 17:24 
Offline
DGL Member

Registriert: Di Mai 24, 2005 16:43
Beiträge: 710
Hi, ich versuche in meiner Engine gerade eine Klasse für Animationen einzubauen, wenn ich diese jedoch jetzt benutze, sehe ich einen schwarzen klotz (da sollte eigentlich die animation drauf) und der rest ist auf einmal weiß, erklären kann ich mir das allerdings nicht, ich weiß auch nicht, ob das so funktioniert, hier einmal relevanter code:
Code:
  1.  
  2. //Standardeigenschaften
  3.   TGraphicObject = class
  4.     constructor Create;
  5.   public
  6.     position,
  7.     size: TVector2D;
  8.     z: integer;
  9.   end;
  10.  
  11. //Klasse für EINE Animation
  12.   TAnimation = class
  13.     constructor Create;
  14.     destructor Destroy; override;
  15.     procedure Free;
  16.   public
  17.     Position,
  18.     coordx,
  19.     coordy: integer;
  20.     Texture: TglBitmap2D;
  21.     AnimWidth,
  22.     AnimHeight: integer;
  23.     Duration: integer;  // in ms
  24.     procedure LoadFromFile(pFilename: string);
  25.     procedure Reset;
  26.   end;
  27.  
  28.   TAnimObj = class(TGraphicObject)
  29.  
  30. //Array aller Animationen des Objektes
  31.     Animations: array of TAnimation;
  32. //Liste mit den Namen der Animationen
  33.     AnimationName: THashedStringList;
  34.     constructor Create;
  35.     destructor Destroy; override;
  36.     procedure Free;
  37.   private
  38. //alpha beta gamma, das übliche ^^
  39.     Fangle: single;
  40.     Fvisible: boolean;
  41.     Fcolor: TColor;
  42.     Fusealpha: boolean;
  43.     Falpha: integer;
  44.     Falphatest: boolean;
  45.     Falphatolerance: single;
  46. //prozeduren zum setzen von eigenschaften
  47.     procedure SetAngle(const value: single);
  48.     procedure SetAlpha(const value: integer);
  49.     procedure SetAlphaTolerance(const value: single);
  50.   public
  51. //  Unwichtig ^^
  52.     RotationOffset: TVector2d;
  53.  
  54. //Eine Animation hinzufügen
  55.     procedure AddAnimation(pFilename, pAnimationName: string);
  56.  
  57. //Liefert Pointer auf Array Element
  58.     function GetAnimation(pAnimationName: string): TAnimation;
  59.  
  60. //Das nächste Bild ausgeben
  61.     procedure Play(pEngine: TEngine; pAnimationName: string; ploop: boolean);
  62.  
  63. //Eigenschaften
  64.     property angle: single read Fangle write SetAngle;
  65.     property visible: boolean read Fvisible write Fvisible;
  66.     property color: TColor read Fcolor write FColor;
  67.     property usealpha: boolean read Fusealpha write Fusealpha;
  68.     property alpha: integer read Falpha write SetAlpha;
  69.     property alphatest: boolean read Falphatest write Falphatest;
  70.     property alphatolerance: single read Falphatolerance write SetAlphaTolerance;
  71.   end;
  72.  


Code:
  1.  
  2. constructor TAnimation.Create;
  3. begin
  4.   inherited Create;
  5.   Texture := TglBitmap2d.Create;
  6.   coordx := 0;
  7.   coordy := 0;
  8.   position := 0;
  9. end;
  10.  
  11. destructor TAnimation.Destroy;
  12. begin
  13.   Texture.Free;
  14.   inherited Destroy;
  15. end;
  16.  
  17. procedure TAnimation.Reset;
  18. begin
  19.   coordx := 0;
  20.   coordy := 0;
  21.   position := 0;
  22. end;
  23.  
  24. procedure TAnimation.LoadFromFile(pFilename: string);
  25. begin
  26.   Texture.LoadFromFile(pFilename);
  27.   Texture.GenTexture;
  28. end;
  29.  
  30. constructor TAnimObj.Create;
  31. begin
  32.   inherited Create;
  33.   setlength(Animations, 0);
  34.   AnimationName := THashedStringList.Create;
  35.   Fangle := 0;
  36.   Fvisible := true;
  37.   FColor := clwhite;
  38.   Fusealpha := false;
  39.   Falpha := 0;
  40.   Falphatest := false;
  41.   Falphatolerance := 0.1;
  42.   RotationOffset.x := 0;
  43.   RotationOffset.y := 0;
  44. end;
  45.  
  46. destructor TAnimObj.Destroy;
  47. var
  48.   i: integer;
  49. begin
  50.   for i := low(Animations) to high(Animations) do
  51.     Animations[i].Free;
  52.   AnimationName.Free;
  53.   inherited Destroy;
  54. end;
  55.  
  56. procedure TAnimObj.AddAnimation(pFilename, pAnimationName: string);
  57. var
  58.   aindex: integer;
  59. begin
  60.   setlength(Animations, length(Animations) + 1);
  61.   aindex := high(animations);
  62.   Animations[aindex] := TAnimation.Create;
  63.   Animations[aindex].LoadFromFile(pFilename);
  64.   AnimationName.Add(pAnimationName);
  65. end;
  66.  
  67. function TAnimObj.GetAnimation(pAnimationName: string): TAnimation;
  68. begin
  69.   result := Animations[AnimationName.IndexOf(pAnimationname)];
  70. end;
  71.  
  72. //zeichnen
  73. procedure TAnimObj.Play(pEngine: TEngine; pAnimationName: string; ploop: boolean);
  74. var
  75.   aIndex: integer;
  76. begin
  77.  
  78. // Sichtbar ? nein - dann weg damit
  79.   if not Fvisible then
  80.     exit;
  81.  
  82. //Falls Alpha vorhanden, das ganze in die alphaliste der engine packen, die übernimmt das rendern <!-- s;) --><img src=\"{SMILIES_PATH}/icon_wink.gif\" alt=\";)\" title=\"Wink\" /><!-- s;) -->
  83.   if Fusealpha then
  84.   begin
  85.     setlength(pEngine.Objects, length(pEngine.Objects) + 1);
  86.     pEngine.Objects[high(pEngine.Objects)].aList := glGenLists(1);
  87.     pEngine.Objects[high(pEngine.Objects)].z := z;
  88.     glNewList(pEngine.Objects[high(pEngine.Objects)].aList, GL_COMPILE);
  89.   end;
  90.  
  91. //Matrix auf den Matrix stack pushen
  92.   glpushmatrix;
  93.  
  94. //Auf die Objekt position translaten
  95.   glTranslatef(position.x * (pEngine.Form.clientwidth / pEngine.width), position.y * (pEngine.Form.clientheight / pEngine.height), 0);
  96.  
  97. //Drehen
  98.   glRotatef(Fangle, 0, 0, 1);
  99.  
  100. //Eventueller rotationspunkt
  101.   glTranslatef(-rotationoffset.x, -rotationoffset.x, 0);
  102.  
  103. //Index der gewählten Animation
  104.   aIndex := AnimationName.IndexOf(pAnimationName);
  105.  
  106. //Texture der Animation binden
  107.   Animations[aIndex].Texture.Bind;
  108.  
  109. //Blending für Alpha
  110.   if Fusealpha then
  111.   begin
  112.     RGBAf(Fcolor, Falpha);
  113.     glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  114.     glEnable(GL_BLEND);
  115.   end else
  116.      RGBf(Fcolor);  //ansonsten nur farbe (standard weiß)
  117.  
  118. //für alphatest
  119.   if Falphatest then
  120.   begin
  121.     glEnable(GL_ALPHA_TEST);
  122.     glAlphaFunc(GL_GREATER, Falphatolerance);
  123.   end;
  124.  
  125. //zeichnen - hoffe das ist so richtig ^^
  126.   glBegin(GL_QUADS);
  127.     with Animations[aIndex] do
  128.     begin
  129.       glTexCoord2f(coordx * (1 / (texture.Width / Animwidth)),coordy * (1 / (texture.Height / Animheight))); glVertex3f(-(size.x * (pEngine.Form.clientwidth / pEngine.width))/2, -(size.y * (pEngine.Form.clientheight / pEngine.height))/2, z - maxdepth + 2);
  130.       glTexCoord2f(         (1 / (texture.Width / Animwidth)),coordy * (1 / (texture.Height / Animheight))); glVertex3f( (size.x * (pEngine.Form.clientwidth / pEngine.width))/2, -(size.y * (pEngine.Form.clientheight / pEngine.height))/2, z - maxdepth + 2);
  131.       glTexCoord2f(         (1 / (texture.Width / Animwidth)),(1 / (texture.Height / Animheight))); glVertex3f( (size.x * (pEngine.Form.clientwidth / pEngine.width))/2,  (size.y * (pEngine.Form.clientheight / pEngine.height))/2, z - maxdepth + 2);
  132.       glTexCoord2f(coordx * (1 / (texture.Width / Animwidth)),(1 / (texture.Height / Animheight))); glVertex3f(-(size.x * (pEngine.Form.clientwidth / pEngine.width))/2,  (size.y * (pEngine.Form.clientheight / pEngine.height))/2, z - maxdepth + 2);
  133.     end;
  134.   glEnd;
  135.  
  136. //Texture Unbinden
  137.   Animations[aIndex].Texture.UnBind;
  138.  
  139. //Blending wieder deaktivieren, falls es benötigt wurde
  140.   if Fusealpha then
  141.     glDisable(GL_BLEND);
  142.  
  143. //das gleiche bei dem alpha test
  144.   if Falphatest then
  145.     glDisable(GL_ALPHA_TEST);
  146.    
  147. //Matrix wieder zurücktransformieren
  148.   glpopmatrix;
  149.  
  150. //List schließen (falls nötig)
  151.   if Fusealpha then
  152.   begin
  153.     glEndList;
  154.  
  155. //    pEngine.sorted := false;  //altbacken
  156.   end;
  157.  
  158. //Animation - hier auch unsicherheiten ^^ aber daran liegts wohl nicht
  159.   with Animations[aindex] do
  160.   begin
  161.     inc(position);
  162.     if (position >= ((Duration) / (AnimWidth * Animheight))) then
  163.     begin
  164.       position := 0;
  165.       inc(coordx);
  166.       if coordx > (Texture.Width / Animwidth) then
  167.       begin
  168.         coordx := 0;
  169.         inc(coordy);
  170.       end;
  171.       if (coordy > (Texture.Height / Animheight)) and ploop then
  172.       begin
  173.         coordx := 0;
  174.         coordy := 0;
  175.       end;
  176.     end;
  177.   end;
  178. end;
  179.  


hoffe mir kann einer helfen :(

vielen dank schonmal, mfg


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Jun 26, 2006 18:43 
Offline
DGL Member

Registriert: Di Mai 24, 2005 16:43
Beiträge: 710
wenn ich das unbind weglasse, oder danach glEnable(GL_TEXTURE_2D) aufrufe, sehe ich wieder den hintergrund, aber der klotz ist schwarz Oo

Es liegt also doch an meiner berechung :(


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Jun 28, 2006 18:25 
Offline
DGL Member

Registriert: Di Mai 24, 2005 16:43
Beiträge: 710
Seth hat geschrieben:
wenn ich das unbind weglasse, oder danach glEnable(GL_TEXTURE_2D) aufrufe, sehe ich wieder den hintergrund, aber der klotz ist schwarz Oo

Es liegt also doch an meiner berechung :(


EDIT: funzt jetzt, die texturbreiten habe ich garnet gebraucht ;)


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.014s | 16 Queries | GZIP : On ]