Commit 8cdf67f674be6b49bad19dbe8e728dedff64bd59

Thomas de Grivel 2024-02-06T20:06:08

fix opacity

diff --git a/libc3/window/sdl2/demo/earth.c b/libc3/window/sdl2/demo/earth.c
index b60c791..a4044d8 100644
--- a/libc3/window/sdl2/demo/earth.c
+++ b/libc3/window/sdl2/demo/earth.c
@@ -66,7 +66,6 @@ bool earth_render (s_sequence *seq)
   f64         *camera_rot_x_speed;
   s_map *map;
   s_gl_sphere *sphere;
-  //f64 sphere_radius;
   s_window_sdl2 *window;
   assert(seq);
   window = seq->window;
@@ -100,46 +99,19 @@ bool earth_render (s_sequence *seq)
   assert(glGetError() == GL_NO_ERROR);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   assert(glGetError() == GL_NO_ERROR);
-  //glEnable(GL_LIGHTING);
   assert(glGetError() == GL_NO_ERROR);
-  //glEnable(GL_LIGHT0);
   assert(glGetError() == GL_NO_ERROR);
-  //f32 ambiant[4] = {0.1f, 0.1f, 0.1f, 1.0f};
-  //glLightfv(GL_LIGHT0, GL_AMBIENT, ambiant);
-  //f32 diffuse[4] = {1.0f, 0.92f, 0.83f, 1.0f};
-  //glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
-  //glLightfv(GL_LIGHT0, GL_SPECULAR, diffuse);
-  //f32 position[4] = {-1000.0, 0.0, 0.0, 1.0};
-  //glLightfv(GL_LIGHT0, GL_POSITION, position);
-  //glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1f);
-  //glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
-  //glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f);
   assert(glGetError() == GL_NO_ERROR);
   glEnable(GL_DEPTH_TEST);
   assert(glGetError() == GL_NO_ERROR);
-  //glPushMatrix();
-  {
-    assert(glGetError() == GL_NO_ERROR);
-    assert(glGetError() == GL_NO_ERROR);
-    //glEnable(GL_TEXTURE_2D);
-    assert(glGetError() == GL_NO_ERROR);
-    gl_camera_bind_texture(camera,
-                           gl_sprite_texture(&g_sprite_earth, 0));
-    assert(glGetError() == GL_NO_ERROR);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-                    GL_LINEAR_MIPMAP_LINEAR);
-    assert(glGetError() == GL_NO_ERROR);
-    gl_sphere_render(sphere);
-    /*
-    glDisable(GL_TEXTURE_2D);
-    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
-    gl_sphere_render_wireframe(sphere);
-    */
-  } // glPopMatrix();
-  //glDisable(GL_TEXTURE_2D);
+  gl_camera_bind_texture(camera,
+                         gl_sprite_texture(&g_sprite_earth, 0));
+  assert(glGetError() == GL_NO_ERROR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+                  GL_LINEAR_MIPMAP_LINEAR);
+  assert(glGetError() == GL_NO_ERROR);
+  gl_sphere_render(sphere);
   glDisable(GL_DEPTH_TEST);
-  //glDisable(GL_LIGHT0);
-  //glDisable(GL_LIGHTING);
   return true;
 }
 
diff --git a/libc3/window/sdl2/gl_camera.c b/libc3/window/sdl2/gl_camera.c
index 8031f71..e48e197 100644
--- a/libc3/window/sdl2/gl_camera.c
+++ b/libc3/window/sdl2/gl_camera.c
@@ -72,7 +72,7 @@ static const char * g_gl_camera_fragment_shader_src =
   "  return f0 + (1 - f0) * pow(1.0 - lDotH, 5);\n"
   "}\n"
   "vec4 microfacetModel (int lightIdx, vec3 pos, vec3 n, vec4 color) {\n"
-  "  vec4 diffuseBrdf = vec4(0.0);  // Metallic\n"
+  "  vec4 diffuseBrdf = vec4(0.0, 0.0, 0.0, 1.0);  // Metallic\n"
   "  if (! uMaterial.Metal) {\n"
   "    diffuseBrdf = color;\n"
   "  }\n"
@@ -176,7 +176,7 @@ s_gl_camera * gl_camera_init (s_gl_camera *camera, uw w, uw h)
   camera->rotation.z = 0.0f;
   camera->light_count = 1;
   camera->light_pos[0] = (s_vec3) {-100, 0, 0};
-  camera->light_color[0] = (s_rgb) {10, 10, 10};
+  camera->light_color[0] = (s_rgb) {1, 1, 1};
   vertex_shader = glCreateShader(GL_VERTEX_SHADER);
   glShaderSource(vertex_shader, 1, &g_gl_camera_vertex_shader_src,
                  NULL);
@@ -261,8 +261,8 @@ void gl_camera_render (s_gl_camera *camera)
   assert(glGetError() == GL_NO_ERROR);
   mat4_init_identity(&camera->projection_matrix);
   mat4_perspective(&camera->projection_matrix, camera->fov_y,
-                           camera->aspect_ratio, camera->clip_z_near,
-                           camera->clip_z_far);
+                   camera->aspect_ratio, camera->clip_z_near,
+                   camera->clip_z_far);
   mat4_init_identity(&camera->view_matrix);
   mat4_translate(&camera->view_matrix, camera->position.x,
                  camera->position.y, camera->position.z);
@@ -273,8 +273,7 @@ void gl_camera_render (s_gl_camera *camera)
   mat4_rotate_axis(&camera->view_matrix, camera->rotation.z,
                    &(s_vec3) { 0.0f, 0.0f, 1.0f });
   mat4_init_identity(&camera->model_matrix);
-  mat4_init_identity(&matrix);
-  mat4_mult_mat4(&camera->view_matrix, &matrix, &matrix);
+  mat4_init_copy(&matrix, &camera->view_matrix);
   mat4_mult_mat4(&camera->projection_matrix, &matrix, &matrix);
   for (int i = 0; i < camera->light_count; i++)
     mat4_mult_vec3(&matrix, camera->light_pos + i,