; dxSetCubeFace Example ; ------------------- width=640 height=480 depth=0 mode=0 dxGraphics3D width,height,depth,mode dxSetBuffer dxBackBuffer() ; 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=dxCreateCamera() dxPositionEntity cam,0,10,-10 ; Create separate camera for updating cube map - this allows us to manipulate main camera and cube camera which avoids any confusion cube_cam=dxCreateCamera() dxHideEntity cube_cam light=dxCreateLight() dxRotateEntity light,90,0,0 ; Load object we will apply cubemap to - the classic teapot teapot=dxLoadMesh("media/teapot.x") dxScaleEntity teapot,3,3,3 dxPositionEntity teapot,0,10,0 ; Create some scenery ; ground ground=dxCreatePlane() dxEntityColor ground,168,133,55 ground_tex=dxLoadTexture("media/sand.bmp") dxScaleTexture ground_tex,10,10 dxEntityTexture ground,ground_tex ; sky sky=dxCreateSphere(24) dxScaleEntity sky,500,500,500 dxFlipMesh sky dxEntityFX sky,1 sky_tex=dxLoadTexture("media/sky.bmp") dxEntityTexture sky,sky_tex ; cactus cactus=dxLoadMesh("media/cactus2.x") dxFitMesh cactus,-5,0,-5,2,6,.5 ; camel camel=dxLoadMesh("media/camel.x") dxFitMesh camel,5,0,-5,6,5,4 ; Load ufo to give us a dynamic moving object that the cubemap will be able to reflect ufo_piv=dxCreatePivot() dxPositionEntity ufo_piv,0,15,0 ufo=dxLoadMesh("media/green_ufo.x",ufo_piv) dxPositionEntity ufo,0,0,10 ; Create texture with dxColor + cubic environment map + store in vram flags tex=dxCreateTexture(256,256,1+128+256) ; Apply cubic environment map to teapot dxEntityTexture teapot,tex While Not dxKeyDown(1) ; Control camera ; mouse look mxs#=mxs#+(dxMouseXSpeed()/5.0) mys#=mys#+(dxMouseYSpeed()/5.0) dxRotateEntity cam,mys#,-mxs#,0 dxMoveMouse width/2,height/2 ; move camera forwards/backwards/left/right with cursor keys If dxKeyDown(200)=True Then dxMoveEntity cam,0,0,.2 ; move camera forward If dxKeyDown(208)=True Then dxMoveEntity cam,0,0,-.2 ; move camera back If dxKeyDown(205)=True Then dxMoveEntity cam,.2,0,0 ; move camera left If dxKeyDown(203)=True Then dxMoveEntity cam,-.2,0,0 ; move camera right ; Turn ufo pivot, causing child ufo mesh to spin around it (and teapot) dxTurnEntity ufo_piv,0,2,0 ; Hide our main camera before updating cube map - we don't need it to be rendererd every time cube_cam is rendered dxHideEntity cam ; Update cubemap UpdateCubemap(tex,cube_cam,teapot) ; Show main camera again dxShowEntity cam dxRenderWorld dxText 0,0,"Use mouse to look around" dxText 0,20,"Use cursor keys to change camera position" dxFlip Wend Function UpdateCubemap(tex,camera,entity) tex_sz=dxTextureWidth(tex) ; Show the camera we have specifically created for updating the cubemap dxShowEntity camera ; Hide entity that will have cubemap applied to it. This is so we can get cubemap from its position, without it blocking the view dxHideEntity entity ; Position camera where the entity is - this is where we will be rendering views from for cubemap dxPositionEntity camera,dxEntityX#(entity),dxEntityY#(entity),dxEntityZ#(entity) dxCameraClsMode camera,False,True ; Set the camera's viewport so it is the same size as our texture - so we can fit entire screen contents into texture dxCameraViewport camera,0,0,tex_sz,tex_sz ; Update cubemap ; do left view dxSetCubeFace tex,0 dxRotateEntity camera,0,90,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; do forward view dxSetCubeFace tex,1 dxRotateEntity camera,0,0,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; do right view dxSetCubeFace tex,2 dxRotateEntity camera,0,-90,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; do backward view dxSetCubeFace tex,3 dxRotateEntity camera,0,180,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; do up view dxSetCubeFace tex,4 dxRotateEntity camera,-90,0,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; do down view dxSetCubeFace tex,5 dxRotateEntity camera,90,0,0 dxRenderWorld dxCopyRect 0,0,tex_sz,tex_sz,0,0,dxBackBuffer(),dxTextureBuffer(tex) ; Show entity again dxShowEntity entity ; Hide the cubemap camera dxHideEntity camera End Function