12 #include "opengl/opengl.h"
13 #include "vulkan/vk.h"
15 /* static functions */
18 static void cleanup();
19 static void display();
22 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods);
23 static void motion_clbk(GLFWwindow *win, double x, double y);
24 static void mouse_clbk(GLFWwindow *win, int button, int action, int mods);
26 /* global variables */
36 // TODO: remove just for test:
39 int main(int argc, char **argv)
41 for(int i=0; i<argc; ++i) {
42 if(strcmp(argv[i], "-opengl") == 0) {
44 printf("Backend: OpenGL.\n");
46 else if(strcmp(argv[i], "-vulkan") == 0) {
48 printf("Backend: Vulkan.\n");
51 printf("No backend specified. Using OpenGL.\n");
56 fprintf(stderr, "Failed to initialize program.\n");
60 glfwSetKeyCallback(win, key_clbk);
61 glfwSetCursorPosCallback(win, motion_clbk);
62 glfwSetMouseButtonCallback(win, mouse_clbk);
64 while(!glfwWindowShouldClose(win)) {
86 camera = new Camera(25, 25, 4, 45);
88 if(!scene.load("data/spot/spot_control_mesh.obj")) {
89 fprintf(stderr, "Failed to load scene.\n");
93 for(size_t i=0; i<scene.objects.size(); ++i) {
94 printf("object: %d\n", (int)i);
95 printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
96 printf("material: %s\n", scene.objects[i]->material->name.c_str());
97 printf("transform:\n");
98 scene.objects[i]->transform.print();
103 static void cleanup()
115 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
117 if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
118 glfwSetWindowShouldClose(win, GLFW_TRUE);
122 static double prev_x, prev_y;
123 static int bnstate[8];
125 static void motion_clbk(GLFWwindow *win, double x, double y)
133 if(!dx && !dy) return;
136 camera->theta += dx * 0.5;
137 camera->phi += dy * 0.5;
139 if(camera->phi < -90) camera->phi = -90;
140 if(camera->phi > 90) camera->phi = 90;
143 camera->distance += dy * 0.1;
144 if(camera->distance < 0.0) camera->distance = 0.0;
148 static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
150 bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0;
151 glfwGetCursorPos(win, &prev_x, &prev_y);
154 static void display()