diff options
author | iurii <[email protected]> | 2024-08-31 21:27:54 +0200 |
---|---|---|
committer | iurii <[email protected]> | 2024-08-31 21:27:54 +0200 |
commit | 1e34058ac8c5929e9dedb544b9a1c84a6c13435a (patch) | |
tree | b7ecd2d3076f732ccafa186f7caa701d9b770def /src | |
parent | 0be81b1387f010bb00e1ea34ff66561fa67cedef (diff) | |
download | funhalla-1e34058ac8c5929e9dedb544b9a1c84a6c13435a.tar.gz |
phong shader model
Diffstat (limited to '')
-rw-r--r-- | src/main.odin | 261 | ||||
-rw-r--r-- | src/shader/shader.odin | 6 |
2 files changed, 220 insertions, 47 deletions
diff --git a/src/main.odin b/src/main.odin index f09ccb4..bb4803e 100644 --- a/src/main.odin +++ b/src/main.odin @@ -139,47 +139,222 @@ main :: proc() { } vertices: []f32 = { - -0.5, -0.5, -0.5, 0.0, 0.0, -1.0, - 0.5, -0.5, -0.5, 0.0, 0.0, -1.0, - 0.5, 0.5, -0.5, 0.0, 0.0, -1.0, - 0.5, 0.5, -0.5, 0.0, 0.0, -1.0, - -0.5, 0.5, -0.5, 0.0, 0.0, -1.0, - -0.5, -0.5, -0.5, 0.0, 0.0, -1.0, - - -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, - 0.5, -0.5, 0.5, 0.0, 0.0, 1.0, - 0.5, 0.5, 0.5, 0.0, 0.0, 1.0, - 0.5, 0.5, 0.5, 0.0, 0.0, 1.0, - -0.5, 0.5, 0.5, 0.0, 0.0, 1.0, - -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, - - -0.5, 0.5, 0.5, -1.0, 0.0, 0.0, - -0.5, 0.5, -0.5, -1.0, 0.0, 0.0, - -0.5, -0.5, -0.5, -1.0, 0.0, 0.0, - -0.5, -0.5, -0.5, -1.0, 0.0, 0.0, - -0.5, -0.5, 0.5, -1.0, 0.0, 0.0, - -0.5, 0.5, 0.5, -1.0, 0.0, 0.0, - - 0.5, 0.5, 0.5, 1.0, 0.0, 0.0, - 0.5, 0.5, -0.5, 1.0, 0.0, 0.0, - 0.5, -0.5, -0.5, 1.0, 0.0, 0.0, - 0.5, -0.5, -0.5, 1.0, 0.0, 0.0, - 0.5, -0.5, 0.5, 1.0, 0.0, 0.0, - 0.5, 0.5, 0.5, 1.0, 0.0, 0.0, - - -0.5, -0.5, -0.5, 0.0, -1.0, 0.0, - 0.5, -0.5, -0.5, 0.0, -1.0, 0.0, - 0.5, -0.5, 0.5, 0.0, -1.0, 0.0, - 0.5, -0.5, 0.5, 0.0, -1.0, 0.0, - -0.5, -0.5, 0.5, 0.0, -1.0, 0.0, - -0.5, -0.5, -0.5, 0.0, -1.0, 0.0, - - -0.5, 0.5, -0.5, 0.0, 1.0, 0.0, - 0.5, 0.5, -0.5, 0.0, 1.0, 0.0, - 0.5, 0.5, 0.5, 0.0, 1.0, 0.0, - 0.5, 0.5, 0.5, 0.0, 1.0, 0.0, - -0.5, 0.5, 0.5, 0.0, 1.0, 0.0, - -0.5, 0.5, -0.5, 0.0, 1.0, 0.0 + -0.5, + -0.5, + -0.5, + 0.0, + 0.0, + -1.0, + 0.5, + -0.5, + -0.5, + 0.0, + 0.0, + -1.0, + 0.5, + 0.5, + -0.5, + 0.0, + 0.0, + -1.0, + 0.5, + 0.5, + -0.5, + 0.0, + 0.0, + -1.0, + -0.5, + 0.5, + -0.5, + 0.0, + 0.0, + -1.0, + -0.5, + -0.5, + -0.5, + 0.0, + 0.0, + -1.0, + -0.5, + -0.5, + 0.5, + 0.0, + 0.0, + 1.0, + 0.5, + -0.5, + 0.5, + 0.0, + 0.0, + 1.0, + 0.5, + 0.5, + 0.5, + 0.0, + 0.0, + 1.0, + 0.5, + 0.5, + 0.5, + 0.0, + 0.0, + 1.0, + -0.5, + 0.5, + 0.5, + 0.0, + 0.0, + 1.0, + -0.5, + -0.5, + 0.5, + 0.0, + 0.0, + 1.0, + -0.5, + 0.5, + 0.5, + -1.0, + 0.0, + 0.0, + -0.5, + 0.5, + -0.5, + -1.0, + 0.0, + 0.0, + -0.5, + -0.5, + -0.5, + -1.0, + 0.0, + 0.0, + -0.5, + -0.5, + -0.5, + -1.0, + 0.0, + 0.0, + -0.5, + -0.5, + 0.5, + -1.0, + 0.0, + 0.0, + -0.5, + 0.5, + 0.5, + -1.0, + 0.0, + 0.0, + 0.5, + 0.5, + 0.5, + 1.0, + 0.0, + 0.0, + 0.5, + 0.5, + -0.5, + 1.0, + 0.0, + 0.0, + 0.5, + -0.5, + -0.5, + 1.0, + 0.0, + 0.0, + 0.5, + -0.5, + -0.5, + 1.0, + 0.0, + 0.0, + 0.5, + -0.5, + 0.5, + 1.0, + 0.0, + 0.0, + 0.5, + 0.5, + 0.5, + 1.0, + 0.0, + 0.0, + -0.5, + -0.5, + -0.5, + 0.0, + -1.0, + 0.0, + 0.5, + -0.5, + -0.5, + 0.0, + -1.0, + 0.0, + 0.5, + -0.5, + 0.5, + 0.0, + -1.0, + 0.0, + 0.5, + -0.5, + 0.5, + 0.0, + -1.0, + 0.0, + -0.5, + -0.5, + 0.5, + 0.0, + -1.0, + 0.0, + -0.5, + -0.5, + -0.5, + 0.0, + -1.0, + 0.0, + -0.5, + 0.5, + -0.5, + 0.0, + 1.0, + 0.0, + 0.5, + 0.5, + -0.5, + 0.0, + 1.0, + 0.0, + 0.5, + 0.5, + 0.5, + 0.0, + 1.0, + 0.0, + 0.5, + 0.5, + 0.5, + 0.0, + 1.0, + 0.0, + -0.5, + 0.5, + 0.5, + 0.0, + 1.0, + 0.0, + -0.5, + 0.5, + -0.5, + 0.0, + 1.0, + 0.0, } @@ -194,7 +369,7 @@ main :: proc() { gl.STATIC_DRAW, ) - gl.GenVertexArrays(1, &cube_vao) + gl.GenVertexArrays(1, &cube_vao) gl.BindVertexArray(cube_vao) gl.VertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 6 * size_of(f32), 0) gl.EnableVertexAttribArray(0) @@ -227,7 +402,7 @@ main :: proc() { light_color := Vec3{1.0, 1.0, 1.0} shader.set_vec3(lighting_shader, cstring("object_color"), &object_color) shader.set_vec3(lighting_shader, cstring("light_color"), &light_color) - shader.set_vec3(lighting_shader, cstring("light_position"), &light_pos) + shader.set_vec3(lighting_shader, cstring("light_position"), &light_pos) aspect: f32 = 800.0 / 600.0 projection := linalg.matrix4_perspective_f32( diff --git a/src/shader/shader.odin b/src/shader/shader.odin index cd798ff..720efde 100644 --- a/src/shader/shader.odin +++ b/src/shader/shader.odin @@ -1,7 +1,6 @@ package shader import "core:math/linalg" -import "core:os" import "core:strings" import gl "vendor:OpenGL" @@ -16,9 +15,6 @@ Vec3 :: linalg.Vector3f32 Mat4 :: linalg.Matrix4x4f32 shader_init :: proc(vsp, fsp: string) -> (^Shader, int) { - assert(os.is_file_path(vsp)) - assert(os.is_file_path(fsp)) - program_id, ok := gl.load_shaders_file(vsp, fsp) if !ok { @@ -58,5 +54,7 @@ set_mat4 :: proc(using shader: ^Shader, name: cstring, value: ^Mat4) { set_value :: proc { set_i32, set_f32, + set_vec3, + set_mat4, set_bool, } |