#include <string.h>
#include <vector>
+#include <gmath/gmath.h>
+
#include "global.h"
/* TODO: fix those */
static void display();
/* glfw callbacks */
-static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods);
-static void motion_clbk(GLFWwindow *win, double x, double y);
-static void mouse_clbk(GLFWwindow *win, int button, int action, int mods);
+
+static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mods);
+static void clbk_motion(GLFWwindow *win, double x, double y);
+static void clbk_mouse(GLFWwindow *win, int button, int action, int mods);
+static void clbk_reshape(GLFWwindow *win, int width, int height);
/* global variables */
+
bool use_vulkan;
+Mat4 mprojection;
GLFWwindow *win;
int win_w = 800;
int win_h = 600;
OrbitCamera *camera;
+float phi = 25;
+float theta = 0;
+float dist = 4;
+
ShaderManager *sdr_man;
/* variables */
-static float phi = 25;
-static float theta = 0;
-static float dist = 4;
+static float aspect;
// TODO: remove just for test:
static Scene scene;
return 1;
}
- glfwSetKeyCallback(win, key_clbk);
- glfwSetCursorPosCallback(win, motion_clbk);
- glfwSetMouseButtonCallback(win, mouse_clbk);
+ glfwSetKeyCallback(win, clbk_key);
+ glfwSetCursorPosCallback(win, clbk_motion);
+ glfwSetMouseButtonCallback(win, clbk_mouse);
+ glfwSetWindowSizeCallback(win, clbk_reshape);
while(!glfwWindowShouldClose(win)) {
display();
static bool init()
{
- /* TODO */
- /*
- TODO changes:
- 1- create cam
- 2- scene
- 3- renderers
- */
if(use_vulkan) {
if(!init_vulkan())
return false;
return false;
}
+// TODO delete: debugging
for(size_t i=0; i<scene.objects.size(); ++i) {
printf("object: %d\n", (int)i);
printf("mesh: %s\n", scene.objects[i]->mesh->name.c_str());
}
}
-static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
+static void clbk_key(GLFWwindow *win, int key, int scancode, int action, int mods)
{
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(win, GLFW_TRUE);
static double prev_x, prev_y;
static int button;
-static void motion_clbk(GLFWwindow *win, double x, double y)
+static void clbk_motion(GLFWwindow *win, double x, double y)
{
switch(button) {
case GLFW_MOUSE_BUTTON_LEFT:
prev_y = y;
}
-static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
+static void clbk_mouse(GLFWwindow *win, int bn, int action, int mods)
{
button = bn;
glfwGetCursorPos(win, &prev_x, &prev_y);
}
+static void clbk_reshape(GLFWwindow *win, int width, int height)
+{
+ if(use_vulkan) {
+ //TODO
+ return;
+ }
+ else {
+ glViewport(0, 0, width, height);
+ aspect = (float)width / (float)height;
+ mprojection = calc_projection_matrix(1000, 0.5, aspect, 45);
+ }
+}
+
static void display()
{
if(use_vulkan) {