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

Aktuelle Zeit: Mi Jul 09, 2025 09:55

Foren-Übersicht » Programmierung » Einsteiger-Fragen
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Karte malen
BeitragVerfasst: Mo Jun 28, 2004 15:42 
Offline
DGL Member

Registriert: Sa Feb 28, 2004 15:36
Beiträge: 40
Hallo,

ich habe mal wieder eine Frage.
Und zwar habe ich jetzt eine kleine Routine geschrieben, die mir eine zufällig generierte Karte aus vielen Quads zeichnet:

Code:
  1.  
  2.     for x := 1 to map_width do
  3.     begin
  4.       for y := 1 to map_width do
  5.       begin
  6.         Frustum.Calculate;
  7.         if (x > 1) and (y>1) then glBindTexture(GL_TEXTURE_2D,tex[(map[x,y])]);
  8.  
  9.         ///////////////////////////////
  10.         /// Haupt-Quad = ohne Alpha ///
  11.         ///////////////////////////////
  12.         glBegin(GL_QUADS);
  13.         glColor4f(1,1,1,1);
  14.  
  15.         if Frustum.IsSphereWithin(x*q_w +(q_w/2), y*q_w  +(q_w/2),b,q_w) then
  16.         begin
  17.         glTexCoord2f(0,0);  glVertex3f(x*q_w   , y*q_w    ,b);
  18.         glTexCoord2f(0,1);  glVertex3f(x*q_w +q_w, y*q_w    ,b);
  19.         glTexCoord2f(1,1);  glVertex3f(x*q_w +q_w, y*q_w  +q_w,b);
  20.         glTexCoord2f(1,0);  glVertex3f(x*q_w   , y*q_w  +q_w,b);
  21.         pf := pf + 1;
  22.         end;
  23.         ///////////////////////////////
  24.         /// Neben-Quads = mit Alpha ///
  25.         ///////////////////7///////////
  26.         if map[x-1,y-1] <> map[x,y] then
  27.         begin
  28.         if (Frustum.IsPointWithin(x*q_w -q_w, y*q_w  -q_w,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w  -q_w,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w -q_w, y*q_w    ,b)) then
  29.         begin
  30.         glColor4f(1,1,1,0);
  31.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w, y*q_w  -q_w,b);  //  Quad links unten
  32.         glTexCoord2f(0,1);  glVertex3f(x*q_w   , y*q_w  -q_w,b);
  33.         glColor4f(1,1,1,1);
  34.         glTexCoord2f(1,1);  glVertex3f(x*q_w   , y*q_w    ,b);
  35.         glColor4f(1,1,1,0);
  36.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w, y*q_w    ,b);
  37.         pf := pf + 1;
  38.         end;
  39.         end;
  40.  
  41.         if map[x-1,y] <> map[x,y] then
  42.         begin
  43.         if (Frustum.IsPointWithin(x*q_w -q_w, y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w -q_w, y*q_w  +q_w,b)) then
  44.         begin
  45.         glColor4f(1,1,1,0);
  46.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w, y*q_w    ,b);  //  Quad links
  47.         glColor4f(1,1,1,1);
  48.         glTexCoord2f(0,1);  glVertex3f(x*q_w   , y*q_w    ,b);
  49.         glTexCoord2f(1,1);  glVertex3f(x*q_w   , y*q_w  +q_w,b);
  50.         glColor4f(1,1,1,0);
  51.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w, y*q_w  +q_w,b);
  52.         pf := pf + 1;
  53.         end;
  54.         end;
  55.  
  56.         if map[x-1,y+1] <> map[x,y] then
  57.         begin
  58.         if (Frustum.IsPointWithin(x*q_w -q_w, y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   , y*q_w  +(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w -q_w, y*q_w  +(2*q_w),b)) then
  59.         begin
  60.         glColor4f(1,1,1,0);
  61.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w, y*q_w  +q_w,b);  //  Quad links oben
  62.         glColor4f(1,1,1,1);
  63.         glTexCoord2f(0,1);  glVertex3f(x*q_w   , y*q_w  +q_w,b);
  64.         glColor4f(1,1,1,0);
  65.         glTexCoord2f(1,1);  glVertex3f(x*q_w   , y*q_w  +(2*q_w),b);
  66.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w, y*q_w  +(2*q_w),b);
  67.                 pf := pf + 1;
  68.         end;
  69.         end;
  70.  
  71.         if map[x+1,y-1] <> map[x,y] then
  72.         begin
  73.         if (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w  -q_w,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w  -q_w,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w    ,b)) then
  74.         begin
  75.         glColor4f(1,1,1,0);
  76.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w  -q_w,b);  //  Quad rechts unten
  77.         glTexCoord2f(0,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w  -q_w,b);
  78.         glTexCoord2f(1,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w    ,b);
  79.         glColor4f(1,1,1,1);
  80.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w    ,b);
  81.               pf := pf + 1;
  82.         end;
  83.         end;
  84.  
  85.         if map[x+1,y] <> map[x,y] then
  86.         begin
  87.         if (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w    ,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w  +q_w,b)) then
  88.         begin
  89.         glColor4f(1,1,1,1);
  90.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w    ,b);  //  Quad rechts
  91.         glColor4f(1,1,1,0);
  92.         glTexCoord2f(0,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w    ,b);
  93.         glTexCoord2f(1,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w  +q_w,b);
  94.         glColor4f(1,1,1,1);
  95.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w  +q_w,b);
  96.         pf := pf + 1;
  97.         end;
  98.         end;
  99.  
  100.         if map[x+1,y+1] <> map[x,y] then
  101.         begin
  102.         if (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   +(2*q_w), y*q_w  +(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w -q_w+(2*q_w), y*q_w  +(2*q_w),b)) then
  103.         begin
  104.         glColor4f(1,1,1,1);
  105.         glTexCoord2f(0,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w  +q_w,b);  //  Quad rechts oben
  106.         glColor4f(1,1,1,0);
  107.         glTexCoord2f(0,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w  +q_w,b);
  108.         glTexCoord2f(1,1);  glVertex3f(x*q_w   +(2*q_w), y*q_w  +(2*q_w),b);
  109.         glTexCoord2f(1,0);  glVertex3f(x*q_w -q_w+(2*q_w), y*q_w  +(2*q_w),b);
  110.         pf := pf + 1;
  111.         end;
  112.         end;
  113.  
  114.         if map[x,y+1] <> map[x,y] then
  115.         begin
  116.         if (Frustum.IsPointWithin(x*q_w     , y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   +q_w, y*q_w  +q_w,b)) or (Frustum.IsPointWithin(x*q_w   +q_w, y*q_w  +(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w     , y*q_w  +(2*q_w),b)) then
  117.         begin
  118.         glColor4f(1,1,1,1);
  119.         glTexCoord2f(0,0);  glVertex3f(x*q_w     , y*q_w  +q_w,b);  // Quad oben
  120.         glTexCoord2f(0,1);  glVertex3f(x*q_w   +q_w, y*q_w  +q_w,b);
  121.         glColor4f(1,1,1,0);
  122.         glTexCoord2f(1,1);  glVertex3f(x*q_w   +q_w, y*q_w  +(2*q_w),b);
  123.         glTexCoord2f(1,0);  glVertex3f(x*q_w     , y*q_w  +(2*q_w),b);
  124.         pf := pf + 1;
  125.         end;
  126.         end;
  127.  
  128.         if (Frustum.IsPointWithin(x*q_w     , y*q_w  +q_w-(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w   +q_w, y*q_w  +q_w-(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w   +q_w, y*q_w  +(2*q_w)-(2*q_w),b)) or (Frustum.IsPointWithin(x*q_w     , y*q_w  +(2*q_w)-(2*q_w),b)) then
  129.         begin
  130.         glColor4f(1,1,1,0);
  131.         glTexCoord2f(0,0);  glVertex3f(x*q_w     , y*q_w  +q_w-(2*q_w),b);  // Quad unten
  132.         glTexCoord2f(0,1);  glVertex3f(x*q_w   +q_w, y*q_w  +q_w-(2*q_w),b);
  133.         glColor4f(1,1,1,1);
  134.         glTexCoord2f(1,1);  glVertex3f(x*q_w   +q_w, y*q_w  +(2*q_w)-(2*q_w),b);
  135.         glTexCoord2f(1,0);  glVertex3f(x*q_w     , y*q_w  +(2*q_w)-(2*q_w),b);
  136.         glEnd;
  137.         pf := pf + 1;
  138.         end;
  139.       end;
  140.     end;
  141.     glEnd;
  142.  


^^sorry dass es so viel code ist, aber ich denke, dass es wichtig sein könnte...

Infos:
1. Der Code funktioniert.
2. "Frustum" stammt aus dem Frustum-Culling Tutorial auf www.delphigl.de
3. "pf" ist eine Variable die mir sagt, wie viele Quads aktuell gezeichnet werden

Meine Frage: Da der Code extremst langsam ist, bin ich ratlos! Ich habe keine Ahnung wieso der das so langsam nur berechnen kann. Wie viele Quads kann man denn so auf einer Radeon9000M zeichnen bevor er anfängt zu ruckeln? Er sagt mir, er würde so ca. 250 Quads zeichnen. Sind das zu viele?
Wie könnte man das verbessern?

Ich habe mir schon ein paar Gedanken dazu gemacht aber ich habe keine Ahnung wie ich die realisieren könnte. Und zwar wollte ich die Karte quasi compilieren also zu einem großen Bild machen und dann die Karte einfach auf ein großes Quad zeichen. Ich weiß aber nicht, wie ich das machen könnte.

Danke schon mal im Voraus.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mo Jun 28, 2004 16:13 
Offline
DGL Member
Benutzeravatar

Registriert: Mo Sep 23, 2002 19:27
Beiträge: 5812
Programmiersprache: C++
  • Du berechnest das Frustum jedes mal wenn du ein Quad renderst, was deine CPU wohl total in die Knie zwingt. Normalerweise berechnet man das nur einmal nach Einstellung der Perspektive.
  • Du testes jeden Punkt eines Quads gegen das Frustum, und da diese Tests komplett auf der CPU laufen, verschiebst du die Abhängigkeit deiner Anwendung stark auf die CPU, wodurch Vorteile modernerer Grafikkarten zu Nichte gemacht werden.
  • 250 Quads (~500 Dreiecke) sind natürlich nicht viel, aber wenn du deine Quads bildschirmfüllend renderst, dann bist du wahrscheinlich füllratenlimitiert, was sich leicht testen lässt : Senke die Auflösung, und wenn du dann bessere Framerate hast, ist dies der Fall. Das ist dann Limitation deiner Graka und viel kannst du bei deinem Falle dann nicht machen.
  • Texturenwechsel sind recht kostspielig. Du solltest deine Quads daher sortiert nach Texturen rendern.


Ich schätze aber mal das dein größtes Problem momentan Punkt 1 ist.

P.S. : Schau dir mal mein 2D-Tutorial an, da wird genau sowas realisiert.

_________________
www.SaschaWillems.de | GitHub | Twitter | GPU Datenbanken (Vulkan, GL, GLES)


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


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 10 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:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.008s | 14 Queries | GZIP : On ]