-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (43 loc) · 1.37 KB
/
main.cpp
File metadata and controls
58 lines (43 loc) · 1.37 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
#include <GL/glew.h>
#include <GLFW/glfw3.h> // putting glew before this, [valid rule]
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return -1;
}
GLFWwindow* window = glfwCreateWindow(800, 600, "GLFW Test", NULL, NULL);
if (!window) {
fprintf(stderr, "Failed to create window\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK) // putting this after setting context [valid rule by glew]
cout << "ERROR!" << endl;
cout << glGetString(GL_VERSION) << endl;
float positions[6] = {
-0.5f, -0.5f,
0.0f, 0.5f,
0.5f, -0.5f,
};
unsigned int buffer; // a buffer for storage
glGenBuffers(1, &buffer); // generate a buffer
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
// glBegin(GL_TRIANGLES);
// glVertex2f(-0.5f, -0.5f);
// glVertex2f(0.0f, 0.5f);
// glVertex2f(0.5f, -0.5f);
// glEnd();
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}