int win_width, win_height;
float win_aspect;
long time_msec;
+double time_sec;
Mat4 view_matrix;
static bool should_swap;
draw_backdrop();
app_swap_buffers();
+ app_redraw(); // since we added animation we need to redisplay even in non-VR mode
}
assert(glGetError() == GL_NO_ERROR);
}
extern int win_width, win_height;
extern float win_aspect;
extern long time_msec;
+extern double time_sec;
extern Mat4 view_matrix;
static Mesh *mesh_skydome;
static unsigned int sdr_skydome;
+static Vec3 grid_color;
+static int uloc_grid_color;
bool init_backdrop()
{
- Vec3 grid_color = color(1.0, 0.07, 1.0);
+ grid_color = color(1.0, 0.07, 1.0);
Vec3 mid_color = color(0.133, 0.006, 0.612);
Vec3 horiz_color = color(0.612, 0.006, 1.0);
Vec3 zenith_color = color(0.029, 0.029, 0.029);
if(!(sdr_grid = create_program_load("sdr/grid.v.glsl", "sdr/grid.p.glsl"))) {
return false;
}
+ uloc_grid_color = get_uniform_loc(sdr_grid, "grid_color");
set_uniform_float3(sdr_grid, "grid_color", grid_color.x, grid_color.y, grid_color.z);
set_uniform_float3(sdr_grid, "fog_color", fog_color.x, fog_color.y, fog_color.z);
glMultMatrixf(xform[0]);
bind_program(sdr_grid);
+ float pulse = 1.0 + sin(time_sec * 3.0) * 0.25;
+ glUniform3f(uloc_grid_color, grid_color.x * pulse, grid_color.y * pulse, grid_color.z * pulse);
bind_texture(tex_grid);
glBegin(GL_QUADS);
}
time_msec = app_get_msec();
+ time_sec = (double)time_msec / 1000.0;
while(SDL_PollEvent(&ev)) {
process_event(&ev);
if(quit) goto break_evloop;
} \
return loc == -1 ? -1 : 0
+int get_uniform_loc(unsigned int prog, const char *name)
+{
+ int loc, curr_prog;
+ glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog);
+ if((unsigned int)curr_prog != prog && bind_program(prog) == -1) {
+ return -1;
+ }
+ loc = glGetUniformLocation(prog, name);
+ if((unsigned int)curr_prog != prog) {
+ bind_program(curr_prog);
+ }
+ return loc;
+}
+
int set_uniform_int(unsigned int prog, const char *name, int val)
{
BEGIN_UNIFORM_CODE {
int link_program(unsigned int prog);
int bind_program(unsigned int prog);
+int get_uniform_loc(unsigned int prog, const char *name);
+
int set_uniform_int(unsigned int prog, const char *name, int val);
int set_uniform_float(unsigned int prog, const char *name, float val);
int set_uniform_float2(unsigned int prog, const char *name, float x, float y);