3. Basic Game Loop and Window Setup
Let's dive straight in and create a basic game loop.
// src/main.odin
package main
import rl "core:raylib"
main :: proc() {
// a lot of stuff happens behind the scenes in this single call
// - a graphics API context is created (usually OpenGL)
// - input handling is set up
// - default shaders are created
// - a window is requested from the operating system
rl.InitWindow(640, 360, "Program Video Games!")
// this loop repeats until we press Esc or close the window
for !rl.WindowShouldClose() {
// begin drawing gets Raylib read to receive draw calls
rl.BeginDrawing()
// clear background makes sure to wipe everything with on solid colour
// if we don't do this, what was drawn last frame will stay there
// and we get a "smearing" effect from moving objects
rl.ClearBackground(rl.BLACK)
// when we are done calling our drawing procedures we signal that by
// calling this procedure
rl.EndDrawing()
}
}
The code is exactly the same as what was shown in the introduction, just with the comments to explain it.
We'll go more in-depth into different aspects of a game loop later.
For now, it's enough to get up and running.