Post by funkheld on Jun 20, 2010 18:15:12 GMT 1
sprite from form f2 and transparent.
you mus rot.bmp and blau.bmp with 64x64 pixel produce.
the Sub LOAD_TEXTURE(Nr As Integer, A As Variant, Optional COL As Variant) is www.peterheinzig.de/ .
peter is an very good gfa32-man.
the Declare Sub glGenTextures Alias "glGenTextures" (ByVal n As Integer, ByVal pTextures As Integer) from Shiny3D.g32 is changed.
this pTextures is now Byval
keys : q-e-w-s-a-d-y-c
you mus rot.bmp and blau.bmp with 64x64 pixel produce.
the Sub LOAD_TEXTURE(Nr As Integer, A As Variant, Optional COL As Variant) is www.peterheinzig.de/ .
peter is an very good gfa32-man.
the Declare Sub glGenTextures Alias "glGenTextures" (ByVal n As Integer, ByVal pTextures As Integer) from Shiny3D.g32 is changed.
this pTextures is now Byval
keys : q-e-w-s-a-d-y-c
$Library "Shiny3D"
Type BitmapInfoHeader
- Int biSize, biWidth, biHeight
- Short biPlanes, biBitCount
- Int biCompression, biSizeImage, biXPelsPerMeter
- Int biYPelsPerMeter, biClrUsed, biClrImportant
EndType
Declare Function TransparentBlt Lib "msimg32.dll" _
(ByVal hdc%, ByVal x%, ByVal y%, ByVal nwidth%, ByVal nheight%, _
ByVal hsrcdc%, ByVal xsrc%, ByVal ysrc%, ByVal nsrcwidth%, ByVal nsrcheight%, _
ByVal crtransparent%) As Bool
Global BIH As BitmapInfoHeader
Global Int hrc, wq, hq, fw, fh
Global Single pi_180, wi, wi1, wi2, wid, x1, y1, dx, dy, sw
Global Int autobild_dreh_dc, autobild_dreh_ad
pi_180 = PI / 180
sw = 2
wid = 2
wi = 0
wq = 100
hq = wq
fw = 500
fh = fw
dx = 100
dy = 100
Form f0 = "test" , , , 800, 600 : .AutoRedraw = 1 : BackColor = RGB(200, 200, 200)
Ocx Form vordergrbild = , 180, 20, fw, fh : .AutoRedraw = 1 : .Visible = 1
Ocx Form hintergrbild = , 130, 20, fw, fh : .AutoRedraw = 1 : .Visible = 0
Ocx Form sicherungbild = , 130, 20, fw, fh : .AutoRedraw = 1 : .Visible = 0 : .BackColor = RGB(255, 255, 0)
Ocx Command CO(1) = "F1.Hide", 5, 5, 70, 25
Ocx Command CO(2) = "F1.Show", 5, 25, 70, 25
Ocx Form oglbild = , 10, 150, hq, wq : .AutoRedraw = 1 : .Appearance = 0 : .Visible = 1
Set Me = oglbild : DoEvents
BitBlt sicherungbild.hDC2, 0, 0, fw, fh, vordergrbild.hDC, 0, 0
init_dc
hrc = CreateRC(oglbild.hDC)
TEXTUR_ZEICHNEN
LOAD_TEXTURE(1, F2, 0)
LOAD_TEXTURE(2, "rot.bmp")
LOAD_TEXTURE(3, "blau.bmp")
F2.Close
RenderScene
sprite_aktion
RenderScene
sprite_aktion
Do
Sleep
Loop Until Me Is Nothing
Sub CO_Click(index%)
Select index
Case 1 : oglbild.Hide : RenderScene : DoEvents : SwapBuffers(oglbild.hDC)
Case 2 : oglbild.Show : RenderScene : DoEvents : SwapBuffers(oglbild.hDC)
EndSelect
Sub TEXTUR_ZEICHNEN
Ocx Form F2 : .Visible = 0 : .Appearance = 0 : .Adjust 256, 256 : .AutoRedraw = 1
Set Me = F2 : BackColor = $ff00ff
Color $ff00ff : Box 0, 0, _X , _Y : Color $00ff00 : PCircle _X / 2, _Y / 2, 100
Set Me = oglbild
Sub sprite_aktion
glReadPixels(0, 0, wq , hq , GL_BGRA, GL_UNSIGNED_BYTE, autobild_dreh_ad)
BitBlt sicherungbild.hDC2, dx, dy, wq, hq, hintergrbild.hDC2, dx, dy
TransparentBlt(hintergrbild.hDC2, dx, dy, wq , hq , autobild_dreh_dc, 0, 0, wq , hq , $ff00ff)
BitBlt hintergrbild.hDC2, dx, dy, wq, hq, vordergrbild.hDC, dx, dy
Sub init_dc
BIH.biSize = SizeOf(BIH) : BIH.biPlanes = 1 : BIH.biBitCount = 32
BIH.biWidth = wq : BIH.biHeight = hq
autobild_dreh_dc = CreateCompatibleDC( f0.hDC)
Local Hbm% = CreateDIBSection(Null, *BIH, DIB_RGB_COLORS, *autobild_dreh_ad, Null, 0)
~SelectObject(autobild_dreh_dc, Hbm) : FreeBmp Hbm
Sub Screen_KeyPreview(hwnd%, umsg%, wqaram%, lparam%, cancel?)
Select wqaram%
Case "q"
wi -= wid
RenderScene
sprite_aktion
Case "e"
wi += wid
RenderScene
sprite_aktion
Case "a"
wi1 -= wid
RenderScene
sprite_aktion
Case "d"
wi1 += wid
RenderScene
sprite_aktion
Case "y"
wi2 -= wid
RenderScene
sprite_aktion
Case "c"
wi2 += wid
RenderScene
sprite_aktion
Case "s"
x1 = Sin(-wi * pi_180) * sw
y1 = Cos(-wi * pi_180) * sw
dx += x1
dy += y1
RenderScene
sprite_aktion
Case "w"
x1 = Sin(-wi * pi_180) * sw
y1 = Cos(-wi * pi_180) * sw
dx -= x1
dy -= y1
RenderScene
sprite_aktion
EndSelect
Sub oglbild_Close(Cancel?)
If hrc Then
wglMakeCurrent(0, 0)
wglDeleteContext(hrc)
End If
End Sub
Sub RenderScene
glLoadIdentity()
glClearColor(1, 0, 1, 0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glTranslatef(0, 0.0, 0)
glRotatef(-wi , 0, 0, 1)
glPushMatrix()
glScalef(.4, 0.5, 0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, Textur(1))
glBegin(GL_QUADS)
glTexCoord2f(0, 0) : glVertex3f(-1, -1, 0)
glTexCoord2f(0, 1) : glVertex3f(-1, 1, 0)
glTexCoord2f(1, 1) : glVertex3f(1, 1, 0)
glTexCoord2f(1, 0) : glVertex3f(1, -1, 0)
glEnd()
glPopMatrix()
glTranslatef(0, 0.0, 0)
glRotatef(-wi1 + 180, 0, 0, 1)
glPushMatrix()
glTranslatef(0, 0.25, 0)
glScalef(0.07, 0.25, 0)
glBindTexture(GL_TEXTURE_2D, Textur(2))
glBegin(GL_QUADS)
glTexCoord2f(0, 0) : glVertex3f(-1, -1, 0)
glTexCoord2f(0, 1) : glVertex3f(-1, 1, 0)
glTexCoord2f(1, 1) : glVertex3f(1, 1, 0)
glTexCoord2f(1, 0) : glVertex3f(1, -1, 0)
glEnd()
glPopMatrix()
glTranslatef(0, 0.5, 0)
glRotatef(-wi2 + 180, 0, 0, 1)
glPushMatrix()
glTranslatef(0, 0.15, 0)
glScalef(0.05, 0.2, 0)
glBindTexture(GL_TEXTURE_2D, Textur(3))
glBegin(GL_QUADS)
glTexCoord2f(0, 0) : glVertex3f(-1, -1, 0)
glTexCoord2f(0, 1) : glVertex3f(-1, 1, 0)
glTexCoord2f(1, 1) : glVertex3f(1, 1, 0)
glTexCoord2f(1, 0) : glVertex3f(1, -1, 0)
glEnd()
glPopMatrix()
SwapBuffers(oglbild.hDC)
End Sub
Sub LOAD_TEXTURE(Nr As Integer, A As Variant, Optional COL As Variant) 'entfällt bei 0 Texturen
'Nr = Nr. der Textur. Kleinster Wert = 1
'A = File$ (auch ":xxx" möglich) oder Form = gezeichnetes Bild (AutoRedraw muß 1 sein!)
'Col = RGB-Wert für Transparentfarbe
'setzt Global Textur%(1 ..). Automatisches ReDim
If Nr < 1 Then Message"Textur-Nr muß > 0 sein!", "FEHLER" : End
Static tex% : If !tex Then Global Textur%(1 .. Nr) : tex++
Local Int DC, Adr, hBM, n, w, h, Nr1 = Nr * 2
If IsExe && Nr > Dim?(Textur()) Then ReDim Textur(1 .. Nr) 'OK in Exe, tw.nicht im Editor
If !IsExe && Nr1 > Dim?(Textur()) Then ReDim Textur(1 .. Nr1) 'OK auch im Editor
If IsObject(A) : w = A.ScaleWidth : h = A.ScaleHeight : n++
Else : Local Picture pic : Set pic = LoadPicture(A)
w = pic.Width * Screen.TwipsPerHimet / Screen.TwipsPerPixelX
h = pic.Height * Screen.TwipsPerHimet / Screen.TwipsPerPixelY
EndIf
Local BIH As BitmapInfoHeader
BIH.biSize = SizeOf(BIH) : BIH.biPlanes = 1 : BIH.biBitCount = 32
BIH.biWidth = w : BIH.biHeight = h
hBM = CreateDIBSection(Null, *BIH, DIB_RGB_COLORS, *Adr, Null, 0)
DC = CreateCompatibleDC(_DC()) : ~SelectObject(DC, hBM) : FreeBmp hBM
If n : BitBlt A.hdc2, 0, 0, w, h, DC
Else : pic.Render DC, 0, 0, w, h, 0, pic.Height - 1, pic.Width, -pic.Height, 0 : Set pic = Nothing
EndIf
If IsMissing(COL) 'Rot und Blau in DC tauschen:
For n = Adr To Adr + w * h * 4 - 3 Step 4 : LPoke n, Bswap3(LPeek(n)) Or $FF000000 : Next
Else 'dto. mit Transparent: (evtl. Fehler bei Gif, Jpg !!)
Local Int c, cT = COL : cT = Bswap3(cT)
For n = Adr To Adr + w * h * 4 - 3 Step 4
c = LPeek(n) : LPoke n, Bswap3(c) : If c <> cT Then Poke n + 3, $FF
Next
EndIf
glEnable(GL_TEXTURE_2D)
glGenTextures(Nr, V:Textur(Nr))
glBindTexture(GL_TEXTURE_2D, Textur(Nr))
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, Adr)
glDisable(GL_TEXTURE_2D)
~DeleteDC(DC)