Les polygones
Les polygones
Salut,
J'ai deja fait des anims en polygones a la "another world". Mais j'ai remarqué que c'etait plutot lent. Hors, en emulant another world amiga sur un pc, les polygones sont super rapides. Pourtant, il y a l'emulation qui doit ralentir l'affichage (j'espere que vous me suivez). Pourtant, another world amiga est super rapide.
D'où ma question : quelle est la meilleure instruction pour afficher un polygone rapide sous PB ? (je suis ouvert a tout, meme aux api)
Danke
J'ai deja fait des anims en polygones a la "another world". Mais j'ai remarqué que c'etait plutot lent. Hors, en emulant another world amiga sur un pc, les polygones sont super rapides. Pourtant, il y a l'emulation qui doit ralentir l'affichage (j'espere que vous me suivez). Pourtant, another world amiga est super rapide.
D'où ma question : quelle est la meilleure instruction pour afficher un polygone rapide sous PB ? (je suis ouvert a tout, meme aux api)
Danke
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
En utilisant le moteur 3D ogre intégré à purebasic ou en utilisant les sprites comme cela:
M.
Code : Tout sélectionner
;Program description: Sprite transformation effects
;Author: Demivec
;Written for: Originally for PB 4.61, with Windows OS, may not function correctly for other OS.
; It does not function correctly with the OpenGL subsystem.
;Date Written: 2 July 2012
;Last Updated: 4 October 2015 for PB 5.40b8 and added some additional features.
;works with pb 5.73b4
EnableExplicit
; Structure Point
; x.i
; y.i
; EndStructure
Structure Point_f
x.f
y.f
EndStructure
Enumeration sprites
#spr_pb
#spr_corner
#spr_text_1
#spr_text_2
#spr_text_3
#spr_text_4
#spr_mousePointer
EndEnumeration
Enumeration fonts
#font_large
#font_small
EndEnumeration
Enumeration windows
#win_main
EndEnumeration
Procedure handleError(value, text.s = "Unknown Error.")
If value = 0
MessageRequester("Error", text)
End
EndIf
EndProcedure
;Sprite info: (width, height) = original dimensions, (newWidth, newHeight) = zoom dimensions,
; degree = rotation amount, (cx,cy) = center point for rotation
Procedure MakeSpriteTransformation(spriteID, width, height, cx, cy, degree, newWidth, newHeight)
Protected.Point_f p1, p2, p3, p4
Protected.f wf = width / newWidth, hf = height / newHeight
If degree = 0
;simple transformation: no rotation, only zooming and translation movements possible
p1\x = (( -cx) / wf) - 0.5: p1\y = (( -cy) / hf) - 0.5
p2\x = ((width - cx) / wf) - 0.5: p2\y = (( -cy) / hf) - 0.5
p3\x = ((width - cx) / wf) - 0.5: p3\y = ((height - cy) / hf) - 0.5
p4\x = (( -cx) / wf) - 0.5: p4\y = ((height - cy) / hf) - 0.5
Else
;more complex transformation: rotation (around point cx,cy) and zooming possible
Protected.f angCos = Cos(Radian(degree)), angSin = Sin(Radian(degree))
Protected.f v1, v2, v3, v4, v5, v6, v7, v8
v1 = -cx * angCos: v3 = -cy * angSin
v2 = -cx * angSin: v4 = -cy * angCos
v6 = (width - cx) * angCos: v7 = (height - cy) * angSin
v5 = (width - cx) * angSin: v8 = (height - cy) * angCos
p1\x = ((v1 - v3) / wf) - 0.5: p1\y = ((v4 + v2) / hf) - 0.5
p2\x = ((v6 - v3) / wf) - 0.5: p2\y = ((v4 + v5) / hf) - 0.5
p3\x = ((v6 - v7) / wf) - 0.5: p3\y = ((v8 + v5) / hf) - 0.5
p4\x = ((v1 - v7) / wf) - 0.5: p4\y = ((v8 + v2) / hf) - 0.5
EndIf
TransformSprite(spriteID, p1\x, p1\y, p2\x, p2\y, p3\x, p3\y, p4\x, p4\y)
EndProcedure
;iso (squish) rotated clockwise degrees
Procedure MakeSpriteIsoClockwise(spriteID, width, height, cx, cy, degree, newWidth, newHeight)
MakeSpriteTransformation(spriteID, width, height, cx, cy, degree, newWidth, newHeight)
EndProcedure
;iso (squish) rotated counter-clockwise degrees
Procedure MakeSpriteIsoCounterClockwise(spriteID, width, height, cx, cy, degree, newWidth, newHeight)
MakeSpriteTransformation(spriteID, width, height, cx, cy, 360 - degree, newWidth, newHeight)
EndProcedure
Procedure MakeSpriteRotate(SpriteID, cx, cy, degree)
Protected width = SpriteWidth(SpriteID), height = SpriteHeight(SpriteID)
ZoomSprite(SpriteID, #PB_Default, #PB_Default)
MakeSpriteTransformation(spriteID, width, height, cx, cy, degree, width, height)
EndProcedure
Procedure MakeSpriteZoomHorizontal(SpriteID, cx, cy, newWidth)
Protected width = SpriteWidth(SpriteID), height = SpriteHeight(SpriteID)
ZoomSprite(SpriteID, #PB_Default, #PB_Default)
MakeSpriteTransformation(spriteID, width, height, cx, cy, 0, newWidth, height)
EndProcedure
Procedure MakeSpriteZoomVertical(SpriteID, cx, cy, newHeight)
Protected width = SpriteWidth(SpriteID), height = SpriteHeight(SpriteID)
ZoomSprite(SpriteID, #PB_Default, #PB_Default)
MakeSpriteTransformation(spriteID, width, height, cx, cy, 0, width, newHeight)
EndProcedure
Procedure MakeSpriteNormal(SpriteID, cx = 0, cy = 0)
Protected width = SpriteWidth(SpriteID), height = SpriteHeight(SpriteID)
ZoomSprite(SpriteID, #PB_Default, #PB_Default)
MakeSpriteTransformation(spriteID, width, height, cx, cy, 0, width, height)
EndProcedure
handleError(InitSprite(), "Can't open screen & sprite enviroment.")
handleError(InitMouse(), "Can't initialize mouse handler.")
handleError(InitKeyboard(), "Can't initialize keyboard handler.")
handleError(OpenWindow(#win_main, 0, 0, 800, 600, "Sprite Transformations, drag numbered corners to transform",
#PB_Window_SystemMenu | #PB_Window_ScreenCentered), "Can't open window.")
handleError(OpenWindowedScreen(WindowID(#win_main), 0, 0, 800, 600, 0, 0, 0), "Can't open windowed screen.")
handleError(LoadFont(#font_large, "Arial", 36), "Unable to load font.")
handleError(LoadFont(#font_small, "Arial", 8), "Unable to load font.")
handleError(CreateSprite(#spr_pb, 64, 64), "Sprite creation failed.")
handleError(StartDrawing(SpriteOutput(#spr_pb)), "Can't draw on sprite.")
Box(0,0,64,64,RGB($FF,$FF,$00))
DrawingMode(#PB_2DDrawing_Outlined)
DrawingFont(FontID(#font_large))
DrawText(0,0,"PB",RGB($FF,$00,$00))
Box(0,0,64,64,RGB($00,$00,$FF))
LineXY( 0,0,64,64,RGB($00,$00,$FF))
LineXY(64,0, 0,64,RGB($00,$00,$FF))
StopDrawing()
handleError(CreateSprite(#spr_mousePointer, 8, 8, #PB_Sprite_AlphaBlending), "Sprite creation failed.")
handleError(StartDrawing(SpriteOutput(#spr_mousePointer)), "Can't draw on sprite.")
FrontColor(RGB($00,$FF,$FF))
LineXY(0,0, OutputWidth() - 1,OutputHeight() - 1)
LineXY(0,0, 0,OutputHeight() - 3)
LineXY(0,0, OutputWidth() - 3,0)
StopDrawing()
TransparentSpriteColor(#spr_mousePointer, RGB($00,$00,$00))
handleError(CreateSprite(#spr_corner, 8, 8, #PB_Sprite_AlphaBlending), "Sprite creation failed.")
handleError(StartDrawing(SpriteOutput(#spr_corner)), "Can't draw on sprite.")
Box(0, 0, OutputWidth(), OutputHeight(), RGB($00, $FF, $00))
StopDrawing()
DataSection
cornerCoordinates:
Data.i 0,0, 64,0, 64,64, 0,64
EndDataSection
Dim corner.Point(3)
Define customSpritePosX = 400, customSpritePosY = 400, i
Restore cornerCoordinates
For i = 0 To 3
handleError(CreateSprite(#spr_text_1 + i, 8, 16, #PB_Sprite_AlphaBlending), "Sprite creation failed.")
handleError(StartDrawing(SpriteOutput(#spr_text_1 + i)), "Can't draw on sprite.")
DrawingMode(#PB_2DDrawing_Outlined)
DrawingFont(FontID(#font_small))
DrawText(0, 0, Str(i + 1),RGB($FF,$FF,$FF),RGB($00,$00,$00))
StopDrawing()
TransparentSpriteColor(#spr_text_1 + i, RGB($00,$00,$00))
Read.i corner(i)\x: corner(i)\x + customSpritePosX
Read.i corner(i)\y: corner(i)\y + customSpritePosY
Next
Define direction = 2
Define zoomX = 64
Define zoomY = 64
Define angle, newWidth, newHeight, displayRow, event, i
ReleaseMouse(1)
Define mouseIsReleased = #True, dragCorner = -1
Repeat
Repeat
event = WindowEvent()
Select event
Case #PB_Event_CloseWindow
End
EndSelect
Until event = 0
FlipBuffers()
ClearScreen(RGB($40, $40, $40))
displayRow = 70
MakeSpriteNormal(#spr_pb, 32, 32) ;normal appearance
DisplaySprite(#spr_pb, 100, displayRow) ;location is needed because display location was not part of transformation
MakeSpriteRotate(#spr_pb, 32, 32, angle) ;rotate around center
DisplaySprite(#spr_pb, 200, displayRow)
MakeSpriteRotate(#spr_pb, 16, 16, angle) ;rotate around non-center point
DisplaySprite(#spr_pb, 350, displayRow)
newWidth = zoomX: newHeight = zoomX
MakeSpriteZoomHorizontal(#spr_pb, 32, 32, newWidth) ;zoom horizontally
DisplaySprite(#spr_pb, 500, displayRow)
MakeSpriteZoomVertical(#spr_pb, 32, 32, newHeight) ;zoom vertically
DisplaySprite(#spr_pb, 600, displayRow)
displayRow = 280
MakeSpriteIsoCounterClockwise(#spr_pb, 64, 64, 32, 32, angle, 64, 32) ;squished vertically
DisplaySprite(#spr_pb, 200 - zoomX * 0.5, displayRow - zoomY * 0.5)
MakeSpriteIsoCounterClockwise(#spr_pb, 64, 64, 32, 32, angle, 32, 64) ;squished horizontally
DisplaySprite(#spr_pb, 300 - zoomX * 0.5, displayRow - zoomY * 0.5)
MakeSpriteIsoClockwise(#spr_pb, 64, 64, 32, 32, angle, 2 * zoomX, 1 * zoomX) ;squished vertically and zoomed
DisplaySprite(#spr_pb, 700 - zoomX * 0.5, displayRow - zoomY * 0.5)
MakeSpriteIsoClockwise(#spr_pb, 64, 64, 32, 32, angle, 1 * zoomX, 2 * zoomX) ;squished horizontally and zoomed
DisplaySprite(#spr_pb, 500 - zoomX * 0.5, displayRow - zoomY * 0.5)
displayRow = 400
MakeSpriteIsoCounterClockwise(#spr_pb, 64, 64, 32, 32, angle, 64, 20 + zoomX / 2) ;squishiness varying vertically
DisplaySprite(#spr_pb, 100, displayRow)
MakeSpriteIsoCounterClockwise(#spr_pb, 64, 64, 32, 32, angle, 20 + zoomX / 2, 64) ;squishiness varying horizontally
DisplaySprite(#spr_pb, 200, displayRow)
ExamineMouse()
;handle screen mouse activation/deactivation
If MouseX() < 2 Or MouseX() > ScreenWidth() - 3 Or MouseY() < 2 Or MouseY() > ScreenHeight() -3
ReleaseMouse(1): mouseIsReleased = #True
EndIf
If WindowMouseX(#win_main) >= 2 And
WindowMouseX(#win_main) < WindowWidth(#win_main, #PB_Window_InnerCoordinate) - 2 And
WindowMouseY(#win_main) >= 2 And
WindowMouseY(#win_main) < WindowHeight(#win_main, #PB_Window_InnerCoordinate) - 2
ReleaseMouse(0): mouseIsReleased = #False
MouseLocate(WindowMouseX(#win_main), WindowMouseY(#win_main))
EndIf
;handle corner dragging for deformable sprite
If Not mouseIsReleased
If MouseButton(#PB_MouseButton_Left)
If dragCorner = -1
For i = 0 To 3
If SpriteCollision(#spr_corner, corner(i)\x, corner(i)\y, #spr_mousePointer, MouseX(), MouseY())
dragCorner = i
MouseDeltaX(): MouseDeltaY() ;reset these values for further reads
Break
EndIf
Next
Else
corner(dragCorner)\x + MouseDeltaX(): corner(dragCorner)\y + MouseDeltaY()
EndIf
ElseIf dragCorner <> -1
corner(dragCorner)\x + MouseDeltaX(): corner(dragCorner)\y + MouseDeltaY()
dragCorner = -1 ;signal that no corner is being dragged
EndIf
EndIf
TransformSprite(#spr_pb, corner(0)\x,corner(0)\y, corner(1)\x,corner(1)\y, corner(2)\x,corner(2)\y, corner(3)\x,corner(3)\y)
DisplaySprite(#spr_pb, 0, 0) ;drawn at location 0,0 because sprite location is part of transformation
;display corners for dragging
For i = 0 To 3
DisplayTransparentSprite(#spr_corner, corner(i)\x, corner(i)\y, 128)
DisplayTransparentSprite(#spr_text_1 + i, corner(i)\x + 8, corner(i)\y)
Next
If Not mouseIsReleased: DisplayTransparentSprite(#spr_mousePointer, MouseX(), MouseY()): EndIf
;update animation attributes
angle + 1: If angle > 360: angle = 0: EndIf
zoomX + direction
If zoomX > 100 : direction = -2 : EndIf
If zoomX < 20 : direction = 2 : EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape): Break: EndIf
Delay(1)
ForEver
Re: Les polygones
Merci.
Je vais y reflechir
Je vais y reflechir
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
salut SPH
sur le forum anglais quelques exemples de code pour les polygones
https://www.purebasic.fr/english/viewto ... 13&t=72158
https://www.purebasic.fr/english/viewto ... 12&t=17035
https://www.purebasic.fr/english/viewto ... =12&t=8893
https://www.purebasic.fr/english/viewto ... 12&t=14049
Cordialement
sur le forum anglais quelques exemples de code pour les polygones
https://www.purebasic.fr/english/viewto ... 13&t=72158
https://www.purebasic.fr/english/viewto ... 12&t=17035
https://www.purebasic.fr/english/viewto ... =12&t=8893
https://www.purebasic.fr/english/viewto ... 12&t=14049
Cordialement
Re: Les polygones
Merci mais j'avais dans l'idée des polygones remplis...
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
Re,
Voici un code produisant 2 polygones. Helas, ils sont "attachés".
Je me demandais comment les détacher et comment leur attribuer une couleur...
Voici un code produisant 2 polygones. Helas, ils sont "attachés".
Je me demandais comment les détacher et comment leur attribuer une couleur...
Code : Tout sélectionner
If OpenWindow(0,0,0,1280,800,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
Else
End
EndIf
If OpenGLGadget(1,0,0,1280,800)
glOrtho_(0,1280,800,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
;glClear_(#GL_DEPTH_BUFFER_BIT|#GL_COLOR_BUFFER_BIT)
glClear_(0)
glBegin_(#GL_POLYGON)
glVertex2f_(500,400)
glVertex2f_(300,400)
glVertex2f_(400,600)
glColor4f_(1,1,1,1)
glBegin_(#GL_POLYGON)
glVertex2f_(11,11)
glVertex2f_(22,11)
glVertex2f_(33,755)
glColor4f_(1,1,1,1)
glEnd_()
SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True)
EndIf
Delay(2000)
CloseWindow(0)
End
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
J'y connais rien dans cette technique, par contre tu devrais t'intéresser aux "Bones" pour l'animation des polygones.
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Re: Les polygones
bjr SPH
un des liens que je t'ai envoyé produit des polygones
remplis séparés grâce a sa librairie "Poly2D.pbi"
je pensais que c'était ça ce que tu cherchais
https://www.purebasic.fr/english/viewto ... =12&t=8893
Cordialement
ps: voici le code Poly2D.pbi
code test
un des liens que je t'ai envoyé produit des polygones
remplis séparés grâce a sa librairie "Poly2D.pbi"
je pensais que c'était ça ce que tu cherchais
https://www.purebasic.fr/english/viewto ... =12&t=8893
Cordialement
ps: voici le code Poly2D.pbi
Code : Tout sélectionner
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; *************************************************************************** ~
;https://www.purebasic.fr/english/viewtopic.php?f=12&t=8893&
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; Polygon2D Drawing Prozeduren (ver. 1.00)
; 2003 by Christian Stolze
;
; Mit diesen Prozeduren können relativ schnell und einfach Polygone mit
; bliebig vielen Eckpunkten gezeichnet werden. Dies ist jedoch nur für
; 2D Zeichenoperationen möglich.
;
; Erstellt am 26.12.2003
;
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; *************************************************************************** ~
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Procedure InitPolygonDrawing() ; Initialisierung für die Polygonlibrary
Structure Vertex ; Struktur für die LinkedLists in denen VertexDaten gespeichert werden
PID.l
ID.l
x.l
y.l
EndStructure
Global NewList PolygonPoints.Vertex() ; LinkedList zum Speichern der Vertex-Kooardinaten der Polygon-Eckpunkte
Global NewList PolygonDrawBuffer.Vertex() ; Zwischenspeicher für spätere Zeichenarbeiten
If ListSize(PolygonPoints())
If PolygonDrawBuffer()
result.l = PolygonPoints() + PolygonDrawBuffer()
Else
result.l = -1
EndIf
Else
result.l = -1
EndIf
ProcedureReturn result.l
EndProcedure
Procedure.l SetPolygonPoint(PolygonID.l, ID.l, x.l, y.l) ; Setzen eines Eckpunktes
ResetList(PolygonPoints())
While NextElement(PolygonPoints())
If PolygonPoints()\ID = ID.l And PolygonPoints()\PID = PolygonID.l
result.l = -1
Else
result.l = 0
EndIf
Wend
If result <> -1 ; Speichert die Eckpunktdaten in die LinkedList
AddElement(PolygonPoints())
PolygonPoints()\PID = PolygonID.l
PolygonPoints()\ID = ID.l
PolygonPoints()\x = x.l
PolygonPoints()\y = y.l
EndIf
ProcedureReturn result.l
EndProcedure
Procedure.l DeletePolygonPoint(PolygonID.l, ID.l) ; Löscht einen Eckpunkt mit der ID.l aus dem angegebenem Polygon
ResetList(PolygonPoints())
While NextElement(PolygonPoints()) ; durchsucht die LinkedList nach dem angegeben Punkt
If PolygonPoints()\ID = ID.l And PolygonPoints()\PID = PolygonID.l
DeleteElement(PolygonPoints())
result.l = 0
Else
result.l = -1
EndIf
Wend
ProcedureReturn result.l ; gibt -1 zurück, wenn der Eckpunkt nicht gelöscht werden konnte.(ansonsten 0)
EndProcedure
Procedure.l MovePolygonPoint(PolygonID.l, ID.l, NewID.l, NewX.l, NewY.l) ; ändert die Daten eines Eckpunktes (ID.l) innerhalb des Polygons (PolygonID.l)
ResetList(PolygonPoints())
While NextElement(PolygonPoints()) ; LinkedList wird nach dem Eckpunkt durchsucht
If PolygonPoints()\ID = ID.l And PolygonPoints()\PID = PolygonID.l
result.l = 0
DeleteElement(PolygonPoints()) ; wurde er gefunden, wird er gelöscht ...
Break
Else
result.l = -1
EndIf
Wend
If result.l <> -1
SelectElement(PolygonPoints(), ID.l-1)
AddElement(PolygonPoints()) ; ... und nun wieder mit neuen Daten hinzugefügt
PolygonPoints()\ID = NewID.l
PolygonPoints()\x = NewX.l
PolygonPoints()\y = NewY.l
EndIf
ProcedureReturn result.l
EndProcedure
Procedure CreatePolygon(PolygonID.l, Width.l, Height.l, BorderColor.l) ; Zeichnen eines Polygons
Protected last.l
Protected VertexX.l, VertexY.l, VertexX1.l, VertexY1.l, VertexX2.l, VertexY2.l
CreateSprite(PolygonID.l, Width.l, Height.l) ; Sprite auf dem das Polygon gezeichnet wird, wird erstellt
ClearList(PolygonDrawBuffer()) ; Zwischenspeicher wird gelöscht
ResetList(PolygonPoints()) ; Alle Eckpunkte des angegeben Polygons (PolygonID.l) werden gesucht ...
While NextElement(PolygonPoints())
If PolygonPoints()\PID = PolygonID.l
AddElement(PolygonDrawBuffer()) ; ... und in den Zwischenspeicher eingefügt
PolygonDrawBuffer()\PID = PolygonPoints()\PID
PolygonDrawBuffer()\ID = PolygonPoints()\ID
PolygonDrawBuffer()\x = PolygonPoints()\x
PolygonDrawBuffer()\y = PolygonPoints()\y
EndIf
Wend
; ResetList(PolygonDrawBuffer()) ; kann einkommentiert werden, um die Eckpunkte
; While NextElement(PolygonDrawBuffer()) ; des Polygons mit Kreisen zu markieren
; VertexX.l = PolygonDrawBuffer()\x
; VertexY.l = PolygonDrawBuffer()\y
; If StartDrawing(SpriteOutput(PolygonID.l))
; Circle(VertexX.l, VertexY.l, 5, BorderColor.l)
; StopDrawing()
; EndIf
; Wend
ResetList(PolygonDrawBuffer()) ; erster und damit letzten Eckpunkt wird ausgelesen und die Koordinaten gespeichert
NextElement(PolygonDrawBuffer()) ; (wird zum Schluß noch gebraucht)
VertexX.l = PolygonDrawBuffer()\x
VertexY.l = PolygonDrawBuffer()\y
ResetList(PolygonDrawBuffer()) ; nun werden nacheinander die Koordinaten der Punkte ausgelesen
While NextElement(PolygonDrawBuffer())
VertexX1.l = PolygonDrawBuffer()\x
VertexY1.l = PolygonDrawBuffer()\y
If NextElement(PolygonDrawBuffer())
VertexX2.l = PolygonDrawBuffer()\x
VertexY2.l = PolygonDrawBuffer()\y
PreviousElement(PolygonDrawBuffer())
ElseIf last.l = 0 ; hier werden die Koordinaten der ersten und letzten Elementes wieder in einer weitere
VertexX1.l = VertexX2.l ; Variable gespeichert um das Polygon abzuschließen
VertexY1.l = VertexY2.l ; und somit den (vor)letzten Eckpunkt wieder mit dem ersten(/letzten)
VertexX2.l = VertexX.l ; verbinden zu können
VertexY2.l = VertexY.l
last.l = 1
EndIf
If StartDrawing(SpriteOutput(PolygonID.l)) ; hier werden jeweils 2 Eckpunkte mit einer Linie verbunden
LineXY(VertexX1.l, VertexY1.l, VertexX2.l, VertexY2.l, BorderColor.l)
StopDrawing()
EndIf
Wend
EndProcedure
Procedure DeletePolygon(PolygonID.l) ; Löscht alle Eckpunkte des angegebenen Polygons aus der LinkedList
ResetList(PolygonPoints())
While NextElement(PolygonPoints())
If PolygonPoints()\PID = PolygonID.l
DeleteElement(PolygonPoints())
EndIf
Wend
EndProcedure
Procedure SetPolygonColor(PolygonID.l, x.l, y.l, OutlinColor.l, Color.l) ; Füllt das angegebene Polygon vom Punkt x,y aus mit der Farbe Color.l bis die
If StartDrawing(SpriteOutput(PolygonID.l)) ; bis die Randfarbe (OutlinColor.l) auftritt
FillArea(x.l, y.l, OutlinColor.l, Color.l)
StopDrawing()
EndIf
EndProcedure
Procedure DisplayPolygon(PolygonID.l, x.l, y.l) ; Zeigt das angegebene Polygon(/Sprite) auf dem Bildschirm an
DisplaySprite(PolygonID.l, x.l, y.l)
EndProcedure
Procedure DisplayTransparentPolygon(PolygonID.l, x.l, y.l, Red.l, Green.l, Blue.l) ; Zeigt das angegebene Polygon(/Sprite) auf dem Bildschirm an
TransparentSpriteColor(PolygonID.l, RGB(Red.l, Green.l, Blue.l)) ; wobei die angegebene Farbe Transparent dargestellt wird
DisplayTransparentSprite(PolygonID.l, x.l, y.l)
EndProcedure
Procedure.l GetPolygonPointX(PolygonID.l, ID.l) ; Ausgabe der X-Koordinate eines Eckpunktes
ResetList(PolygonPoints())
While NextElement(PolygonPoints()) ; LinkedList wird nach dem Eckpunkt durchsucht
If PolygonPoints()\ID = ID.l And PolygonPoints()\PID = PolygonID.l
result.l = PolygonPoints()\x
Break
Else
result.l = -1
EndIf
Wend
ProcedureReturn result.l
EndProcedure
Procedure.l GetPolygonPointY(PolygonID.l, ID.l) ; Ausgabe der Y-Koordinate eines Eckpunktes
ResetList(PolygonPoints())
While NextElement(PolygonPoints()) ; LinkedList wird nach dem Eckpunkt durchsucht
If PolygonPoints()\ID = ID.l And PolygonPoints()\PID = PolygonID.l
result.l = PolygonPoints()\y
Break
Else
result.l = -1
EndIf
Wend
ProcedureReturn result.l
EndProcedure
Code : Tout sélectionner
XIncludeFile "Poly2D.pbi"
#SCREEN_Width = 500
#SCREEN_Height = 500
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("ERROR","Cant init DirectX",0)
End
EndIf
MainWnd.l = OpenWindow(0, 0, 0, #SCREEN_Width, #SCREEN_Height, "Polygon Beispiel", #PB_Window_ScreenCentered)
If OpenWindowedScreen(MainWnd.l, 0, 0, #SCREEN_Width, #SCREEN_Height, 1, 0, 0)
If InitPolygonDrawing()
; -- Cursor
SetPolygonPoint(0, 0, 5, 5)
SetPolygonPoint(0, 1, 30, 20)
SetPolygonPoint(0, 2, 17, 17)
SetPolygonPoint(0, 3, 20, 30)
CreatePolygon(0, 50, 50, RGB(0,0,255))
SetPolygonColor(0, 10, 10, RGB(0,0,255), RGB(0,0,255))
; -- Fünfeck
SetPolygonPoint(1, 0, 0, 0)
SetPolygonPoint(1, 1, 150, 0)
SetPolygonPoint(1, 2, 175, 75)
SetPolygonPoint(1, 3, 150, 200)
SetPolygonPoint(1, 4, 50, 125)
CreatePolygon(1, 176, 201, RGB(255,255,255))
SetPolygonColor(1, 10, 10, RGB(255,255,255), RGB(255,0,0))
; -- Dreieck
SetPolygonPoint(2, 0, 0, 25)
SetPolygonPoint(2, 1, 150, 0)
SetPolygonPoint(2, 2, 175, 75)
CreatePolygon(2, 176, 76, RGB(255,0,255))
; -- Achteck
SetPolygonPoint(3, 0, 50, 50)
SetPolygonPoint(3, 1, 100, 25)
SetPolygonPoint(3, 2, 150, 50)
SetPolygonPoint(3, 3, 175, 100)
SetPolygonPoint(3, 4, 150, 150)
SetPolygonPoint(3, 5, 100, 175)
SetPolygonPoint(3, 6, 50, 150)
SetPolygonPoint(3, 7, 25, 100)
CreatePolygon(3, 176, 176, RGB(255,255,0))
SetPolygonColor(3, 51, 51, RGB(255,255,0), RGB(255,255,0))
EndIf
EndIf
a.l = -1
b.l = -1
Repeat
While WindowEvent() : Wend
ExamineKeyboard()
ExamineMouse()
DisplayPolygon(1, 250, 200) ; Fünfeck
DisplayTransparentPolygon(2, 20, 20, 0, 0, 0) ; Dreieck -> Schwarz als transparente Farbe
DisplayTransparentPolygon(3, 20, 250, 0, 0, 0) ; Achteck -> Schwarz als transparente Farbe
DisplayTransparentPolygon(0, MouseX(), MouseY(), 0, 0, 0) ; Mousecursor -> Schwarz als transparente Farbe
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
Until KeyboardPushed(#PB_Key_Escape)
End
Dernière modification par kernadec le sam. 21/nov./2020 10:49, modifié 1 fois.
Re: Les polygones
Je cherche la methode d'affichage la plus rapide.kernadec a écrit :bjr SPH
un des liens que je t'ai envoyé produit des polygones
remplis séparés grâce a sa librairie "Poly2D.pbi"
je pensais que c'était ça ce que tu cherchais
https://www.purebasic.fr/english/viewto ... =12&t=8893
Cordialement
Et quand je dis "polygones pleins", c'est plein d'une couleur (pas d'une image; quoi que c'est utile de l'avoir sous la main)
Donc, je creuse les polygones open gl :
glVertex2f_(500,400)
C'est ce qu'il me faut mais je ne sais pas faire 2 polygones et je ne sais pas choisir sa couleur...
Alors, si vous avez ca...
MERCI KERNADEK, je regarde ca...
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
Pour ceux que ca interesse, voici comment faire :
Code : Tout sélectionner
If OpenWindow(0,0,0,1280,800,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
If OpenGLGadget(1,0,0,1280,800)
glOrtho_(0,1280,800,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(0)
glBegin_(#GL_POLYGON)
glColor4f_(1,1,1,1)
glVertex2f_(500,400)
glVertex2f_(300,400)
glVertex2f_(400,600)
glEnd_()
glBegin_(#GL_POLYGON)
glColor4f_(0.5,0.5,0.5,0.5)
glVertex2f_(11,11)
glVertex2f_(22,11)
glVertex2f_(33,755)
glEnd_()
SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True)
EndIf
Delay(5000)
CloseWindow(0)
EndIf
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
j'etais justement en trains de te faire un exemple simple
Code : Tout sélectionner
If OpenWindow(0,0,0,1280,800,#Null$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
Else
End
EndIf
If OpenGLGadget(1,0,0,1280,800)
glOrtho_(0,1280,800,0,-1,1)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
For i=1 to 3600
glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT) ; efface l'ecran openGL
; on dessine le polygone
glBegin_(#GL_POLYGON)
glColor3f_(0,0,1) ; on choisi la couleur du crayon AVANT de dessiner
glVertex2f_(500,400)
glVertex2f_(300,400)
glVertex2f_(400,600)
glEnd_()
; ensuite on le bouge
glTranslatef_(10, -8, 0) ; on le recentre un peut dans l'ecran
RollAxisZ.f=1
glRotatef_ (RollAxisZ, 0, 0, 1) ;tourne autour de l'axe des Z
SetGadgetAttribute(1,#PB_OpenGL_FlipBuffers,#True) ; Affiche
Next i
EndIf
CloseWindow(0)
End
Site: http://michel.dobro.free.fr/
Devise :"dis moi ce dont tu as besoin, je t'expliquerai comment t'en passer"
Re: Les polygones
Ton exemple m'aura appris 2 nouvelles instructions
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Re: Les polygones
bjr à tous
pour débuter la programmation avec OpenGL voici un lien.
http://sdz.tdct.org/sdz/creez-des-progr ... pengl.html
Cordialement
pour débuter la programmation avec OpenGL voici un lien.
http://sdz.tdct.org/sdz/creez-des-progr ... pengl.html
Cordialement
Dernière modification par kernadec le dim. 22/nov./2020 15:33, modifié 2 fois.
Re: Les polygones
@kernadec
Il a l'air sympa ce lien. Merci je vais étudier ça.
Dommage, je ne vois pas les images d'exemple
@++
Il a l'air sympa ce lien. Merci je vais étudier ça.
Dommage, je ne vois pas les images d'exemple
@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Re: Les polygones
bjr venom
merci venon pour le retour j'ai changé le lien de mon post précédent qui permet maintenant d avoir les liens
dans les pages qui mènent vers le SiteDuZero ".org" remis ce-dessous
http://sdz.tdct.org/sdz/creez-des-progr ... pengl.html
normalement on peut télécharger les images
ou aller sur le Site du Zero
le site du Zero semble avoir disparu enfin je sais plus... mais voilà une adresse chez ".org"
voila le lien
http://sdz.tdct.org/
ou il y a d'autre liens comme celui là
https://opengl.developpez.com/tutoriels ... -tutorial/
Cordialement
merci venon pour le retour j'ai changé le lien de mon post précédent qui permet maintenant d avoir les liens
dans les pages qui mènent vers le SiteDuZero ".org" remis ce-dessous
http://sdz.tdct.org/sdz/creez-des-progr ... pengl.html
normalement on peut télécharger les images
ou aller sur le Site du Zero
le site du Zero semble avoir disparu enfin je sais plus... mais voilà une adresse chez ".org"
voila le lien
http://sdz.tdct.org/
ou il y a d'autre liens comme celui là
https://opengl.developpez.com/tutoriels ... -tutorial/
Cordialement