29-12-2007, 11:30 PM
Im a french programmer and i have added PNG to mirage source.
First add to reference PaintX 1.0 Type library. (go to : http://www.paintlib.de )
Now create a module modPNG and add:
Now change all .bmp to .png
Now go to modDirectX en change Sub InitSurfaces()
With :
And add to modDirectX :
Now change :
.Picture = LoadPicture(App.Path + "\gfx\tiles.bmp")
With:
Now change :
frmItemEditor.picItems.Picture = LoadPicture(App.Path & "\gfx\items.bmp")
with :
Now change :
frmNpcEditor.picSprites.Picture = LoadPicture(App.Path & "\gfx\sprites.bmp")
with :
I use it on my game, good luck and good png :mrgreen:
El_Dindonnier.
First add to reference PaintX 1.0 Type library. (go to : http://www.paintlib.de )
Now create a module modPNG and add:
Code:
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Function LoadPNG(FileName As String) As StdPicture
Dim PictureDecoder As New PAINTXLib.PictureDecoder
Set LoadPNG = PictureDecoder.LoadPicture(FileName)
End Function
Public Function LoadImage(FileName As String, DDraw As DirectDraw7, SDesc As DDSURFACEDESC2) As DirectDrawSurface7
Dim TPict As StdPicture
Set TPict = LoadPNG(FileName)
SDesc.lHeight = CLng((TPict.Height * 0.001) * 567 / Screen.TwipsPerPixelY)
SDesc.lWidth = CLng((TPict.Width * 0.001) * 567 / Screen.TwipsPerPixelX)
Set LoadImage = DDraw.CreateSurface(SDesc)
Dim SDC As Long, TDC As Long
SDC = LoadImage.GetDC
TDC = CreateCompatibleDC(0)
SelectObject TDC, TPict.Handle
BitBlt SDC, 0, 0, SDesc.lWidth, SDesc.lHeight, TDC, 0, 0, vbSrcCopy
LoadImage.ReleaseDC SDC
DeleteDC TDC
Set TPict = Nothing
End Function
Public Function LoadImageStretch(FileName As String, Height As Long, Width As Long, DDraw As DirectDraw7, SDesc As DDSURFACEDESC2) As DirectDrawSurface7
Dim TPict As New StdPicture
Set TPict = LoadPNG(FileName)
SDesc.lHeight = Height
SDesc.lWidth = Width
Set LoadImageStretch = DDraw.CreateSurface(SDesc)
Dim SDC As Long, TDC As Long
SDC = LoadImageStretch.GetDC
TDC = CreateCompatibleDC(0)
SelectObject TDC, TPict.Handle
StretchBlt SDC, 0, 0, Width, Height, TDC, 0, 0, CLng((TPict.Width * 0.001) * 567 / Screen.TwipsPerPixelX), CLng((TPict.Height * 0.001) * 567 / Screen.TwipsPerPixelY), vbSrcCopy
LoadImageStretch.ReleaseDC SDC
DeleteDC TDC
Set TPict = Nothing
End Function
Now change all .bmp to .png
Now go to modDirectX en change Sub InitSurfaces()
With :
Code:
Sub InitSurfaces()
Dim KEY As DDCOLORKEY
' Set the key for masks
KEY.low = 0
KEY.high = 0
' Initialize back buffer
DDSD_BackBuffer.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD_BackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
DDSD_BackBuffer.lWidth = (MAX_MAPX + 1) * PIC_X
DDSD_BackBuffer.lHeight = (MAX_MAPY + 1) * PIC_Y
Set DD_BackBuffer = DD.CreateSurface(DDSD_BackBuffer)
' Init sprite ddsd type and load the bitmap
DDSD_Sprite.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD_Sprite.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
Set DD_SpriteSurf = LoadImage(App.Path & "\gfx\sprites.png", DD, DDSD_Sprite)
SetMaskColorFromPixel DD_SpriteSurf, 0, 0
' Init sprite ddsd type and load the bitmap
DDSD_Tile.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD_Tile.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
Set DD_TileSurf = LoadImage(App.Path & "\gfx\tiles.png", DD, DDSD_Tile)
SetMaskColorFromPixel DD_TileSurf, 0, 0
' Init sprite ddsd type and load the bitmap
DDSD_Item.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
DDSD_Item.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_SYSTEMMEMORY
Set DD_ItemSurf = LoadImage(App.Path & "\gfx\items.png", DD, DDSD_Item)
SetMaskColorFromPixel DD_ItemSurf, 0, 0
End Sub
And add to modDirectX :
Code:
Public Sub SetMaskColorFromPixel(ByRef TheSurface As DirectDrawSurface7, ByVal X As Long, ByVal Y As Long)
Dim TmpR As RECT
Dim TmpDDSD As DDSURFACEDESC2
Dim TmpColorKey As DDCOLORKEY
With TmpR
.Left = X
.top = Y
.Right = X
.Bottom = Y
End With
TheSurface.Lock TmpR, TmpDDSD, DDLOCK_WAIT Or DDLOCK_READONLY, 0
With TmpColorKey
.low = TheSurface.GetLockedPixel(X, Y)
.high = .low
End With
TheSurface.SetColorKey DDCKEY_SRCBLT, TmpColorKey
TheSurface.Unlock TmpR
End Sub
Now change :
.Picture = LoadPicture(App.Path + "\gfx\tiles.bmp")
With:
Code:
.Picture = LoadPNG(App.Path + "\gfx\tiles.bmp")
Now change :
frmItemEditor.picItems.Picture = LoadPicture(App.Path & "\gfx\items.bmp")
with :
Code:
frmItemEditor.picItems.Picture = LoadPNG(App.Path & "\gfx\items.bmp")
Now change :
frmNpcEditor.picSprites.Picture = LoadPicture(App.Path & "\gfx\sprites.bmp")
with :
Code:
frmNpcEditor.picSprites.Picture = LoadPNG(App.Path & "\gfx\sprites.bmp")
I use it on my game, good luck and good png :mrgreen:
El_Dindonnier.