Skip to content

Latest commit

 

History

History
95 lines (65 loc) · 2.73 KB

README.md

File metadata and controls

95 lines (65 loc) · 2.73 KB

EN | RU

< Back Index Next >
Not available Tutorials 02. Mouse

01. Background color

In this tutorial we start education by learning to set background color.

Estimated completion time: 5 minutes.

Table of contents

Here's the line of code to set background color to red:

main.application.camera.clearColor = {1, 0, 0}

Run in ogse

Note: either paste this code yourself to ogse, or simply click Run in ogse.

Let's see into API we used:

  • main namespace hosts application instance
  • main.application instance hosts subsystems like camera, mouse, etc.
  • main.application.camera instance is a viewport into application's scene
  • main.application.camera.clearColor property is a clearing color (effectively background color) of the camera
    • accepts array of color components in RGB format
      main.application.camera.clearColor = {1, 0, 0}
    • returns array of color components in RGB format
      local color = main.application.camera.clearColor
      print("background color:", color[1], color[2], color[3])

It was fairly easy to set background color, right? Now let's find out what color is used by default:

local color = main.application.camera.clearColor
print("Default background color:", color[1], color[2], color[3])

Run in ogse

Notes:

  • local keyword means that declared variable is local to current scope and will be garbage collected upon the scope's exit
  • Lua indexes arrays starting from 1, unlike C that does so from 0

Have a look at the debug console. You should see the following line:

Default background color:  0.200000    0.200000    0.400000

Thus, default background color is 0.2, 0.2, 0.4. Why that specific color, you ask? Because 0.2, 0.2, 0.4 is default background color of OpenSceneGraph used by ogs.

You have successfully set background color to red and then printed default background color.

< Back Index Next >
Not available Tutorials 02. Mouse