#include "stdafx.h" #include "Callbacks.h" #include "Structures.h" #include "AuxObjects.h" /************************************************************************/ /* Structures and definitions */ /************************************************************************/ // 3d objects Coordinates coordinates; Grid grid; Prism prism; // Defined in Callbacks.cpp extern winsz WindowSize; extern bool cameraRotation; extern double cameraAngleX; extern void setProjectionMatrix(void); /************************************************************************/ /* Aux. stuff */ /************************************************************************/ // Initializing scene before using it void init_scene(GLFWwindow* window) { resize_callback(window, WindowSize.Width, WindowSize.Height); } /************************************************************************/ /* Drawing */ /************************************************************************/ void render_scene(void) { // Perform camera rotation ("R" key) if (cameraRotation == true) { cameraAngleX += 0.1; setProjectionMatrix(); } // Select & reset the modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Drawing coordinates, grid & light coordinates.draw(4); grid.draw(10, 1); // Build and draw prism prism.build(6); prism.draw(); } int main(int argc, char* argv[]) { GLFWwindow* window; std::cout << WindowSize.Width << ", " << WindowSize.Height << std::endl; // Init GLFW if(!glfwInit()) { printf("glfwInit failed\n"); return -1; } // Trying to create window glfwSetErrorCallback(error_callback); window = glfwCreateWindow(WindowSize.Width, WindowSize.Height, "Test app", NULL, NULL); if (window == NULL) { printf("glfwOpenWindow failed. Can your hardware handle OpenGL 3.2?\n"); glfwTerminate(); return -2; } int attrib; attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE); // Creating context glfwMakeContextCurrent(window); // Setting up callbacks glfwSetKeyCallback(window, keyboard_callback); glfwSetFramebufferSizeCallback(window, resize_callback); glfwSetMouseButtonCallback(window, mouse_callback); glfwSetCursorPosCallback(window, cursor_callback); glfwSetScrollCallback(window, wheel_callback); // Initialization init_scene(window); // Main loop while (!glfwWindowShouldClose(window)) { render_scene(); glfwSwapBuffers(window); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glfwPollEvents(); } glfwDestroyWindow(window); // clean up and exit glfwTerminate(); return 0; }