-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInit.h
More file actions
66 lines (47 loc) · 1.8 KB
/
Copy pathInit.h
File metadata and controls
66 lines (47 loc) · 1.8 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
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
int endProgram(std::string message) {
std::cout << message << std::endl;
glfwTerminate();
return -1;
}
GLFWwindow* initGLFW() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
auto mode = glfwGetVideoMode(primaryMonitor);
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "Controller Visualizer", primaryMonitor, NULL);
if (window == NULL) {
endProgram("Failed to create window");
return NULL;
}
glfwMakeContextCurrent(window);
return window;
}
GLuint sceneFBO, sceneColorTex;
void CreateSceneFramebuffer(int width, int height)
{
glGenFramebuffers(1, &sceneFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sceneFBO);
// ----- Color texture -----
glGenTextures(1, &sceneColorTex);
glBindTexture(GL_TEXTURE_2D, sceneColorTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, sceneColorTex, 0);
// Check
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
printf("Framebuffer is not complete!\n");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}