SHOW:
|
|
- or go back to the newest paste.
1 | #include <iostream> | |
2 | ||
3 | #include <GL/glew.h> | |
4 | #include <GL/glfw.h> | |
5 | ||
6 | #include "LoadShaders.h" | |
7 | ||
8 | GLuint vertexArrayObjects[1]; | |
9 | GLuint buffers[1]; | |
10 | const GLuint vertexCount = 6; | |
11 | ||
12 | void init() { | |
13 | // glClearColor(0,0,0,0); | |
14 | ||
15 | glGenVertexArrays(1, vertexArrayObjects); | |
16 | glBindVertexArray(vertexArrayObjects[0]); | |
17 | ||
18 | GLfloat vertices[vertexCount][2] { | |
19 | {-90.0, -90.0}, | |
20 | { 85.0, -90.0}, | |
21 | {-90.0, 85.0}, | |
22 | { 90.0, -85.0}, | |
23 | { 90.0, 90.0}, | |
24 | {-85.0, 90.0} | |
25 | }; | |
26 | ||
27 | glGenBuffers(1, buffers); | |
28 | glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); | |
29 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); | |
30 | ||
31 | ShaderInfo shaders[] { | |
32 | {GL_VERTEX_SHADER, "one.vsh"}, | |
33 | {GL_FRAGMENT_SHADER, "one.fsh"}, | |
34 | {GL_NONE, nullptr} | |
35 | }; | |
36 | ||
37 | GLuint program = LoadShaders(shaders); | |
38 | glUseProgram(program); | |
39 | ||
40 | - | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, ((char *)NULL + (1))); |
40 | + | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, ((char *)NULL + (0))); |
41 | glEnableVertexAttribArray(0); | |
42 | ||
43 | ||
44 | } | |
45 | ||
46 | void display() { | |
47 | glClear(GL_COLOR_BUFFER_BIT); | |
48 | ||
49 | glBindVertexArray(vertexArrayObjects[0]); | |
50 | glDrawArrays(GL_TRIANGLES, 0, vertexCount); | |
51 | ||
52 | glFlush(); | |
53 | } | |
54 | ||
55 | int main(int argc, char * argv[]) | |
56 | { | |
57 | if(!glfwInit()) { | |
58 | glfwTerminate(); | |
59 | std::cerr << "unable to initialize GLFW" << std::endl; | |
60 | return EXIT_FAILURE; | |
61 | } | |
62 | ||
63 | glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); | |
64 | glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 0); | |
65 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); | |
66 | glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); | |
67 | glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
68 | glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | |
69 | ||
70 | if(!glfwOpenWindow(512,512, | |
71 | 8,8,8, | |
72 | 8,24,8, | |
73 | GLFW_WINDOW)) { | |
74 | glfwTerminate(); | |
75 | std::cerr << "unable to create window" << std::endl; | |
76 | return EXIT_FAILURE; | |
77 | } | |
78 | glfwSetWindowTitle("OpenGL Application"); | |
79 | ||
80 | glewExperimental = true; | |
81 | if(glewInit()) { | |
82 | glfwTerminate(); | |
83 | std::cerr << "unable to initialize GLEW" << std::endl; | |
84 | return EXIT_FAILURE; | |
85 | } | |
86 | ||
87 | init(); | |
88 | ||
89 | while (glfwGetWindowParam(GLFW_OPENED)) { | |
90 | display(); | |
91 | glfwSwapBuffers(); | |
92 | } | |
93 | ||
94 | ||
95 | glfwTerminate(); | |
96 | return EXIT_SUCCESS; | |
97 | } |