MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: MP3D Engine Alpha 31

Post by AndyLy »

This is not an emergency. Rest, then you will work on the engine with new forces. )
Happy holidays!
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 31

Post by Psychophanta »

Of course, we expect you take advantage of your holidays to improve the MP3D lib.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 31

Post by mpz »

Hi,

@Alexi Do you use the correct pb version 5.11 ?!? I think it is an error mesage from an old pb version 4.11 or older.

I work on some bugfixes and have a new nice Physic command MP_ChangePhysikHull(Mesh, Typ) Now. If you change a mesh (vertex commands or size) the comamnd actualised the physic body for collisions. Next step are help file and make the new version

Demosample
http://www.flasharts.de/mpz/Physic.exe

Image


Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MP3D Engine Alpha 31

Post by deseven »

Hello. I need some help :)

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
grass.png:
Image

player.png:
Image

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.
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: MP3D Engine Alpha 31

Post by leonhardt »

deseven wrote:Hello. I need some help :)

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
grass.png:
Image

player.png:
Image

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.
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 MPZ

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
use the MP_ListSwapElements function instead :)
poor English...

PureBasic & Delphi & VBA
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MP3D Engine Alpha 31

Post by deseven »

leonhardt wrote: use the MP_ListSwapElements function instead :)
Thank you, but it doesn't fix the transparency issue.

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
Still the same ugly player sprite.

UPD: It seems that I got the logic :)
The list is filled in order of the sprite loading. So, the easy way is to load sprites in the order of their appearance.
1. BgTile = MP_LoadSprite("grass.png")
2. Player = MP_LoadSprite("player.png")
But there is still some problem with alphachannel.
I got this
Image
instead of that
Image
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Re: MP3D Engine Alpha 31

Post by Sveinung »

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
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: MP3D Engine Alpha 31

Post by leonhardt »

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
you mean this?
no,it doesn't work.

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
poor English...

PureBasic & Delphi & VBA
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 31

Post by mpz »

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

Code: Select all

  ; MP_RenderWorld()     

  MP_RenderBegin()
      ; Draw 2D first
      MP_Render2D()
      ; Draw your sprite last and over text
      MP_RenderSprite() 
   MP_RenderEnd()
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...

Image

Greetings
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MP3D Engine Alpha 31

Post by deseven »

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...
Thank you!
But it's actually a RGBA image which have a usuall RGB + additional alpha-channel. Is there a way to load and display theese correctly?
Another small question - how can i hide the mouse cursor?

And... Maybe someone can advice me how to make flashlight effect on top of sprites? I tried to use a big sprite with alpha and rotation, but probably this isn't the best solution...
http://dl.dropboxusercontent.com/u/9439 ... -28-25.jpg
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 31

Post by mpz »

Hi dseven,

if you use the color rgb(1,1,1) for the black color the sprite do what you want.

- how can i hide the mouse cursor?

Have a look on the MP_UseCursor(a) command

- 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


Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MP3D Engine Alpha 31

Post by deseven »

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
Thanks.
I made it by using another technique (found it in google :) ):
- draw a shadow mask (1x1 white sprite with 80-95% transparency, scaled to the whole screen)
- draw any lights as a semi-transparent white sprites
- draw a background with MP_SpriteBlendingMode(sprite,1,3)
http://dl.dropbox.com/u/943974/td_proto ... -55-74.png

But with this approach i don't know how to draw objects which have their own transparency... Any ideas?

And another small question - how can i set filtering level? Do i need to use MP_SetSamplerState?
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: MP3D Engine Alpha 31

Post by leonhardt »

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

Code: Select all

  ; MP_RenderWorld()     

  MP_RenderBegin()
      ; Draw 2D first
      MP_Render2D()
      ; Draw your sprite last and over text
      MP_RenderSprite() 
   MP_RenderEnd()
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...

Image

Greetings
but the normal pb sprite3d lib could handle this png file correctly,it use DX9 too, check this code:

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

poor English...

PureBasic & Delphi & VBA
User avatar
deseven
Enthusiast
Enthusiast
Posts: 367
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: MP3D Engine Alpha 31

Post by deseven »

leonhardt wrote: but the normal pb sprite3d lib could handle this png file correctly,it use DX9 too, check this code:
That's true...
But whatever, it's not hard to use $010101 instead of $000000

P.S. Better flashlight sprite :) http://dl.dropboxusercontent.com/u/9439 ... oto_sh.png
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: MP3D Engine Alpha 31

Post by dobro »

@mpz Excellent Work ! :shock:
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply