chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
http://www.raylib.com/
zlib License
851 stars 74 forks source link

Incorrect Namespacing in Camera2DDemo Example and probably others #241

Closed r-odriguez closed 6 months ago

r-odriguez commented 6 months ago

Issue description

After creating a blank project using dotnet new console and adding Raylib-cs with dotnet add package Raylib-cs, the code sample provided here doesn't work out of the box which I imagine that it should (I could be wrong and please point out if I am. I'm new to C# and I don't really know how things work just yet)

Environment and other useful information

Reproducing errors

mkdir test/
cd test/
dotnet new console
dotnet add package Raylib-cs

copy code from Examples/Core/Camera2dDemo.cs into the generated Program.cs. Run:

dotnet run

Expected output

INFO: Initializing raylib 5.0
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 1920 x 1080
INFO:     > Screen size:  800 x 450
INFO:     > Render size:  800 x 450
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 230
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Intel
INFO:     > Renderer: Mesa Intel(R) UHD Graphics (TGL GT2)
INFO:     > Version:  4.6 (Core Profile) Mesa 24.0.7-arch1.3
INFO:     > GLSL:     4.60
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
INFO: Window closed successfully

Actual output and errors

/path/to/project/Program.cs(30,9): error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(31,9): error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(31,37): error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(32,9): error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(32,35): error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(45,34): error CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(53,9): error CS0246: The type or namespace name 'Camera2D' could not be found (are you missing a using directive or an assembly reference?) [/path/to/project/temp.csproj]
/path/to/project/Program.cs(69,27): error CS0103: The name 'KeyboardKey' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(73,32): error CS0103: The name 'KeyboardKey' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(82,27): error CS0103: The name 'KeyboardKey' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(86,32): error CS0103: The name 'KeyboardKey' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(114,30): error CS0103: The name 'KeyboardKey' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(124,29): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(128,52): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(135,38): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(137,83): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(143,17): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(148,50): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(150,54): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(151,60): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(152,79): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(153,74): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(155,56): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(156,50): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(158,62): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(159,65): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(160,66): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(161,55): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]
/path/to/project/Program.cs(162,69): error CS0103: The name 'Color' does not exist in the current context [/path/to/project/temp.csproj]

The build failed. Fix the build errors and run again.

Temporary fix

I managed to make it work by changing using static Raylib_cs.Raylib to using Raylib_cs and adding Raylib. at the beginning of some types. Not all of them needed tho, Rectangle, Camera2D and Color are examples that only worked without the namespace.

r-odriguez commented 6 months ago

After reading some old closed issues I found that by adding using Raylib_cs on top of using static Raylib_cs.Raylib fixed too.

chrisdill commented 6 months ago

@i3elj Yeah it needs using Raylib_cs which the examples currently sets in Examples.csproj as a global using so each example doesn't need to specify it to have access to the namespace.