include stdafx include Callbacks include Structures include AuxObjects

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#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;
}