Skip to content

Conversation

RobinsAviary
Copy link

Ported core_3d_camera_mode.c, core_input_keys.c, core_input_mouse.c, core_input_mouse_wheel.c, core_window_should_close.c, and examples_template.c from the official raylib examples to Odin.

Checklist before submitting:

  • This example has been added to .github/workflows/check.yml (for automatic testing)
  • This example compiles cleanly with flags -vet -strict-style -vet-tabs -disallow-do -warnings-as-errors
  • This example follows the core naming convention: https://github.com/odin-lang/Odin/wiki/Naming-Convention (exception can be made for ports of examples that need to match 1:1 to the original source).
  • By submitting, I understand that this example is made available under these licenses: Public Domain and Odin's BSD-3 license. Only for third-party dependencies are other licenses allowed.

@RobinsAviary
Copy link
Author

Ported core_world_screen.c and core_3d_camera_free.c, as well.

Copy link
Collaborator

@karl-zylinski karl-zylinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there. Thanks for the PR!

I put in some comments. Most of them are about general things rather than one-off specifics. For each comment, please consider other places in the other files where the same thing may happen.

I know these are ports, but I still think it is a good idea to showcase small ways in which Odin is different from C. Therefore some of the things I commented on are in the realm of "not possible in C, but easily possible in Odin, so it's a good idea to do it in these ports".

Also, sorry if some of these things are not specified by the PR checklist. I'll try to add in more specific style guide things there.

circles[i].color = colors[rl.GetRandomValue(0, 13)]
}

music: rl.Music = rl.LoadMusicStream("resources/mini1111.xm")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style:
Use type inference when possible. I.e. music := rl.LoadMusicStream("resources/mini1111.xm")

(please fix this and all other occurrences in the PR)

rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - 3d camera free")

// Define the camera to look into our 3d world
camera: rl.Camera3D
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use initializer when possible.

I.e.

camera := rl.Camera3D {
	position = {10, 10, 10}, // Camera position
	// etc
}

Please fix this and other occurances

camera.fovy = 45 // Camera field-of-view Y
camera.projection = .PERSPECTIVE // Camera projection type

cube_position: rl.Vector3 = {0, 0, 0}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for zero init. Just do cube_position: rl.Vector3

//--------------------------------------------------------------------------------------

// Main game loop
for (!rl.WindowShouldClose()) { // Detect window close button or ESC key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra parens here and in some other places.


rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - input mouse")

ball_position: rl.Vector2 = { -100, -100 }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever you need to specify both type and value, then please do like this:

ball_position := rl.Vector2 { -100, -100 }

// Draw our render texture with rotation applied
// NOTE: We set the origin of the texture to the center of the render texture
rl.DrawTexturePro(target.texture,
{0, 0, f32(target.texture.width), f32(-target.texture.height)},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably throw out the width and height to two f32 variables and only do the cast once that way.


rl.SetExitKey(.KEY_NULL) // Disable KEY_ESCAPE to close window, X-button still works

exit_window_requested: bool = false // Flag to request window to exit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit_window_requested := false or exit_window_requested: bool

}

// Update bunnies
bunniesSize: uint = len(bunnies)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • remove bunnies_count
  • This variable doesn't use the correct naming convention, but also, it is not necessary:
  • The loop below can just be for &bunny in bunnies {}

@karl-zylinski
Copy link
Collaborator

Also, I made a new wiki page that has both some naming conventions + style conventions: https://github.com/odin-lang/examples/wiki/Naming-and-style-convention (new PRs will link to this page instead of the old naming convention page). I'll add to that document as I run into common mistakes!

@RobinsAviary
Copy link
Author

Also, I made a new wiki page that has both some naming conventions + style conventions: https://github.com/odin-lang/examples/wiki/Naming-and-style-convention (new PRs will link to this page instead of the old naming convention page). I'll add to that document as I run into common mistakes!

Awesome, thanks! I'm working on all the changes right now.

@karl-zylinski
Copy link
Collaborator

karl-zylinski commented Oct 3, 2025

I wanted to see why it looped backwards in audio_module_playing.odin, so I experimented. Since I was happy with how it worked, I pushed the changes as well. Just letting you know; don't want it to look like I was "taking over". Carry on! :) Let me know when this is ready for a second review

SCREEN_HEIGHT :: 450

rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - music stream")
defer rl.CloseWindow() // Close window and OpenGL context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think moving the cleanup with defer is useful.

My take on this is: Only use defer when you can leave a scope in many ways, so you are sure that the cleanup happens. Don't use it when there is a single way to leave the scope. Using defer has a cost: It makes the code harder to read, as it no longer happens in the order it is stated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants