AtomicX ! i have try ! but with animated object the cubic map on the static scene objects don't change ! a solution ?
THE CODE :
Include "Inc_CubeMapping.bb"
Graphics3D 640,480,16,2
SetBuffer BackBuffer()
; If user's graphics card does not support cubic mapping then quit example
If GfxDriverCaps3D()<110 Then RuntimeError "Sorry, your graphics card does not support cubic environemnt maps."
cam=CreateCamera()
PositionEntity cam,0,10,-30
light1=CreateLight(2)
PositionEntity light1,30,30,-30
LightRange light1,150
LightColor light1,255,255,255
light2=CreateLight(2)
PositionEntity light2,-30,30,30
LightRange light2,150
LightColor light2,255,255,255
teapot=LoadMesh("silicon.3Ds")
ScaleEntity teapot,0.1,0.1,0.1
PositionEntity teapot,0,9,0
EntityShininess teapot,1
EntityColor teapot,255,255,0
teapot1=CreateSphere(80)
ScaleEntity teapot1,5,5,5
PositionEntity teapot1,10,9,0
EntityShininess teapot1,1
EntityColor teapot1,0,255,0
; ground
ground1=CreateCube()
PositionEntity ground1,0,0,0
ScaleEntity ground1,40,1,40
ground2=CreateCube()
PositionEntity ground2,0,0,40
ScaleEntity ground2,40,40,1
ground3=CreateCube()
PositionEntity ground3,0,0,-40
ScaleEntity ground3,40,40,1
Texture=LoadTexture ("01.bmp")
EntityTexture Ground1,Texture
; Create texture with color + cubic environment map + store in vram flags
size=256
CreateCubeMap(128,teapot,2)
CreateCubeMap(128,teapot1,2)
CreateCubeMap(128,ground3,2)
While Not KeyDown(1)
mxs#=mxs#+(MouseXSpeed()/5.0)
mys#=mys#-(MouseYSpeed()/5.0)
RotateEntity cam,mys#,-mxs#,0
MoveMouse GraphicsWidth()/2,GraphicsHeight ()/2
If KeyDown(200)=True Then MoveEntity cam,0,0,.3 ; move camera forward
If KeyDown(208)=True Then MoveEntity cam,0,0,-.3 ; move camera back
If KeyDown(205)=True Then MoveEntity cam,.3,0,0 ; move camera left
If KeyDown(203)=True Then MoveEntity cam,-.3,0,0 ; move camera right
TurnEntity teapot,0.2,0.2,0.2
TurnEntity teapot1,0.2,0.2,0.2
;UpdateCubemap()
RenderWorld
Flip
Wend
THE INCLUDE :
; *********************************************************************
; * Include : Création de cubic map *
; * *
; * Version : V1.0 *
; *********************************************************************
; --------------------------
; Type des CubeMap
; --------------------------
Type TCubeMap
Field CubeCamera
Field CubeTexture
Field CubeEntity
End Type
; -------------------------------------------------------------------------------
; Fonction qui permet d'initialiser le cubemaping d'un objet
; -------------------------------------------------------------------------------
Function CreateCubeMap(Size,Entity,Index)
Cube.TCubeMap=New TCubeMap
Cube\CubeCamera=CreateCamera()
Cube\CubeTexture=CreateTexture(Size,Size,1+128+256+512)
Cube\CubeEntity=Entity
TmpTextureSize=TextureWidth(Cube\CubeTexture)
; --------------------------------
; Affichage de la camera
; --------------------------------
ShowEntity Cube\CubeCamera
; ---------------------------------
; On cache l'entite attache
; ---------------------------------
HideEntity Cube\CubeEntity
; -------------------------------------------------------------
; On positionne la camera au centre de l'objet
; -------------------------------------------------------------
PositionEntity Cube\CubeCamera,EntityX#(Cube\CubeEntity),EntityY#(Cube\CubeEntity),EntityZ#(Cube\CubeEntity)
CameraClsMode Cube\CubeCamera,False,True
; ------------------------------
; Definition du viewport
; ------------------------------
CameraViewport Cube\CubeCamera,0,0,TmpTextureSize,TmpTextureSize
; ------------------
; Face gauche
; ------------------
SetCubeFace Cube\CubeTexture,0
RotateEntity Cube\CubeCamera,0,90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face avant
; ---------------
SetCubeFace Cube\CubeTexture,1
RotateEntity Cube\CubeCamera,0,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face droite
; ---------------
SetCubeFace Cube\CubeTexture,2
RotateEntity Cube\CubeCamera,0,-90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; -----------------
; Face arriere
; -----------------
SetCubeFace Cube\CubeTexture,3
RotateEntity Cube\CubeCamera,0,180,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ------------------
; Face dessus
; ------------------
SetCubeFace Cube\CubeTexture,4
RotateEntity Cube\CubeCamera,-90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------
; Face dessous
; --------------------
SetCubeFace Cube\CubeTexture,5
RotateEntity Cube\CubeCamera,90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------------
; On reaffiche l'entite
; --------------------------
ShowEntity Cube\CubeEntity
; ----------------------------
; On cache la camera
; ----------------------------
HideEntity Cube\CubeCamera
EntityTexture Cube\CubeEntity,Cube\CubeTexture,0,Index
End Function
; ------------------------------------------------------------------------
; Fonction qui permet de rafraichir les cubes mapping
; ------------------------------------------------------------------------
Function UpdateCubemap()
For Cube.TCubeMap=Each TCubeMap
TmpTextureSize=TextureWidth(Cube\CubeTexture)
; --------------------------------
; Affichage de la camera
; --------------------------------
ShowEntity Cube\CubeCamera
; ---------------------------------
; On cache l'entite attache
; ---------------------------------
HideEntity Cube\CubeEntity
; -------------------------------------------------------------
; On positionne la camera au centre de l'objet
; -------------------------------------------------------------
PositionEntity Cube\CubeCamera,EntityX#(Cube\CubeEntity),EntityY#(Cube\CubeEntity),EntityZ#(Cube\CubeEntity)
CameraClsMode Cube\CubeCamera,False,True
; ------------------------------
; Definition du viewport
; ------------------------------
CameraViewport Cube\CubeCamera,0,0,TmpTextureSize,TmpTextureSize
; ------------------
; Face gauche
; ------------------
SetCubeFace Cube\CubeTexture,0
RotateEntity Cube\CubeCamera,0,90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face avant
; ---------------
SetCubeFace Cube\CubeTexture,1
RotateEntity Cube\CubeCamera,0,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face droite
; ---------------
SetCubeFace Cube\CubeTexture,2
RotateEntity Cube\CubeCamera,0,-90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; -----------------
; Face arriere
; -----------------
SetCubeFace Cube\CubeTexture,3
RotateEntity Cube\CubeCamera,0,180,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ------------------
; Face dessus
; ------------------
SetCubeFace Cube\CubeTexture,4
RotateEntity Cube\CubeCamera,-90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------
; Face dessous
; --------------------
SetCubeFace Cube\CubeTexture,5
RotateEntity Cube\CubeCamera,90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------------
; On reaffiche l'entite
; --------------------------
ShowEntity Cube\CubeEntity
; ----------------------------
; On cache la camera
; ----------------------------
HideEntity Cube\CubeCamera
Next
End Function
THE CODE :
Include "Inc_CubeMapping.bb"
Graphics3D 640,480,16,2
SetBuffer BackBuffer()
; If user's graphics card does not support cubic mapping then quit example
If GfxDriverCaps3D()<110 Then RuntimeError "Sorry, your graphics card does not support cubic environemnt maps."
cam=CreateCamera()
PositionEntity cam,0,10,-30
light1=CreateLight(2)
PositionEntity light1,30,30,-30
LightRange light1,150
LightColor light1,255,255,255
light2=CreateLight(2)
PositionEntity light2,-30,30,30
LightRange light2,150
LightColor light2,255,255,255
teapot=LoadMesh("silicon.3Ds")
ScaleEntity teapot,0.1,0.1,0.1
PositionEntity teapot,0,9,0
EntityShininess teapot,1
EntityColor teapot,255,255,0
teapot1=CreateSphere(80)
ScaleEntity teapot1,5,5,5
PositionEntity teapot1,10,9,0
EntityShininess teapot1,1
EntityColor teapot1,0,255,0
; ground
ground1=CreateCube()
PositionEntity ground1,0,0,0
ScaleEntity ground1,40,1,40
ground2=CreateCube()
PositionEntity ground2,0,0,40
ScaleEntity ground2,40,40,1
ground3=CreateCube()
PositionEntity ground3,0,0,-40
ScaleEntity ground3,40,40,1
Texture=LoadTexture ("01.bmp")
EntityTexture Ground1,Texture
; Create texture with color + cubic environment map + store in vram flags
size=256
CreateCubeMap(128,teapot,2)
CreateCubeMap(128,teapot1,2)
CreateCubeMap(128,ground3,2)
While Not KeyDown(1)
mxs#=mxs#+(MouseXSpeed()/5.0)
mys#=mys#-(MouseYSpeed()/5.0)
RotateEntity cam,mys#,-mxs#,0
MoveMouse GraphicsWidth()/2,GraphicsHeight ()/2
If KeyDown(200)=True Then MoveEntity cam,0,0,.3 ; move camera forward
If KeyDown(208)=True Then MoveEntity cam,0,0,-.3 ; move camera back
If KeyDown(205)=True Then MoveEntity cam,.3,0,0 ; move camera left
If KeyDown(203)=True Then MoveEntity cam,-.3,0,0 ; move camera right
TurnEntity teapot,0.2,0.2,0.2
TurnEntity teapot1,0.2,0.2,0.2
;UpdateCubemap()
RenderWorld
Flip
Wend
THE INCLUDE :
; *********************************************************************
; * Include : Création de cubic map *
; * *
; * Version : V1.0 *
; *********************************************************************
; --------------------------
; Type des CubeMap
; --------------------------
Type TCubeMap
Field CubeCamera
Field CubeTexture
Field CubeEntity
End Type
; -------------------------------------------------------------------------------
; Fonction qui permet d'initialiser le cubemaping d'un objet
; -------------------------------------------------------------------------------
Function CreateCubeMap(Size,Entity,Index)
Cube.TCubeMap=New TCubeMap
Cube\CubeCamera=CreateCamera()
Cube\CubeTexture=CreateTexture(Size,Size,1+128+256+512)
Cube\CubeEntity=Entity
TmpTextureSize=TextureWidth(Cube\CubeTexture)
; --------------------------------
; Affichage de la camera
; --------------------------------
ShowEntity Cube\CubeCamera
; ---------------------------------
; On cache l'entite attache
; ---------------------------------
HideEntity Cube\CubeEntity
; -------------------------------------------------------------
; On positionne la camera au centre de l'objet
; -------------------------------------------------------------
PositionEntity Cube\CubeCamera,EntityX#(Cube\CubeEntity),EntityY#(Cube\CubeEntity),EntityZ#(Cube\CubeEntity)
CameraClsMode Cube\CubeCamera,False,True
; ------------------------------
; Definition du viewport
; ------------------------------
CameraViewport Cube\CubeCamera,0,0,TmpTextureSize,TmpTextureSize
; ------------------
; Face gauche
; ------------------
SetCubeFace Cube\CubeTexture,0
RotateEntity Cube\CubeCamera,0,90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face avant
; ---------------
SetCubeFace Cube\CubeTexture,1
RotateEntity Cube\CubeCamera,0,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face droite
; ---------------
SetCubeFace Cube\CubeTexture,2
RotateEntity Cube\CubeCamera,0,-90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; -----------------
; Face arriere
; -----------------
SetCubeFace Cube\CubeTexture,3
RotateEntity Cube\CubeCamera,0,180,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ------------------
; Face dessus
; ------------------
SetCubeFace Cube\CubeTexture,4
RotateEntity Cube\CubeCamera,-90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------
; Face dessous
; --------------------
SetCubeFace Cube\CubeTexture,5
RotateEntity Cube\CubeCamera,90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------------
; On reaffiche l'entite
; --------------------------
ShowEntity Cube\CubeEntity
; ----------------------------
; On cache la camera
; ----------------------------
HideEntity Cube\CubeCamera
EntityTexture Cube\CubeEntity,Cube\CubeTexture,0,Index
End Function
; ------------------------------------------------------------------------
; Fonction qui permet de rafraichir les cubes mapping
; ------------------------------------------------------------------------
Function UpdateCubemap()
For Cube.TCubeMap=Each TCubeMap
TmpTextureSize=TextureWidth(Cube\CubeTexture)
; --------------------------------
; Affichage de la camera
; --------------------------------
ShowEntity Cube\CubeCamera
; ---------------------------------
; On cache l'entite attache
; ---------------------------------
HideEntity Cube\CubeEntity
; -------------------------------------------------------------
; On positionne la camera au centre de l'objet
; -------------------------------------------------------------
PositionEntity Cube\CubeCamera,EntityX#(Cube\CubeEntity),EntityY#(Cube\CubeEntity),EntityZ#(Cube\CubeEntity)
CameraClsMode Cube\CubeCamera,False,True
; ------------------------------
; Definition du viewport
; ------------------------------
CameraViewport Cube\CubeCamera,0,0,TmpTextureSize,TmpTextureSize
; ------------------
; Face gauche
; ------------------
SetCubeFace Cube\CubeTexture,0
RotateEntity Cube\CubeCamera,0,90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face avant
; ---------------
SetCubeFace Cube\CubeTexture,1
RotateEntity Cube\CubeCamera,0,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ---------------
; Face droite
; ---------------
SetCubeFace Cube\CubeTexture,2
RotateEntity Cube\CubeCamera,0,-90,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; -----------------
; Face arriere
; -----------------
SetCubeFace Cube\CubeTexture,3
RotateEntity Cube\CubeCamera,0,180,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; ------------------
; Face dessus
; ------------------
SetCubeFace Cube\CubeTexture,4
RotateEntity Cube\CubeCamera,-90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------
; Face dessous
; --------------------
SetCubeFace Cube\CubeTexture,5
RotateEntity Cube\CubeCamera,90,0,0
RenderWorld
CopyRect 0,0,TmpTextureSize,TmpTextureSize,0,0,BackBuffer(),TextureBuffer(Cube\CubeTexture)
; --------------------------
; On reaffiche l'entite
; --------------------------
ShowEntity Cube\CubeEntity
; ----------------------------
; On cache la camera
; ----------------------------
HideEntity Cube\CubeCamera
Next
End Function