Re: MP3D Engine Alpha 31
Posted: Fri May 31, 2013 7:00 pm
This is not an emergency. Rest, then you will work on the engine with new forces. )
Happy holidays!
Happy holidays!
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
If Not MP_Graphics3D(800,600,0,1) : End : EndIf
Player = MP_LoadSprite("player.png")
BgTile = MP_LoadSprite("grass.png")
Repeat
MP_DrawTiledSprite(BgTile,0,0)
MP_Box(0,0,415,315,$ffff00,1)
MP_DrawSprite(Player,400,300)
MP_SpriteSetZ(BgTile,1)
MP_SpriteSetZ(Player,0)
MP_RenderWorld()
MP_Flip()
Until MP_KeyDown(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
Because SpriteSetZ shouldn't be used like this,it only changes the Z buffer depth,I have used HGE functions (for Delphi) to change Z buffer like this and get the same ugly(alpha value) result,so there is no bug with your code neither the MP3D engine,if changing the Z-order is your goal,you can check this code by MPZdeseven wrote:Hello. I need some help
grass.png:Code: Select all
If Not MP_Graphics3D(800,600,0,1) : End : EndIf Player = MP_LoadSprite("player.png") BgTile = MP_LoadSprite("grass.png") Repeat MP_DrawTiledSprite(BgTile,0,0) MP_Box(0,0,415,315,$ffff00,1) MP_DrawSprite(Player,400,300) MP_SpriteSetZ(BgTile,1) MP_SpriteSetZ(Player,0) MP_RenderWorld() MP_Flip() Until MP_KeyDown(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
player.png:
1. Why the box is on top of all sprites?
2. What's wrong with alpha in player sprite?
Can someone explain how it works and what am i doing wrong?
Thanks in advance.
Code: Select all
;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine Beispielprogramme
;// Dateiname: MP_SpriteOrder.pb
;// Erstellt am: 16.11.2011
;// Update am :
;// Author: Michael Paulwitz
;//
;// Info:
;// Order of Sprites
;// Darstellungsreihenfolge der Sprites
;//
;//
;////////////////////////////////////////////////////////////////
Global wX = 640
Global wY = 480
;- *** Create Window
MP_Graphics3DWindow(0, 0, wX, wY, "Sprite oder: Change order of Sprite with Space", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
If CreateImage(0, 164, 164)
MP_CreateImageColored(0, 0, #Yellow,#Yellow,#Red,#Red)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(40,0,"Hallo ich bin",$10101); ,$10101) means rgb(1,1,1) = black, but not transaprent
DrawText(60,20,"Sprite 1",$10101)
StopDrawing()
EndIf
If CreateImage(1, 164, 164)
MP_CreateImageColored(1, 0, #Red,#Red,#Blue,#Blue)
StartDrawing(ImageOutput(1))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(40,0,"Hallo ich bin",$10101)
DrawText(60,20,"Sprite 2",$10101)
StopDrawing()
EndIf
If CreateImage(2, 164, 164)
MP_CreateImageColored(2, 0, #Blue,#Blue,#Green,#Green)
StartDrawing(ImageOutput(2))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(40,0,"Hallo ich bin",$10101)
DrawText(60,20,"Sprite 3",$10101)
StopDrawing()
EndIf
If CreateImage(3, 164, 164)
MP_CreateImageColored(3, 0, #Green,#Green,#Yellow,#Yellow)
StartDrawing(ImageOutput(3))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(40,0,"Hallo ich bin",$10101)
DrawText(60,20,"Sprite 4",$10101)
StopDrawing()
EndIf
Texture1 = MP_ImageToTexture(0)
Texture2 = MP_ImageToTexture(1)
Texture3 = MP_ImageToTexture(2)
Texture4 = MP_ImageToTexture(3)
FreeImage(0)
FreeImage(1)
FreeImage(2)
FreeImage(3)
; Display result of initialization order
Sprite1 = MP_SpriteFromTexture(Texture1)
Sprite2 = MP_SpriteFromTexture(Texture2)
Sprite3 = MP_SpriteFromTexture(Texture3)
Sprite4 = MP_SpriteFromTexture(Texture4)
MessageRequester("Info", "You have "+Str(MP_ListGetSize(9))+" Sprites")
Repeat
Event = WindowEvent()
MP_DrawSprite(Sprite1, 25, 25)
MP_DrawSprite(Sprite2, 65, 65)
MP_DrawSprite(Sprite3, 105, 105)
MP_DrawSprite(Sprite4, 145, 145)
MP_DrawSprite(Sprite1, 225, 225)
MP_DrawSprite(Sprite2, 265, 265)
MP_DrawSprite(Sprite3, 305, 305)
MP_DrawSprite(Sprite4, 345, 345)
If MP_KeyDown( #PB_Key_Space)
;MP_ListGetElement(9,Random(3))
MP_ListSwapElements(9, MP_ListGetElement(9,Random(3)),MP_ListGetElement(9,Random(3)))
;MP_ListSwapElements(9, Sprite2, Sprite3)
;MP_ListSwapElements(9, Sprite3, Sprite4)
;MP_ListSwapElements(9, Sprite4, Sprite1)
EndIf
MP_RenderWorld() ; Render World yeh go on
MP_Flip ()
Until MP_KeyDown(#PB_Key_Escape) Or Event=#PB_Event_CloseWindow
Thank you, but it doesn't fix the transparency issue.leonhardt wrote: use the MP_ListSwapElements function instead
Code: Select all
If Not MP_Graphics3D(800,600,0,1) : End : EndIf
Player = MP_LoadSprite("player.png")
BgTile = MP_LoadSprite("grass.png")
MP_ListSwapElements(9,MP_ListGetElement(9,0),MP_ListGetElement(9,1))
Repeat
MP_DrawTiledSprite(BgTile,0,0)
MP_Box(0,0,415,315,$ffff00,1)
MP_DrawSprite(Player,400,300)
MP_RenderWorld()
MP_Flip()
Until MP_KeyDown(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
you mean this?Sveinung wrote:If you change the color of the players body to somthing like (5,5,5), it will work.
Color (0,0,0) is the transperant color.
Regards
Sveinung
Code: Select all
If Not MP_Graphics3D(800,600,0,1) : End : EndIf
SetCurrentDirectory("c:\rad\projects")
BgTile = MP_LoadSprite("grass.png")
;MP_ListSwapElements(9,MP_ListGetElement(9,0),MP_ListGetElement(9,1))
Player = MP_LoadSprite("player.png")
MP_TransparentSpriteColor(Player,RGB(5,5,5))
;MP_AmbientSetLight($FF2233)
Repeat
MP_DrawTiledSprite(BgTile,0,0)
MP_Box(0,0,300,300,$FFFF00,1)
MP_DrawSprite(Player,400,300)
MP_RenderWorld()
MP_Flip()
Until MP_KeyDown(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
Code: Select all
; MP_RenderWorld()
MP_RenderBegin()
; Draw 2D first
MP_Render2D()
; Draw your sprite last and over text
MP_RenderSprite()
MP_RenderEnd()
Thank you!mpz wrote: 2. What's wrong with alpha in player sprite?
* Ist not a alpha image, it is only a rgb image. The problem, is i use DX9 sprite and in DX9 sprite the black color rgb(0,0,0) is all times transparent. Perhaps i find a solution but for now i have change the black rgb(0,0,0) to rgb(1,1,1) and it works. Test the following image please...
Thanks.mpz wrote: - big sprite with alpha and rotation, but probably this isn't the best solution..
Why not? Other solution is to create a shader (Postprocessing).The shader make the light or darknes from the sprite as circle
but the normal pb sprite3d lib could handle this png file correctly,it use DX9 too, check this code:mpz wrote:Hello to all,
thanks for you help...
@deseven
1. Why the box is on top of all sprites?
The render order is: Sprite and then 2D. To change this you can exchange the MP_RenderWorld() function (2D has no Z-Order) with the following Render commands
2. What's wrong with alpha in player sprite?Code: Select all
; MP_RenderWorld() MP_RenderBegin() ; Draw 2D first MP_Render2D() ; Draw your sprite last and over text MP_RenderSprite() MP_RenderEnd()
* Ist not a alpha image, it is only a rgb image. The problem, is i use DX9 sprite and in DX9 sprite the black color rgb(0,0,0) is all times transparent. Perhaps i find a solution but for now i have change the black rgb(0,0,0) to rgb(1,1,1) and it works. Test the following image please...
Greetings
Code: Select all
InitSprite()
InitSprite3D()
UsePNGImageDecoder()
OpenWindow(0,0,0,800,600,"",$CF1001)
OpenWindowedScreen(WindowID(0),0,0,800,600)
CreateSprite3D(0,LoadSprite(-1,"player.png",#PB_Sprite_Texture|#PB_Sprite_AlphaBlending))
Repeat
ClearScreen($FFFFFF)
Start3D()
DisplaySprite3D(0,200,200)
Stop3D()
FlipBuffers()
Until WindowEvent()=16
That's true...leonhardt wrote: but the normal pb sprite3d lib could handle this png file correctly,it use DX9 too, check this code: