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 static float phi = 25;
37 static float theta = 0;
38 static float dist = 4;
40 // TODO: remove just for test:
43 int main(int argc, char **argv)
45 for(int i=0; i<argc; ++i) {
46 if(strcmp(argv[i], "-opengl") == 0) {
48 printf("Backend: OpenGL.\n");
50 else if(strcmp(argv[i], "-vulkan") == 0) {
52 printf("Backend: Vulkan.\n");
55 printf("No backend specified. Using OpenGL.\n");
60 fprintf(stderr, "Failed to initialize program.\n");
64 glfwSetKeyCallback(win, key_clbk);
65 glfwSetCursorPosCallback(win, motion_clbk);
66 glfwSetMouseButtonCallback(win, mouse_clbk);
68 while(!glfwWindowShouldClose(win)) {
97 camera = new OrbitCamera;
98 camera->set_orbit_params(phi, theta, dist);
100 if(!scene.load("data/spot/spot_control_mesh.obj")) {
101 fprintf(stderr, "Failed to load scene.\n");
105 for(size_t i=0; i<scene.objects.size(); ++i) {
106 printf("object: %d\n", (int)i);
107 printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
108 printf("material: %s\n", scene.objects[i]->material->name.c_str());
109 printf("transform:\n");
110 scene.objects[i]->transform.print();
115 static void cleanup()
127 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
129 if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
130 glfwSetWindowShouldClose(win, GLFW_TRUE);
134 static double prev_x, prev_y;
137 static void motion_clbk(GLFWwindow *win, double x, double y)
140 case GLFW_MOUSE_BUTTON_LEFT:
151 case GLFW_MOUSE_BUTTON_RIGHT:
152 dist *= (y - prev_y) * 0.01 + 1;
163 static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
166 glfwGetCursorPos(win, &prev_x, &prev_y);
169 static void display()
176 scene.objects[0]->mesh->update_vertex_data();
177 scene.objects[0]->mesh->draw();