@@ -18,6 +18,7 @@ struct Vertex {
18
18
enum UniformSlot {
19
19
UniformSlot_Time,
20
20
UniformSlot_Resolution,
21
+ UniformSlot_MousePosition,
21
22
UniformSlot__Count,
22
23
};
23
24
@@ -50,6 +51,7 @@ struct Render {
50
51
51
52
f32 time;
52
53
Vec2f resolution;
54
+ Vec2f mouse_position;
53
55
};
54
56
55
57
static int compile_shader_source (StringView, GLenum type);
@@ -149,6 +151,12 @@ void render_set_resolution(Render* render, Vec2f resolution)
149
151
}
150
152
}
151
153
154
+ void render_set_mouse_position (Render* render, Vec2f position)
155
+ {
156
+ render->mouse_position = position;
157
+ glUniform2f (render->uniforms [UniformSlot_MousePosition], position.x , position.y );
158
+ }
159
+
152
160
int render_reload_shaders (Render* render)
153
161
{
154
162
auto vert = render->bundle ->open (" Shaders/simple.vert" );
@@ -186,6 +194,7 @@ void render_use_simple(Render* render)
186
194
glUseProgram (render->programs [Shader_Color]);
187
195
uniform_location (render->programs [Shader_Color], render->uniforms );
188
196
glUniform2f (render->uniforms [UniformSlot_Resolution], render->resolution .x , render->resolution .y );
197
+ glUniform2f (render->uniforms [UniformSlot_MousePosition], render->mouse_position .x , render->mouse_position .y );
189
198
glUniform1f (render->uniforms [UniformSlot_Time], render->time );
190
199
}
191
200
@@ -283,7 +292,7 @@ struct UniformDef {
283
292
const char *name;
284
293
};
285
294
286
- static_assert (UniformSlot__Count == 2 , " The amount of the shader uniforms have change. Please update the definition table accordingly" );
295
+ static_assert (UniformSlot__Count == 3 , " The amount of the shader uniforms have change. Please update the definition table accordingly" );
287
296
static const UniformDef uniform_defs[UniformSlot__Count] = {
288
297
[UniformSlot_Time] = {
289
298
.slot = UniformSlot_Time,
@@ -293,6 +302,10 @@ static const UniformDef uniform_defs[UniformSlot__Count] = {
293
302
.slot = UniformSlot_Resolution,
294
303
.name = " resolution" ,
295
304
},
305
+ [UniformSlot_MousePosition] = {
306
+ .slot = UniformSlot_MousePosition,
307
+ .name = " mouse_position" ,
308
+ },
296
309
};
297
310
298
311
0 commit comments