Autor Beitrag
Passi077
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 16:35 
Hi,

folgendes Problem:

Ich hab ein Polygon mit beliebig vielen Punkten gegeben, und dieses möchte ich nun mit einem frei wählbaren Muster, also einem Bitmap mit z.B. der Größe 32x32 Pixel, füllen.

Kann man das irgendwie hinkriegen?

Edit: Wenns eine Möglichkeit gibt, ein 2D Polygon mit OpenGL mit der Textur drauf zu zeichnen, ist auch ok ;)

Danke + Grüße
Passi
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Mo 11.07.05 17:04 
Hmm, das ist jetzt nur so ne Idee, aber vllt. klappt's ja. Du könntest dein Bitmap erstellen, dass die Maße deiner Figur hat. Die ganze Fläche füllst du mit dem Muster, das du verwenden möchtest. Dann zeichnest du ein Polygon drum und füllst die Fläche drumherum mit einer Farbe, die du dann als Transparent definierst. Dann noch auf das eigentliche Bild kopieren. Wie man bzw. ob man überhaupt um ein Polygon drumherum füllen kann, weiss ich nicht. Aber vllt. hilft die Idee ja bei einer anderen Idee :D

Gruß,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 11.07.05 17:19 
mit opengl sehe ich da kein problem :?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.07.05 17:20 
Welcher Art ist die Musterung zu verstehen? Tiled \ Strechted? Ist das Polygon Clipping Mask?

Davon hängt das ab.

Wenn das Polygon clipping mask ist, empfielt sich die Nutzung des Stencil-Puffers (Polygon rein und zum Clippen eines Quads mit den Eckpunkten der Textur nutzen).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 17:22 
Das hab ich mir auch überlegt, aber da gibts eben das Problem mit dem da drumrum füllen... mit Floodfill kann man ja leider keine Tolerance einstellen - und selbst wenn man das könnte gäbe es dann noch das Problem wenn PenColor und Texturhintergrund die selbe Farbe haben... dann wird mein Polygon einfach mit gefüllt.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 17:25 
Zitat:

Welcher Art ist die Musterung zu verstehen? Tiled \ Strechted? Ist das Polygon Clipping Mask?


Also die Musterung soll tiled sein..

Zur 2. Frage hab ich leider keine Antwort, weil ich keine Ahnung hab wie man in OpenGL Polygone zeichnet :?:

Ich hab bisher nur Vierecke hinbekommen :oops:

Aber schon mal schön zu hören, dass es mit OpenGL funktioniert :)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.07.05 18:02 
Clipping Mask: Heißt, dass alles was vom Polygon auf dem Bildschirm zu sehen ist hat die Musterung. Da wo das Polygon nicht ist fängt die Musterung zwar schon an, aber wird nicht gezeichnet.

hmmm. Bei Tiled muss ich leider die Experten ran lassen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 18:07 
K Thx,

naja dann is wohl nicht clipped Performanceschonender..

aber das ist grad mal nicht ganz so wichtig, ich könnte schon viel weitermachen, wenn ich wüsste wie ich aus den mir gegebenen Punkten (Array of TPoint) ein Polygon in OpenGL zeichnen kann, 2D? Textur ist vorerst nicht ganz so wichtig..

Hab vorhin mal Google bemüht, aber irgendwie finde ich da kaum was was mir hilft, weil die Kombination "OpenGL" und "Polygon" blöderweise ziemlich oft vorkommt...
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 11.07.05 18:21 
ausblenden Delphi-Quelltext
1:
2:
3:
glBegin(GL_POLYGON);
glVertex2f(x,y); //für jeden Punkt)
glEnd;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 21:00 
Danke nochmal, funktioniert wunderbar :) !

Wenn mir nun hoffentlich noch jemand sagen kann, wie ich da ne Textur gekachelt drauflegen kann, wär's super !
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 28

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 11.07.05 21:01 
hast du denn schon ne textur drauf ?
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 21:14 
Ne, meine Versuche dazu sind kläglich gescheitert :roll:
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 21:37 
Mhh Noch was:

Ich hab mir gerade mal einen Editor für Polygone gemacht der die Koordinaten dann in eine Datei speichert, die das andere Programm dann ausliest und anhand derer das Polygon zeichnet.

Leider ist da eine extreme Ungenauigkeit zu erkennen, wenn sich mehrere Y-Werte Überlagern. Um das mal zu veranschaulichen, hier 2 Bilder, das erste aus dem Editor, das 2. ist das gezeichnete Polygon:

www.chris-tec.net/POL.jpg
www.chris-tec.net/POL2.jpg

Woran liegt das und vor allem, wie kann ich das ändern?

Der Code zum Zeichnen des Polygons ist folgender:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
glBegin(GL_POLYGON);

  for i := 0 to high(coords)-1 do
  begin

    glVertex2f(coords[i].X, coords[i].y); //für jeden Punkt)

  end;

glEnd;


Coords ist das Array of TPoint in dem folgende Werte drinstehen (jeweils erst X, dann Y):

109,245
93,231
75,208
74,191
77,172
99,139
111,131
144,118
184,117
228,131
243,155
245,175
238,195
232,203
224,220
232,231
247,236
256,234
278,216
284,193
289,167
288,140
286,124
287,106
293,96
304,89
330,90
362,102
369,122
371,159
369,183
361,211
350,230
333,253
323,266
298,298
283,308
256,326
239,330

Danke und Grüße
Passi

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Mo 11.07.05 21:39 
WOOOOOOW :shock:

Würde es dir was ausmachen deinen Post zu editieren und entwder Zeilenumbrüche oder Leerzeichen einzufügen, weil so wird der Post recht breit ...

Alstar

//EDIT: Zu spät gepostet ... :oops:
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 11.07.05 22:14 
OpenGl zeichnet mit GL_POLYGON nur konvexe Polygone. Es funktioniert teils auch für nicht-konvexe Polygone (deswegen kommt's halbwegs richtig; aber nur halbwegs), du kannst aber nicht Gift draufnehmen, dass es klappen wird. Willst du sicher gehen, dass es klappt, musst du das Polygon zuerst "tesselieren" (siehe gluTessBeginPolygon, u.a.). Auch aus Performancegründen macht es Sinn, das Polygon zuerst in Dreiecke aufzuteilen.
(Ein konvexes Polygon ist ein Polygon ohne "Einbuchtungen". D.h. wenn du eine gespannte Schnur drumherum wickelst berührt diese den ganzen Rand)
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 11.07.05 22:35 
Puh das Ganze wird so langsam doch recht kompliziert ^^

Also, erst mal: hab ich das richtig verstanden, dass ich nun statt dem bisherigen Code einfach folgenden nehmen könnte:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
gluTessBeginPolygon(tobj, NULL);
  gluTessBeginContour(tobj);

  for i := 0 to high(coords)-1 do  
  begin  

    gluTessVertex(tobj, coords[i].X, coords[i].y);

  end;

  gluTessEndContour(tobj);
gluTessEndPolygon(tobj);


? Wenn ja, hab ich nur ein Problem mit dem tobj bzw mit

ausblenden Delphi-Quelltext
1:
function gluNewTess : PGLUtesselator;					


Das ist ja anscheinend wieder so ein seltsamer Pointer ^^ mit dem ich nix anfangen kann.. ausserdem weiß ich nicht wie ich mein Polygon da reinladen kann, weil das braucht man ja anscheinend nur für die Tesselierung und kann es danach wieder aus diesem Pointer rauswerfen.. ?
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 11.07.05 22:42 
Ne, so einfach geht das nicht. Du musst mit der Aktion eine glNewList erzeugen: Mit glNewList startest du quasi eine "Aufzeichnung". In einer Schleife führst du dann gluTessVertex aus (Parameter => Eckpunkte des Polygons). Wenn du damit fertig bist werden eine Reihe von Befehlen mit glBegin/glEnd/glVertex3fv (damit das klappt musst du einige Callbacks definieren). Diese Befehle werden dann durch die Callbacks in die Display-List geschrieben. Zum Zeichnen des Polygons führst du dann einfach die Displayliste per glCallList aus.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mi 13.07.05 11:47 
Hi nochmal

erst mal Danke :)!

Aber ich krieg es einfach nicht hin, liegt wahrscheinlich daran, dass ich jetzt eben kaum Zeit hatte um mich in OepnGL einzuarbeiten.

Ich versteh einfach leider nicht, wie das funktioniert.

Also mein Versuch ist blöderweise schon am ersten Schritt gescheitert ^^

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
 
      tess := gluNewTess();

      // Callbacks festlegen 
      gluTessCallback (tess, GLU_TESS_BEGIN, tcbBegin);   // <- alles undefiniert, was muss tcbBegin etc. sein?
      gluTessCallback (tess, GLU_TESS_VERTEX, tcbVertex);
      gluTessCallback (tess, GLU_TESS_END, tcbEnd);


Dann muss ich anscheinend die Daten des Polygons senden, worauf dann die Tesselierung stattfindet, und dann kann ich das Polygon über die Callbacks zeichnen.

So. Jetzt frag ich echt etwas, was ich normal nie fragen würde ^^, aber könnte mir jemand einfach den kompletten Code für ein konkaves Polygon in OpenGL geben? Wie gesagt, normal guck ich schon das ich das alles selber hinkriege, aber in diesem Fall ist es besonders wegen dem zeitdruck blöd, da das Projekt bis Freitag fertig sein muss.

Es wäre soweit fast alles fertig, wenn ich ne einfache Procedure zum Zeichnen der Polygone hätte...

Ich hoffe es erbarmt sich jemand, sonst müsste mein Game mit hässlichen konvexen Polygonen auskommen :(

Grüße
Passi

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 13.07.05 18:23 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
const
 N = 100;
var
 GLArrayd3: TGLArrayd3;
 GluObj: PGLUtesselator;
 myPolygon: TGLUInt;
 myPointList: array of TGLArrayf3;
 I: Integer;
begin
  // Definition eines nicht-konvexen Objektes
  SetLength(myPointList, N);
  for I := 0 to N-1 do
  begin
    myPointList[I][0] := cos(2*pi*I/N)*(1+cos(2*pi*I/N*8)/4);
    myPointList[I][1] := sin(2*pi*I/N)*(1+cos(2*pi*I/N*8)/4);
    myPointList[I][2] := 0;
  end;

  // Display-List erstellen
  myPolygon := glGenLists(1); 
  glNewList(myPolygon, GL_COMPILE);

  // Tesselierung in konkave Polygone
  GluObj := gluNewTess;
  gluTessCallback(GluObj, GLU_TESS_VERTEX, @glVertex3fv);
  gluTessCallback(GluObj, GLU_TESS_BEGIN, @glBegin);
  gluTessCallback(GluObj, GLU_TESS_END, @glEnd);

  gluTessBeginPolygon(GluObj, nil);
  gluTessBeginContour(GluObj);
  for I := 0 to length(myPointList)-1 do
  begin
    GLArrayd3[0] := myPointList[I][0];
    GLArrayd3[1] := myPointList[I][1];
    GLArrayd3[2] := myPointList[I][2];
    gluTessVertex(GluObj, GLArrayd3, @myPointList[I]);
  end;
  gluTessEndContour(GluObj);
  gluTessEndPolygon(GluObj);
  glEndList;
  gluDeleteTess(GluObj);

  // Das Objekt zeichnen...
  glCallList(myPolygon);
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Do 14.07.05 16:41 
Hi,

vielen vielen Dank für den Code :) !!

Funktioniert wunderbar.. aber ist das normal, dass da wahnsinnig viel Leistung gebraucht wird?

Mein Game läuft ohne die Polygone mit 600 FPS, aber wenn ich nur 3 Polygone mit je etwa 20 Koordinaten zeichnen lasse, fällt die Framerate auf nur noch knapp 200 FPS ab.. :?:

Und dann noch die Sache mit der Textur.. ich hab mit glvertex3f rumprobiert aber ich krieg immer nur den ersten Pixel der Textur der auf das komplette Polygon gezeichnet wird.. ?


Und nochmal Danke euch allen, find ich super das ihr mir so helf :) !