Implement Utah teapot model loading
This commit is contained in:
1 parent
f546f27a42
commit
620cf7606b
8 files changed
+303
-48
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "gpu.h"
|
||||
#include "model.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
@@ -8,17 +9,6 @@
|
||||
#define W 800
|
||||
#define H 600
|
||||
|
||||
static const vertex_t vertices[] = {
|
||||
{ { 0.000, 0.612, 0.000 }, { 1, 0, 0 } },
|
||||
{ { -0.500, -0.204, -0.289 }, { 0, 1, 0 } },
|
||||
{ { 0.500, -0.204, -0.289 }, { 0, 0, 1 } },
|
||||
{ { 0.000, -0.204, 0.577 }, { 1, 1, 1 } },
|
||||
};
|
||||
|
||||
static const uint16_t indices[] = {
|
||||
0, 3, 1, 0, 1, 2, 0, 2, 3, 3, 2, 1,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
@@ -54,8 +44,15 @@ key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Read model from passed path
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s PATH/TO/MODEL\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
model_t model = model_read(argv[1]);
|
||||
|
||||
// Set up window
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
@@ -70,18 +67,14 @@ int main()
|
||||
const gpu_config_t gpu_config = {
|
||||
.application_name = "Foo",
|
||||
.window = window,
|
||||
.vertex_data = vertices,
|
||||
.vertex_data_size = sizeof(vertices),
|
||||
.index_data = indices,
|
||||
.index_data_size = sizeof(indices),
|
||||
};
|
||||
gpu_ctx_t gpu;
|
||||
gpu_init(&gpu, &gpu_config);
|
||||
gpu_init(&gpu, &gpu_config, model);
|
||||
|
||||
const vec3_t cam = { 2, 2, -2 };
|
||||
const vec3_t tgt = { 0, 0, 0 };
|
||||
const vec3_t cam = { 0, 4, -4 };
|
||||
const vec3_t tgt = { 0, 0.5, 0 };
|
||||
mvp_t mvp = {
|
||||
.model = MAT4_SCALE(2),
|
||||
.model = MAT4_SCALE(0.667),
|
||||
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
|
||||
.proj = mat4_perspective((float)W / H, PI / 6, 0.1, 10.0),
|
||||
};
|
||||
@@ -110,6 +103,7 @@ int main()
|
||||
|
||||
// Clean up
|
||||
gpu_cleanup(&gpu);
|
||||
model_cleanup(&model);
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
|
||||
Reference in new issue
Block a user