www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - raylib-d Create Light Sources

reply jwatson-CO-edu <real.name colorado.edu> writes:
I am attempting to recreate the [Raylib flat shading 
tutorial](https://www.raylib.com/examples/shaders/loader.html?name=sha
ers_basic_lighting) with raylib-d.  I have been able to find most of the
necessary wrappers except the one the creates light sources. How do I create
light sources in raylib-d?

```d
uint MAX_LIGHTS = 4;
//...
Light[MAX_LIGHTS] lights; // Error: undefined identifier `Light`
lights[0] = CreateLight(
     LIGHT_POINT, Vector3( -2, 1, -2 ), Vector3Zero(), 
Colors.YELLOW, shader
);
lights[1] = CreateLight(
     LIGHT_POINT, Vector3( 2, 1, 2 ), Vector3Zero(), Colors.RED, 
shader
);
lights[2] = CreateLight(
     LIGHT_POINT, Vector3( -2, 1, 2 ), Vector3Zero(), 
Colors.GREEN, shader
);
lights[3] = CreateLight(
     LIGHT_POINT, Vector3( 2, 1, -2 ), Vector3Zero(), Colors.BLUE, 
shader
);
```
Nov 30 2022
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/30/22 7:56 PM, jwatson-CO-edu wrote:
 
 uint MAX_LIGHTS = 4;
This needs to be an `enum`.
 //...
 Light[MAX_LIGHTS] lights; // Error: undefined identifier `Light`
The rlights header file is not part of the raylib library, but is in the examples directory, you will need to port it. It's not very big, you probably can do it in a half hour. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/examples/shaders/rlights.h -Steve
Nov 30 2022
parent jwatson-CO-edu <real.name colorado.edu> writes:
On Thursday, 1 December 2022 at 01:17:16 UTC, Steven 
Schveighoffer wrote:
 On 11/30/22 7:56 PM, jwatson-CO-edu wrote:
 
 uint MAX_LIGHTS = 4;
The rlights header file is not part of the raylib library, but is in the examples directory, you will need to port it. It's not very big, you probably can do it in a half hour. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/examples/shaders/rlights.h -Steve
[This seems to work](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/06_gliderShade /source/rlights.d), in case anyone else wanted to do lighting in this way.
Dec 01 2022