aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-05-03 14:12:44 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-05-03 14:12:44 +0100
commit232035b7e24d2a49a472c28b326f2227af11963d (patch)
treec28ab15c7117b7eff45a61faf12734c363b5f944
parenta1e93038af0a739b9af57bd40ffbee6963dc3242 (diff)
downloadfaqe-232035b7e24d2a49a472c28b326f2227af11963d.tar.gz
faqe-232035b7e24d2a49a472c28b326f2227af11963d.tar.xz
faqe-232035b7e24d2a49a472c28b326f2227af11963d.zip
Animate the light position around the cube
-rw-r--r--faqe.c9
-rw-r--r--vert.glsl3
2 files changed, 9 insertions, 3 deletions
diff --git a/faqe.c b/faqe.c
index 3b81e24..e51aaf0 100644
--- a/faqe.c
+++ b/faqe.c
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
SDL_GLContext *glc;
GLuint prog;
struct {
- GLint model, view, proj, tex;
+ GLint model, view, proj, tex, light;
} uni;
FILE *cube_file;
struct fmd cube_fmd;
@@ -46,6 +46,7 @@ int main(int argc, char **argv)
struct {
bool w, a, s, d, spc, lct;
} key = { 0 };
+ vec4 lipos;
float tlast;
setprogname(argc >= 1 && argv[0] != NULL ? argv[0] : "faqe");
@@ -91,6 +92,7 @@ int main(int argc, char **argv)
{ "view", &uni.view },
{ "proj", &uni.proj },
{ "tex", &uni.tex },
+ { "light", &uni.light },
{ 0 },
});
@@ -164,6 +166,10 @@ int main(int argc, char **argv)
camera_lookat(view, &cam);
+ lipos[0] = 3.0 * cosf(tnow / 10) * cosf(tnow / 20);
+ lipos[1] = 3.0 * sinf(tnow / 10);
+ lipos[2] = 3.0 * cosf(tnow / 10) * sinf(tnow / 20);
+
gl_clearcolor(0.2, 0.3, 0.3, 1.0);
gl_clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mat4x4_identity(model);
@@ -171,6 +177,7 @@ int main(int argc, char **argv)
gl_prog_use(prog);
gl_uni_setm4fv(uni.view, 1, GL_FALSE, view[0]);
gl_uni_setm4fv(uni.model, 1, GL_FALSE, model[0]);
+ gl_uni_set3fv(uni.light, 1, lipos);
model_render(&cube_model);
gl_va_bind(0);
diff --git a/vert.glsl b/vert.glsl
index 9fea064..19469a4 100644
--- a/vert.glsl
+++ b/vert.glsl
@@ -15,11 +15,10 @@ out vec3 lipos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
+uniform vec3 light;
void main()
{
- vec3 light = vec3(1.2, 1.0, 2.0);
-
gl_Position = proj * view * model * vec4(pos, 1.0);
fpos = vec3(view * model * vec4(pos, 1.0));
fuv = uv;