Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (70 loc) · 2.54 KB
/
Copy pathmain.cpp
File metadata and controls
93 lines (70 loc) · 2.54 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
// Carrega as funções do OpenGL.
#include <GL/glew.h>
// Permite criar a janela e processar eventos.
#include <GLFW/glfw3.h>
#include <iostream>
#include <cstdlib>
struct Engine {
GLFWwindow* window;
// Dimensões iniciais da janela, em pixels.
int WIDTH = 1200;
int HEIGHT = 720;
Engine() {
if (!glfwInit()) {
std::cerr << "Erro ao inicializar o GLFW.\n";
std::exit(EXIT_FAILURE);
}
// Solicita a versão 3.3 do OpenGL.
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// Seleciona o perfil Core, usado no OpenGL moderno.
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Cria a janela.
// Os dois nullptr indicam:
// 1. Não usar um monitor em modo de tela cheia.
// 2. Não compartilhar recursos com outro contexto.
window = glfwCreateWindow(WIDTH, HEIGHT, "CalcRender", nullptr, nullptr);
if (window == nullptr) {
std::cerr << "Erro ao criar a janela.\n";
// Encerra o GLFW, que já havia sido inicializado.
glfwTerminate();
std::exit(EXIT_FAILURE);
}
// Seleciona o contexto OpenGL da nossa janela.
// Os comandos gráficos passam a utilizar esse contexto.
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
const GLenum glewErr = glewInit();
if (glewErr != GLEW_OK) {
std::cerr << "Erro ao inicializar o GLEW: "
<< glewGetErrorString(glewErr)
<< '\n';
// Libera a janela e encerra o GLFW antes de sair.
glfwDestroyWindow(window);
glfwTerminate();
// Impede que o programa continue com a janela destruída.
std::exit(EXIT_FAILURE);
}
// Solicita sincronização da apresentação com a tela.
glfwSwapInterval(1);
}
void run() {
// Cria um cor: cor preta. Para a tela.
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// Limpa o buffer de cor utilizando a cor definida acima.
glClear(GL_COLOR_BUFFER_BIT);
}
} engine;
int main() {
while (!glfwWindowShouldClose(engine.window)) {
// Prepara um quadro com o fundo preto.
engine.run();
// Inicializa o quadro.
glfwSwapBuffers(engine.window);
// Processa os eventos da janela.
glfwPollEvents();
}
glfwDestroyWindow(engine.window);
glfwTerminate();
return 0;
}