13 #include "shader_manager.h"
15 #include "opengl/opengl.h"
16 #include "vulkan/vk.h"
18 /* static functions */
21 static void cleanup();
22 static void display();
25 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods);
26 static void motion_clbk(GLFWwindow *win, double x, double y);
27 static void mouse_clbk(GLFWwindow *win, int button, int action, int mods);
29 /* global variables */
37 ShaderManager *sdr_man;
40 static float phi = 25;
41 static float theta = 0;
42 static float dist = 4;
44 // TODO: remove just for test:
47 int main(int argc, char **argv)
49 for(int i=0; i<argc; ++i) {
50 if(strcmp(argv[i], "-opengl") == 0) {
52 printf("Backend: OpenGL.\n");
54 else if(strcmp(argv[i], "-vulkan") == 0) {
56 printf("Backend: Vulkan.\n");
59 printf("No backend specified. Using OpenGL.\n");
64 fprintf(stderr, "Failed to initialize program.\n");
68 glfwSetKeyCallback(win, key_clbk);
69 glfwSetCursorPosCallback(win, motion_clbk);
70 glfwSetMouseButtonCallback(win, mouse_clbk);
72 while(!glfwWindowShouldClose(win)) {
101 sdr_man = new ShaderManager;
103 camera = new OrbitCamera;
104 camera->set_orbit_params(phi, theta, dist);
106 if(!scene.load("data/spot/spot_control_mesh.obj")) {
107 fprintf(stderr, "Failed to load scene.\n");
111 for(size_t i=0; i<scene.objects.size(); ++i) {
112 printf("object: %d\n", (int)i);
113 printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
114 printf("material: %s\n", scene.objects[i]->material->name.c_str());
115 printf("transform:\n");
116 scene.objects[i]->transform.print();
121 static void cleanup()
134 static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
136 if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
137 glfwSetWindowShouldClose(win, GLFW_TRUE);
141 static double prev_x, prev_y;
144 static void motion_clbk(GLFWwindow *win, double x, double y)
147 case GLFW_MOUSE_BUTTON_LEFT:
158 case GLFW_MOUSE_BUTTON_RIGHT:
159 dist *= (y - prev_y) * 0.01 + 1;
170 static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
173 glfwGetCursorPos(win, &prev_x, &prev_y);
176 static void display()
183 scene.objects[0]->mesh->draw();