SetCubeFace texture,face

Parameters

texture - texture handle (must be created with the cubic environment map flag, 128)

face - which face of the cubemap to select for drawing
0: left
1: forward (default)
2: right
3: backward
4: up
5: down

Description

Selects which face of a cubemap texture you draw into.

A cubic environment map is really six images, one per direction. SetCubeFace picks the face that TextureBuffer will hand back next, so the drawing pattern is: SetCubeFace, SetBuffer TextureBuffer(tex), draw, and repeat for each of the six faces. Games use this to render live reflections - point a camera in each direction, render into each face in turn, and the cubemap reflects the scene.

In classic Blitz3D the texture had to be created with flags 128+256 - 128 makes it a cubemap, and 256 stores it in video memory, which the old renderer required before cube faces could be drawn into. The example keeps both flags so the same code works everywhere.

On the Blitz3D+ DirectX 12 runtime, SetCubeFace is currently a no-op: the face selection is ignored and every draw lands in the same single image, which entities then map by their UV coordinates. The command is safe to call - a program written for the classic renderer runs without errors - but you will not see six distinct faces yet, as the example demonstrates honestly on screen.

See also: SetCubeMode, CreateTexture, TextureBuffer, SetBuffer.

Example

; SetCubeFace Example
; -------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-4

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

; Flag 128 = cubic environment map, flag 256 = keep it drawable
cube_tex=CreateTexture(128,128,128+256)

; The ball that wears the cubemap
ball=CreateSphere(16)
PositionEntity ball,0,1,0
EntityTexture ball,cube_tex

; Draw all six faces to start with
For f=0 To 5
    draw_face(cube_tex,f)
Next
last_face=5

While Not KeyDown(1)

    ; Keys 1-6 draw into one cube face; Space redraws all six
    For f=0 To 5
        If KeyHit(2+f)
            draw_face(cube_tex,f)
            last_face=f
        EndIf
    Next
    If KeyHit(57)
        For f=0 To 5
            draw_face(cube_tex,f)
        Next
        last_face=5
    EndIf

    TurnEntity ball,0,1,0

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"1-6: draw cube face 0-5   Space: draw all six   Esc: exit"
    Text 0,20,"SetCubeFace cube_tex,"+last_face
    Text 0,40,"Note: this DirectX 12 runtime does not select cube faces yet, so"
    Text 0,60,"every draw lands in the same image and the sphere maps it by UV."

    Flip

Wend

End

Function draw_face(tex,f)
    ; Select the destination face, then draw into the texture buffer
    SetCubeFace tex,f
    SetBuffer TextureBuffer(tex)
    ClsColor 40+f*35,220-f*30,120+f*20
    Cls
    Color 0,0,0
    Text 8,8,"face "+f
    SetBuffer BackBuffer()
    Color 255,255,255
End Function

Index