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)) {
93 camera = new Camera(25, 25, 4, 45);
95 if(!scene.load("data/spot/spot_control_mesh.obj")) {
96 fprintf(stderr, "Failed to load scene.\n");
100 for(size_t i=0; i<scene.objects.size(); ++i) {
101 printf("object: %d\n", (int)i);
102 printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
103 printf("material: %s\n", scene.objects[i]->material->name.c_str());
104 printf("transform:\n");
105 scene.objects[i]->transform.print();
110 static void cleanup()
122 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
124 if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
125 glfwSetWindowShouldClose(win, GLFW_TRUE);
129 static double prev_x, prev_y;
130 static int bnstate[8];
132 static void motion_clbk(GLFWwindow *win, double x, double y)
140 if(!dx && !dy) return;
143 camera->theta += dx * 0.5;
144 camera->phi += dy * 0.5;
146 if(camera->phi < -90) camera->phi = -90;
147 if(camera->phi > 90) camera->phi = 90;
150 camera->distance += dy * 0.1;
151 if(camera->distance < 0.0) camera->distance = 0.0;
155 static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
157 bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0;
158 glfwGetCursorPos(win, &prev_x, &prev_y);
161 static void display()