How to map a scene on a cube

Blitz3D Forums/Blitz3D Programming/How to map a scene on a cube

Dirk Krause(Posted 2004) [#1]
Is there any example code out there how to map some scene made with 'renderworld' to a texture that is mapped to an object? Like you have a TV set mesh watching an FPS?


N(Posted 2004) [#2]
Tex = CreateTexture(256,256,1+16+32+256)
Buffer = CreateImage(GraphicsWidth(),GraphicsHeight())

RenderWorld
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,BackBuffer(),ImageBuffer(Buffer)
ResizeImage Buffer,256,256
CopyRect 0,0,256,256,0,0,ImageBuffer(Buffer),TextureBuffer(Tex)


I think it goes something like that, but I could be wrong, since I really don't do that much stuff like this at all (any more, at least).


Dirk Krause(Posted 2004) [#3]
This way you put the scene into a texture, ok. But what if you want this texture to be on a rotating cube? You need a second RenderWorld, right?


N(Posted 2004) [#4]
Yes. So clear the backbuffer and render from another point of view.


semar(Posted 2004) [#5]
There's an example by Mark, in the "mak" directory of the Blitz3D installation, which covers exactly this case.

Sergio.


Dirk Krause(Posted 2004) [#6]
Right! Thanks a lot!


Dirk Krause(Posted 2004) [#7]
So here goes, the multicam example plus cube texturing (resizing the image _really_ slows it down, so I left it out):



Graphics3D 640,480

tex=CreateTexture( 64,64 )
SetBuffer TextureBuffer( tex )
Color 255,0,0:Rect 0,0,32,32:Rect 32,32,32,32
Color 255,128,0:Rect 32,0,32,32:Rect 0,32,32,32
SetBuffer BackBuffer()
Color 255,255,255

cone=CreateCone(20)
EntityTexture cone,tex

sphere=CreateSphere(10)
PositionEntity sphere,2,0,0
EntityTexture sphere,tex

cylinder=CreateCylinder(20)
PositionEntity cylinder,-2,0,0
EntityTexture cylinder,tex

cubetex = CreateTexture(256,256,1+16+32+256)
cubebuffer = CreateImage(256,256)
cube=CreateCube()
PositionEntity cube,0,0,-8
EntityTexture cube,cubetex

light=CreateLight()
TurnEntity light,45,45,0

pivot=CreatePivot()

z_cam=CreateCamera( pivot )
CameraViewport z_cam,0,0,320,240
PositionEntity z_cam,0,0,-5

y_cam=CreateCamera( pivot )
CameraViewport y_cam,320,0,320,240
PositionEntity y_cam,0,5,0
TurnEntity y_cam,90,0,0

x_cam=CreateCamera( pivot )
CameraViewport x_cam,0,240,320,240
TurnEntity x_cam,0,-90,0
PositionEntity x_cam,-5,0,0

cube_cam = CreateCamera()
CameraViewport cube_cam,320,240,320,240
TurnEntity cube_cam,180,0,0
PositionEntity cube_cam,0,0,-5


While Not KeyHit(1)

    TurnEntity cube,.1,.2,.3
    TurnEntity cylinder,.4,.6,.8

	If KeyDown(203) MoveEntity pivot,-.1,0,0
	If KeyDown(205) MoveEntity pivot,.1,0,0
	If KeyDown(200) MoveEntity pivot,0,.1,0
	If KeyDown(208) MoveEntity pivot,0,-.1,0
	If KeyDown(30) MoveEntity pivot,0,0,.1
	If KeyDown(44) MoveEntity pivot,0,0,-.1

	UpdateWorld
	RenderWorld
	Text 0,0,"Front"

    CopyRect 0,0,256,256,0,0,BackBuffer(),ImageBuffer(cubeBuffer)
    ; ResizeImage cubeBuffer,256,256
    CopyRect 0,0,256,256,0,0,ImageBuffer(cubeBuffer),TextureBuffer(cubeTex)

	Text 320,0,"Top"
	Text 0,240,"Left"
	Text 320,240,"Cube"
	Flip



Wend

End



Ziltch(Posted 2004) [#8]
Any need for the imagebuffer?

try skipping the copy to theimagebuffer ;
CopyRect 0,0,256,256,0,0,BackBuffer(),TextureBuffer(cubeTex).

Saves a copyrect command!


N(Posted 2004) [#9]
Any need for the imagebuffer?


Some need. Thing is, the backbuffer isn't sized at 256*256, so you're only copying a corner of it with your suggestion. By copying it to the image buffer, resizing, and copying it to the texture buffer you essentially get the whole thing. Problem with the resizing is that it really is horrendously slow.


poopla(Posted 2004) [#10]
Why not resize the rendering viewport? Then hardware takes care of the scaling with a simple scissor test.


Michael Reitzenstein(Posted 2004) [#11]
Scissor tests have nothing to do with scaling.


poopla(Posted 2004) [#12]
My bad I've been awake for WAY too long.