Creating a 3D scene
In this guide, you will create a 3D camera, add lighting, and render your first cube.
Requirements
Section titled “Requirements”Before starting:
- CC:Tweaked installed
- DirectGPU installed
- A DirectGPU display
Creating a display
Section titled “Creating a display”local gpu = peripheral.find("directgpu")
local displayId = gpu.autoDetectAndCreateDisplay()Setting up the camera
Section titled “Setting up the camera”Before rendering 3D objects, initialize the camera using setupCamera.
gpu.setupCamera( displayId, 60, 0.1, 1000)Move the camera:
gpu.setCameraPosition( displayId, 0, 2, 5)Look at the scene:
gpu.lookAt( displayId, 0, 0, 0)Adding lighting
Section titled “Adding lighting”A scene without lights will appear dark.
Add ambient light:
gpu.addAmbientLight( displayId, 50, 50, 50, 0.5)Add a directional light:
gpu.addDirectionalLight( displayId, 0, -1, 0, 255, 255, 255, 1)Drawing a cube
Section titled “Drawing a cube”Now draw a cube:
gpu.drawCube( displayId, 0, 0, 0, 2, 0, 45, 0, 255, 100, 100)Finally update:
gpu.updateDisplay(displayId)You now have a basic 3D scene.