-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialization.cpp
67 lines (51 loc) · 1.48 KB
/
initialization.cpp
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
#include "glad/glad.h"
#include <GLFW/glfw3.h>
#include <iostream>
void processInput(GLFWwindow *window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
}
void check_link_success(unsigned int program)
{
int success;
char infoLog[512];
glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(program, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::LIONING::COMPILATION_FAILED\n" << infoLog << std::endl;
}
}
void framebuffer_size_callback(GLFWwindow *window, int width, int height)
{
glViewport(0, 0, width, height);
}
GLFWwindow *initialize_glfw(int width, int height, bool show_window, int multisampling)
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, show_window ? GLFW_TRUE : GLFW_FALSE);
if(multisampling){
glfwWindowHint(GLFW_SAMPLES,multisampling);
}
GLFWwindow *window =
glfwCreateWindow(width, height, "opengle", NULL, NULL);
if (!window) {
std::cout << " window failed" << std::endl;
glfwTerminate();
std::exit(9);
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
return window;
}
void initialize_glad()
{
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
std::exit(8);
}
}