6 #include <gmath/gmath.h>
15 #include "shader_manager.h"
17 #include "opengl/opengl.h"
18 #include "vulkan/vk.h"
20 /* static functions */
23 static void cleanup();
24 static void display();
28 static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mods);
29 static void clbk_motion(GLFWwindow *win, double x, double y);
30 static void clbk_mouse(GLFWwindow *win, int button, int action, int mods);
31 static void clbk_reshape(GLFWwindow *win, int width, int height);
33 /* global variables */
47 ShaderManager *sdr_man;
52 // TODO: remove just for test:
55 int main(int argc, char **argv)
57 for(int i=0; i<argc; ++i) {
58 if(strcmp(argv[i], "-opengl") == 0) {
60 printf("Backend: OpenGL.\n");
62 else if(strcmp(argv[i], "-vulkan") == 0) {
64 printf("Backend: Vulkan.\n");
67 printf("No backend specified. Using OpenGL.\n");
72 fprintf(stderr, "Failed to initialize program.\n");
76 glfwSetKeyCallback(win, clbk_key);
77 glfwSetCursorPosCallback(win, clbk_motion);
78 glfwSetMouseButtonCallback(win, clbk_mouse);
79 glfwSetWindowSizeCallback(win, clbk_reshape);
81 while(!glfwWindowShouldClose(win)) {
103 sdr_man = new ShaderManager;
105 camera = new OrbitCamera;
106 camera->set_orbit_params(phi, theta, dist);
108 if(!scene.load("data/spot/spot_control_mesh.obj")) {
109 fprintf(stderr, "Failed to load scene.\n");
113 // TODO delete: debugging
114 for(size_t i=0; i<scene.objects.size(); ++i) {
115 printf("object: %d\n", (int)i);
116 printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
117 printf("material: %s\n", scene.objects[i]->material->name.c_str());
118 printf("transform:\n");
119 scene.objects[i]->transform.print();
124 static void cleanup()
137 static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mods)
139 if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
140 glfwSetWindowShouldClose(win, GLFW_TRUE);
144 static double prev_x, prev_y;
147 static void clbk_motion(GLFWwindow *win, double x, double y)
150 case GLFW_MOUSE_BUTTON_LEFT:
161 case GLFW_MOUSE_BUTTON_RIGHT:
162 dist *= (y - prev_y) * 0.01 + 1;
173 static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods)
176 glfwGetCursorPos(win, &prev_x, &prev_y);
179 static void clbk_reshape(GLFWwindow *win, int width, int height)
186 glViewport(0, 0, width, height);
187 aspect = (float)width / (float)height;
188 mprojection = calc_projection_matrix(1000, 0.5, aspect, 45);
192 static void display()
199 scene.objects[0]->mesh->draw();