[DX7] DrawPolyImage

Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Neue Antwort erstellen

Lastmayday

Betreff: [DX7] DrawPolyImage

BeitragSa, Jun 12, 2010 6:04
Antworten mit Zitat
Benutzer-Profile anzeigen
(Vorerstmal nur die DX7 version)
womöglich lange vermisst und nun endlich da: die Möglichkeit Bmax2d-images zu verzerren und einzufärben mit alpha-channel!

Ich habe mehrere Stunden damit verbracht diese Funktion zu basteln ( <3 Google ) nun möchte ich diese euch nicht vorenthalten. Vorher hatte ich den Standard d3d7max2d.mod verändert was mir Bmax beim neu bauen von den Modulen übel nahm. Aber mit der totalen Kontrolle über Timages kann wesentlich mehr machen als ich zuerst dachte und eigentlich machen wollte. Mit dieser Funktion lassen sich leichter iso-maps bauen Wink . So und los geht’s:

Einfach eine include mit:

BlitzMax: [AUSKLAPPEN]
 

Global boostMax2D_Driver:TD3D7Max2DDriver, boostMax2D_active:Int

Rem
bbdoc: init_boostMax2D(D3D7Max2DDriver())
End Rem

Function init_boostMax2D(device:TD3D7Max2DDriver)
boostMax2D_Driver = device
boostMax2D_active = True
End Function


Rem
bbdoc: Draw an image with polycords to the back buffer
about:
xy:Float[] <= an array with 8 xy cords for drwing on the back buffer: = [x1, y1, x2, y2, x3, y3, x4, x4]
own_xyzuv:Float[] <= an array with 8 xy cords for the image cut(0.5 means 50% of the image): = [x1, y1, x2, y2, x3, y3, x4, x4]
tx:Float and ty:Float <= the orgin data
color:Int[] <= an array with 4 color data for every image corner
End Rem

Function DrawPolyImage(image:TImage, xy:Float[], tx:Float = 0, ty:Float = 0, frame:Int = 0, color:Int[] = Null, own_xyzuv:Float[] = Null)
Function Pow2Size:Int(n:Int)
Local t:Int = 1
While t < n
t:*2
Wend
Return t
End Function

If Not boostMax2D_Driver.IsValid() Return
If Not boostMax2D_active Then RuntimeError("boostMax2D: run first 'init_boostMax2D(D3D7Max2DDriver())'")

Local iframe:TImageFrame = image.Frame(frame)
Local d3d7frame:TD3D7ImageFrame = TD3D7ImageFrame(image.frames[frame])

Local swidth:Float = Pow2Size(image.width)
Local sheight:Float = Pow2Size(image.height)

Local uv:Float Ptr
Local c:Int Ptr
Local xyzuv:Float[] = New Float[24]

If own_xyzuv Then
xyzuv[4] = own_xyzuv[0]
xyzuv[5] = own_xyzuv[1]
xyzuv[10] = own_xyzuv[2]
xyzuv[11] = own_xyzuv[3]
xyzuv[16] = own_xyzuv[4]
xyzuv[17] = own_xyzuv[5]
xyzuv[22] = own_xyzuv[6]
xyzuv[23] = own_xyzuv[7]
Else
xyzuv[4] = 0.0
xyzuv[5] = 0.0
xyzuv[10] = Float(image.width) / swidth
xyzuv[11] = 0.0
xyzuv[16] = Float(image.width) / swidth
xyzuv[17] = Float(image.height) / sheight
xyzuv[22] = 0.0
xyzuv[23] = Float(image.height) / sheight
End If


uv = xyzuv
c = Int Ptr(uv)

uv[0] = xy[0] * boostMax2D_Driver.ix + xy[1] * boostMax2D_Driver.iy + tx
uv[1] = xy[0] * boostMax2D_Driver.jx + xy[1] * boostMax2D_Driver.jy + ty
If color Then c[3] = color[0] Else c[3] = boostMax2D_Driver.drawcolor

uv[6] = xy[2] * boostMax2D_Driver.ix + xy[3] * boostMax2D_Driver.iy + tx
uv[7] = xy[2] * boostMax2D_Driver.jx + xy[3] * boostMax2D_Driver.jy + ty
If color Then c[9] = color[1] Else c[9] = boostMax2D_Driver.drawcolor

uv[12] = xy[4] * boostMax2D_Driver.ix + xy[5] * boostMax2D_Driver.iy + tx
uv[13] = xy[4] * boostMax2D_Driver.jx + xy[5] * boostMax2D_Driver.jy + ty
If color Then c[15] = color[2] Else c[15] = boostMax2D_Driver.drawcolor

uv[18] = xy[6] * boostMax2D_Driver.ix + xy[7] * boostMax2D_Driver.iy + tx
uv[19] = xy[6] * boostMax2D_Driver.jx + xy[7] * boostMax2D_Driver.jy + ty
If color Then c[21] = color[3] Else c[21] = boostMax2D_Driver.drawcolor

boostMax2D_Driver.SetActiveFrame(d3d7frame)
boostMax2D_Driver.device.DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, uv, 4, 0)
End Function



und einmal „init_boostMax2D(D3D7Max2DDriver())“ aufrufen (nach dem man das Graphics Fenster erstellt hat) und die Funktion ist einsatzbereit.

Und so benutzt man es:

BlitzMax: [AUSKLAPPEN]
 
Local tri:Float[]
Local colordata:Int[4]

tri = [p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y] 'eck punkte setzten (im Uhrzeigersinn)

Local cdat1:Byte Ptr = Varptr(colordata[0]) 'eck Farben setzten (optional)
cdat1[0] = blau
cdat1[1] = gruen
cdat1[2] = rot
cdat1[3] = alpha
Local cdat2:Byte Ptr = Varptr(colordata[1])
cdat2[0] = blau
cdat2[1] = gruen
cdat2[2] = rot
cdat2[3] = alpha
Local cdat3:Byte Ptr = Varptr(colordata[2])
cdat3[0] = blau
cdat3[1] = gruen
cdat3[2] = rot
cdat3[3] = alpha
Local cdat4:Byte Ptr = Varptr(colordata[3])
cdat4[0] = blau
cdat4[1] = gruen
cdat4[2] = rot
cdat4[3] = alpha


Local trionimage:Float[8] 'nur einen bestimten teil des images zeichen (0.5 sind 50% des bildes)

trionimage[0] = 0.0 'x oben liks
trionimage[1] = 0.0 'y
trionimage[2] = 1.0 'x oben rechts
trionimage[3] = 0.0 'y
trionimage[4] = 1.0 'x unten rechts
trionimage[5] = 1.0 'y
trionimage[6] = 0.0 'x unten liks
trionimage[7] = 1.0 'y


DrawPolyImage(TImage, tri,,, , colordata, trionimage)
'oder

DrawPolyImage(TImage, tri,,, , colordata)
'oder

SetColor(255,255,255)
DrawPolyImage(TImage, tri)



was man damit nun tolles anstellen kann?

user posted image


(edit1) own_xyzuv:Float[] < Bildausschnitt hinzgefügt

juse4pro

BeitragSa, Jun 12, 2010 19:58
Antworten mit Zitat
Benutzer-Profile anzeigen
Echt praktisch! Erinnert mich an RollerCoaster Razz
Portfolio |LinkedIn |XING

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Codearchiv & Module

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group