summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 15:01:54 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-17 15:01:54 +1100
commitc97327fcdcbe8b85d7718cfb722e1525986a8514 (patch)
tree9c0df938345bff356f8fcc97740afedb1f500b3d /examples
parent1afe4876cb8133c5b47fdcfeb07decc5565c4844 (diff)
parent51b4a3fc75351d6ecd2142c228d31a1f7ed52152 (diff)
Merge branch 'master' into transform-hierarchy
Diffstat (limited to 'examples')
-rw-r--r--examples/obj_loading/backpack_screenshot.pngbin0 -> 2404274 bytes
-rw-r--r--examples/obj_loading/ex_obj_loading.c39
2 files changed, 34 insertions, 5 deletions
diff --git a/examples/obj_loading/backpack_screenshot.png b/examples/obj_loading/backpack_screenshot.png
new file mode 100644
index 0000000..a16b1f2
--- /dev/null
+++ b/examples/obj_loading/backpack_screenshot.png
Binary files differ
diff --git a/examples/obj_loading/ex_obj_loading.c b/examples/obj_loading/ex_obj_loading.c
index bdadd7e..6e63938 100644
--- a/examples/obj_loading/ex_obj_loading.c
+++ b/examples/obj_loading/ex_obj_loading.c
@@ -1,4 +1,5 @@
#include <glfw3.h>
+#include <string.h>
#include "camera.h"
#include "core.h"
@@ -7,6 +8,14 @@
#include "render.h"
#include "render_types.h"
+const vec3 pointlight_positions[4] = {
+ { 0.7, 0.2, 2.0 },
+ { 2.3, -3.3, -4.0 },
+ { -4.0, 2.0, -12.0 },
+ { 0.0, 0.0, -3.0 },
+};
+point_light point_lights[4];
+
int main() {
core* core = core_bringup();
@@ -19,9 +28,29 @@ int main() {
// 2. upload vertex data to gpu
model_upload_meshes(&core->renderer, backpack);
// 3. create a camera
- vec3 camera_pos = vec3(3., 4., 10.);
+ vec3 camera_pos = vec3(3., 2., 10.);
vec3 camera_front = vec3_normalise(vec3_negate(camera_pos));
camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0));
+ // 4. create lights
+
+ // directional (sun) light setup
+ directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 },
+ .ambient = (vec3){ 0.2, 0.2, 0.2 },
+ .diffuse = (vec3){ 0.5, 0.5, 0.5 },
+ .specular = (vec3){ 1.0, 1.0, 1.0 } };
+ // point lights setup
+ for (int i = 0; i < 4; i++) {
+ point_lights[i].position = pointlight_positions[i];
+ point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 };
+ point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 };
+ point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 };
+ point_lights[i].constant = 1.0;
+ point_lights[i].linear = 0.09;
+ point_lights[i].quadratic = 0.032;
+ }
+
+ scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 };
+ memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4]));
// --- Enter Main loop
while (!glfwWindowShouldClose(core->renderer.window)) {
@@ -30,10 +59,10 @@ int main() {
render_frame_begin(&core->renderer);
- // Draw the cube
- transform cube_tf =
- transform_create(VEC3_ZERO, quat_ident(), 2.0); // make the backpack a bit bigger
- draw_model(&core->renderer, &cam, backpack, cube_tf);
+ // Draw the backpack
+ transform model_tf = transform_create(vec3(0.0, -0.4, 0.0), quat_ident(),
+ 1.8); // make the backpack a bit bigger
+ draw_model(&core->renderer, &cam, backpack, model_tf, &our_scene);
render_frame_end(&core->renderer);
}