Skip to content

Commit da04098

Browse files
authored
Camera updates (#499)
* Misc info * Update camera information * Review fixes
1 parent ee88cf0 commit da04098

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

docs/en/manuals/camera.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,32 @@ You can tell the render script to use the projection provided by the camera by s
132132
msg.post("@render:", "use_camera_projection")
133133
```
134134

135-
Alternatively, you can set a specific camera that should be used for rendering in a render script:
135+
### Render script
136+
137+
Starting with Defold 1.9.6, when using the default render script Defold will automatically set the last enabled camera that should be used for rendering. Before this change, a script somewhere in the project needed to explicitly send the `use_camera_projection` message to the renderer to notify it that the view and projection from camera components should be used. This is no longer necesessary, but it is still possible to do so for backwards compatability purposes.
138+
139+
Alternatively, you can set a specific camera that should be used for rendering in a render script. This could be useful in cases where you need to control more specifically which camera should be used for rendering, for example in a multiplayer game.
136140

137141
```lua
138142
-- render.set_camera will automatically use the view and projection matrices
139143
-- for any rendering happening until render.set_camera() is called.
140144
render.set_camera("main:/my_go#camera")
141145
```
142146

147+
To check if a camera is active or not, you can use the `get_enabled` function from the [Camera API](https://defold.com/ref/alpha/camera/#camera.get_enabled:camera):
148+
149+
```lua
150+
if camera.get_enabled("main:/my_go#camera") then
151+
-- camera is enabled, use it for rendering!
152+
render.set_camera("main:/my_go#camera")
153+
end
154+
```
155+
156+
::: sidenote
157+
To use the `set_camera` function together with frustum culling, you need to pass this as an option to the function:
158+
`render.set_camera("main:/my_go#camera", {use_frustum = true})`
159+
:::
160+
143161
### Panning the camera
144162

145163
You pan/move the camera around the game world by moving the game object the camera component is attached to. The camera component will automatically send an updated view matrix based on the current x and y axis position of the camera.

docs/en/manuals/project-settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ The texture profiles file to use for this project, `/builtins/graphics/default.t
222222
Verify the return value after each graphics call and report any errors in the log.
223223

224224
#### OpenGL Version Hint
225-
OpenGL context version hint. If a specific version is selected, this will used as the minimum version required (does not apply to OpenGL ES). Defaults to OpenGL 3.3.
225+
OpenGL context version hint. If a specific version is selected, this will be used as the minimum version required (does not apply to OpenGL ES). Defaults to OpenGL 3.3.
226226

227227
#### OpenGL Core Profile Hint
228228
Set the 'core' OpenGL profile hint when creating the context. The core profile removes all deprecated features from OpenGL, such as immediate mode rendering. Does not apply to OpenGL ES. `true` by default.

docs/en/manuals/render.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ msg.post("@render:", "use_fixed_projection", { near = -1, far = 1, zoom = 2 })
135135

136136
### Camera projection
137137

138-
You can also use the projection provided by a [Camera component](/manuals/camera). You enable the camera projection by sending a message to the render script:
139-
140-
```lua
141-
msg.post("@render:", "use_camera_projection")
142-
```
143-
138+
When using the default render script and there are enabled [Camera components](/manuals/camera) available in the project, they will take precedence over any other view / projections set in the render script. To read more about how to work with camera components in render scripts, please consult the [Camera documentation](/manuals/camera).
144139

145140
## Frustum culling
146141

0 commit comments

Comments
 (0)