-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (76 loc) · 2.4 KB
/
main.cpp
File metadata and controls
97 lines (76 loc) · 2.4 KB
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
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdio.h>
#include "SceneManager.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// Helper Functions
bool printVersions() {
if (const GLubyte* renderer = glGetString(GL_RENDERER))
printf("OpenGL Renderer: %s\n", renderer);
else {
printf("Failed to get OpenGL renderer\n");
return false;
}
if (const GLubyte* version = glGetString(GL_VERSION))
printf("OpenGL Version: %s\n", version);
else {
printf("Failed to get OpenGL version\n");
return false;
}
return true;
}
void error_callback(int error, const char* description) {
fprintf(stderr, "Error: %s\n", description);
throw;
}
void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
throw;
}
////////////////////////////////////////////////////////////////////////////////
// Main
int main(int argc, char** argv){
glfwSetErrorCallback(error_callback);
// Initialize GLFW
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return 1;
}
// Make the Window for the Scene
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
const char* title = "CLAHE";
int width = 800;
int height = 800;
if (!SceneManager::CreateWindow(title, width, height)) {
fprintf(stderr, "Failed to create window\n");
return 1;
}
// Debug Messages
if (!printVersions()) {
return 1;
}
// Initialize GLEW
GLenum err = glewInit();
if (err != GLEW_OK) {
printf("Failed to initialize GLEW!\n");
return 1;
}
// During init, enable debug output
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(MessageCallback, 0);
// Main Render Loop
SceneManager::InitScene();
while (SceneManager::WindowOpen()) {
SceneManager::Update();
SceneManager::Draw();
}
SceneManager::ClearScene();
glfwTerminate();
return 0;
}
////////////////////////////////////////////////////////////////////////////////