News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Images Rotation & Render Method Examples

Started by kevin, February 26, 2010, 11:36:19 PM

Previous topic - Next topic

kevin

 Images Rotation & Render Method Examples

  Behind the scenes PlayBASIC & it's brother PBFX use various rendering devices to perform actions upon images.   So the rendering method a graphic command uses, is determined by a combination of the type of image you supply the command and what rendering methods are available to the rendering device.    If no method is available (the drawmode doesn't exist for this device) then it'll default to software rendering if possible.  

 Image Types

  Video (Direct Draw / Video Memory)
  FX     (Software / System Memory)
  3D     (Direct3D / Video Memory)  (Only available in PBFX revisions)

  See Tutorial -> Crash course in Image & Sprites Draw Modes


 Lets have a quick look at some examples and see what device they're using to do the rendering job.
 
Image Rotation (PlayBASIC V1.63 / V1.64)

PlayBASIC Code: [Select]
   Width=128
Height=Width

// Create a FX image surface in system memory.
CreateFXimage 1,Width,Height

// put something on it
rendertoimage 1
For lp=0 to 1000
dotc rnd(width),rnd(height),rndrgb()
linec rnd(width),rnd(height),rnd(width),rnd(height),rndrgb()
next

rendertoscreen

#if PLayBasicVersion>163
screenVsync on
#else
SetFps 60
#endif

Do

Cls 255

Angle#=Angle#+1

Size#=2+Cos(angle#)*1

// Draw the rotated image, now since this is FX image,
// the GFX engine will default to the software engine for this
// task.
DrawRotatedImage 1,200,300,Angle#,Size#,2,Width/-2,Height/-2,false

// draw it again but with filtering enabled (If it's available!)
DrawRotatedImage 1,600,300,Angle#,Size#,2,Width/-2,Height/-2,false+8*(PLayBasicVersion>163)

Sync
loop



  In this example (For PlayBasic V1.63 Learning and 1.64K Retail), the image type is that of an FX surface. So The graphic engine will default to using  PB's standard  CPU rendering method in the Gfx lib.    In PB1.64 version this support filtering,  older 1.63 versions don't
 



 
Image Rotation (PBFX)

PlayBASIC Code: [Select]
   Width=128
Height=Width

// Create a 3D image surface.
Create3Dimage 1,Width,Height


// put something on it
rendertoimage 1
For lp=0 to 1000
dotc rnd(width),rnd(height),rndrgb()
linec rnd(width),rnd(height),rnd(width),rnd(height),rndrgb()
next

rendertoscreen


screenVsync on

Do

Cls 255

Angle#++

Size#=2+Cos(angle#)*1

// Draw the rotated image, since it's a 3D surface and we're
// rendering to the screen, the computers 3D GPU is used for the task
DrawRotatedImage 1,200,300,Angle#,Size#,2,Width/-2,Height/-2,false

// draw it again but with filtering enabled (If it's available!)
DrawRotatedImage 1,600,300,Angle#,Size#,2,Width/-2,Height/-2,false+8

Sync
loop
Sync




 In this example for PBFX, we're creating a 3D image.  These images are textures on your video cards gpu and can be drawn using the Direct3D device (generally).  

 Try,  Changing the Create3DImage to CreateImage and see what happens..    




 Image Rotation (Really Common Error!)


PlayBASIC Code: [Select]
   Width=128
Height=Width

// Create a standard video image surface.
Createimage 1,Width,Height


// put something on it
rendertoimage 1
For lp=0 to 1000
dotc rnd(width),rnd(height),rndrgb()
linec rnd(width),rnd(height),rnd(width),rnd(height),rndrgb()
next

rendertoscreen

screenVsync on

Do

Cls 255

Angle#++

Size#=2+Cos(angle#)*1

// Draw the rotated image, now since this is VIDEO image,
// there;s no rotation method available to it. So it'll default to
// software rendering.
DrawRotatedImage 1,200,300,Angle#,Size#,2,Width/-2,Height/-2,false

// draw it again but with filtering enabled (If it's available!)
DrawRotatedImage 1,600,300,Angle#,Size#,2,Width/-2,Height/-2,false+8

Sync
loop
Sync




  Nice and slow huh..    This occurs because the DrawDraw device in DirectX doesn't support image rotation, so the rendering has to drop back to the PB gfx lib's CPU rendering method.   Now since the surface is in video memory, the CPU can't read from it quick enough, so it chugs to a halt.

  See Tutorial -> Crash course in Image & Sprites Draw Modes

  Now what about direct 3D in PBFX ?  Unfortunately, the Direct3D device can't use direct draws images, so it'll default back to software rendering also.  For Direct3D, Images have to be explicitly set up for use with it.  


Crystal Noir

#1
Good samples.