News:

Function Finder  Find all the functions within source code files

Main Menu

G2D question

Started by monkeybot, October 18, 2014, 06:45:42 AM

Previous topic - Next topic

monkeybot

I have been messing around with G2D a bit and seem to be having problems with the perspective sprite command.

if i understand this correctly i just use normal PB sprite setup and then direct the drawing to the GL screen.

I can render sprites to the PB screen but when i uncomment  line 44

G2dDraworderedSpritesToCamera(PerSpectiveCamera)         

it crashes


PlayBASIC Code: [Select]
; PROJECT : Project3
; AUTHOR : PC
; CREATED : 18/10/2014
; EDITED : 18/10/2014
; ---------------------------------------------------------------------
explicit on
#include "G2D_Library.pba"
local q
; for q=0 to 100
; circlec rnd(800),rnd(600),rnd(10),1,rnd($ffffff)

;next
;sync
local FontTextureImage =g2dLoadFont("arial",10,32,0)
// First up, we open GL library.. With our screen size and
Dim GL as tMyGL pointer
GL=G2DStart(800,600)
ScreenLayout 400,000,700,600
// check if the library even opened ?
If int(GL)=0 then end


Global PerSpectiveCamera
global image=newimage(50,50,2)
rendertoimage image
ink $ffffff
circle 25,25,10,1
RenderToScreen

PerSpectiveCamera=g2dNewCamera(1)
if not PerSpectiveCamera then end

g2dShadeBox(0,0,800,600,$304050,$304050,$807050,$807050)
g2dsync()
g2dShadeBox(0,0,800,600,$304050,$304050,$807050,$807050)


local Count=Zoom_Sprites_Scene(1,500,image)
repeat
cls



; G2dDraworderedSpritesToCamera(PerSpectiveCamera)



DrawAllSprites

; local SPeed#=2

; if LeftKey()
; G2DMoveCamera(PerSpectiveCamera,-SPeed#,0)
; endif

; if RightKey()
; G2DMoveCamera(PerSpectiveCamera,SPeed#,0)
; endif

; if UpKey()
; G2DMoveCamera(PerSpectiveCamera,0,-SPeed#)
; endif

; if DownKey()
; G2DMoveCamera(PerSpectiveCamera,0,SPeed#)
; endif
;
; if Keystate(30)
; G2dMoveCameraZ(PerSpectiveCamera,SPeed#)
; endif

; if Keystate(44)
; G2dMoveCameraZ(PerSpectiveCamera,-SPeed#)
; endif


; -------------------------------------------------
; draw on the Direct X surface at the bottom
; -------------------------------------------------
; boxc 0,0,400,100,true,0
; ink -1
; text 10,10,"Test #13: Perspective #"+str$(Count)+" Sprite Scene (Bubble Stars) use Arrow & AZ Keys control camera"
; text 10,20,"Fps:"+str$(fps())

// call PB SYNC too
sync
g2dsync()

until SpaceKey()
g2dend()
end






Psub Zoom_Sprites_Scene(FirstSprite,LastSprite,ThisIMage)


local ScreenWidth=800
local ScreenHeight=600;GetScreenHeight()

local scx=ScreenWidth/2
local scy=ScreenHeight/2

local Pad=50
local lp, MaxZ=3000
For lp=firstsprite to LastSprite

if GetSpriteStatus(lp) =0

CreateSprite lp

spriteimage lp,ThisIMage
spritedrawmode lp,2
centerspritehandle lp
positionspritexyz lp, rndrange(Pad,screenWidth-Pad)-scx,rndrange(Pad,screenHeight-Pad)-scy,rnd(MaxZ)

spritefilter lp,true

; spritetint lp,rnd($ffffff)|(rnd(128)<<24)

endif

local z#=GetSpriteZ(lp)-5

if z#<pad
z#=MaxZ
positionspritexyz lp, rndrange(Pad,screenWidth-Pad)-scx,rndrange(Pad,screenHeight-Pad)-scy,z#
; spritetint lp,rnd($ffffff)|(rnd(128)<<24)
else
positionspriteZ lp,z#
endif


next

Total=(LastSprite+1)-firstsprite

EndPsub Total





// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// ---[ (MISC SUB'S To INIT Materials iused in the various demos ]-----------------------------------------------
Login required to view complete source code




monkeybot

i didnt convert to texture

g2dConvertToTexture(image)

monkeybot

#2
now i can't get the alpha mask working...

PlayBASIC Code: [Select]
; PROJECT : Project3
; AUTHOR : PC
; CREATED : 18/10/2014
; EDITED : 18/10/2014
; ---------------------------------------------------------------------
explicit on
#include "G2D_Library.pba"
local q
; for q=0 to 100
; circlec rnd(800),rnd(600),rnd(10),1,rnd($ffffff)

;next
;sync
local FontTextureImage =g2dLoadFont("arial",10,32,0)
// First up, we open GL library.. With our screen size and
Dim GL as tMyGL pointer
GL=G2DStart(400,600)
ScreenLayout 400,000,800,600
// check if the library even opened ?
If int(GL)=0 then end


Global PerSpectiveCamera
global image=newfximage(50,50,1)
rendertoimage image
ink $ffffff
circle 25,25,10,1
RenderToScreen
;drawimage image,10,10,1
;sync
;Waitkey
local gimage=100
;g2dCreateImage(gimage,50,50) ; Cr
;rendertoimage gimage
;circlec 25,25,10,1,$ff0000
;rendertoscreen
MakeAlphaChannel(image,argb(0,0,0,0))
;MakeAlphaChannel(image,argb(0,0,0,0))
g2dConvertToTexture(image)



PerSpectiveCamera=g2dNewCamera(1)
if not PerSpectiveCamera then end

; g2dsync()
; g2dShadeBox(0,0,800,600,$304050,$304050,$807050,$807050)


local Count=Zoom_Sprites_Scene(1,500,image)
repeat
cls
g2dcls(0)

g2dShadeBox(0,0,200,600,$304050,$304050,$807050,$807050)
g2dShadeBox(200,0,400,600,$0,$33333,$ffffff,$ffffff)

G2dDraworderedSpritesToCamera(PerSpectiveCamera)
; g2ddrawallsprites()


DrawAllSprites

local SPeed#=2

if LeftKey()
G2DMoveCamera(PerSpectiveCamera,-SPeed#,0)
endif

if RightKey()
G2DMoveCamera(PerSpectiveCamera,SPeed#,0)
endif

if UpKey()
G2DMoveCamera(PerSpectiveCamera,0,-SPeed#)
endif
if DownKey()
G2DMoveCamera(PerSpectiveCamera,0,SPeed#)
endif

if Keystate(30)
G2dMoveCameraZ(PerSpectiveCamera,SPeed#)
endif

if Keystate(44)
G2dMoveCameraZ(PerSpectiveCamera,-SPeed#)
endif


; -------------------------------------------------
; draw on the Direct X surface at the bottom
; -------------------------------------------------
; boxc 0,0,400,100,true,0
; ink -1
; text 10,10,"Test #13: Perspective #"+str$(Count)+" Sprite Scene (Bubble Stars) use Arrow & AZ Keys control camera"
; text 10,20,"Fps:"+str$(fps())

// call PB SYNC too
sync
g2dsync()

until SpaceKey()
g2dend()
end






Psub Zoom_Sprites_Scene(FirstSprite,LastSprite,ThisIMage)


; local ScreenWidth=400
; local ScreenHeight=600;GetScreenHeight()

; local scx=ScreenWidth/2
; local scy=ScreenHeight/2

; local Pad=50
local lp, MaxZ=3000
For lp=firstsprite to LastSprite

if GetSpriteStatus(lp) =0
;spritedebug
CreateSprite lp

spriteimage lp,ThisIMage
spritedrawmode lp,2
centerspritehandle lp
; positionspritexyz lp, 000,100,lp*100;rnd(500)

positionspritexyz lp, rnd(400),rnd(600),rndrange(500,1500)
#print GetSpriteX(lp)
#print GetSpriteY(lp)

spritefilter lp,true

spritetint lp,rnd($ffffff)|(rnd(128)<<24)

endif

; local z#=GetSpriteZ(lp)-5

; if z#
; z#=MaxZ
; positionspritexyz lp, rnd(400),rnd(400),z#
; ;
;positionspritexyz lp, rndrange(Pad,screenWidth-Pad)-scx,rndrange(Pad,screenHeight-Pad)-scy,z#
Login required to view complete source code

kevin


Had quick look which revision 6 prototype and i think it'd a by product of the textures initial state, since the library has to manage the state changes per texture.   In other words the 'transparency state' that's being set different for the texture, isn't  what the G2D thinks it's current state is.  So it thinks the it's was transparent, when it's actually opaque.


   While not a big deal, just remember the START() function builds the GL interface,  so calling g2d functions before it exists is unsafe an useage.

 
PlayBASIC Code: [Select]
       // This requires the GL device be opened first, so it'll fail if it's called before. The result won't be a valid texture.
local FontTextureImage =g2dLoadFont("arial",10,32,0)

// First up, we open GL library.. With our screen size and
Dim GL as tMyGL pointer
GL=G2DStart(400,600)








monkeybot

#4
Ahh that'll be why the fonts weren't working then.

So is the transparency thing a bug?

I am loving the perspective sprites,do i remember them from 1.7?



kevin

QuoteSo is the transparency thing a bug?

I'd say so..

QuoteI am loving the perspective sprites,do i remember them from 1.7?

    Yep, it's basically the same thing.. Perspective Platfomer Example (PBFX)   (note the 2007 vintage)