1 #include <iostream>
2 #include "StdAfx.h"
3
4 GLuint Buffer_ID;
5 const int BUFFER_NUMBER = 1;
6
7 GLuint VAO_ID;
8 GLuint VAO_NUMBER = 1;
9
10 const int VERTICES_NUMBER = 6;
11 const int vPosition = 0;
12
13 void Initialize()
14 {
15 //---------------------准备数据-------------------------------
16 GLfloat vertices[VERTICES_NUMBER][2] =
17 {
18 { -0.90, -0.90 },
19 { 0.85, -0.90 },
20 { -0.90, 0.85 },
21
22 { 0.90, -0.85 },
23 { 0.90, 0.90 },
24 { -0.85, 0.90 }
25 };
26
27 // 生成缓存对象
28 glGenBuffers(BUFFER_NUMBER, &Buffer_ID);
29
30 // 绑定缓存对象
31 glBindBuffer(GL_ARRAY_BUFFER, Buffer_ID);
32
33 // 填入数据
34 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
35
36 //-------------------设置顶点数据属性------------------------------
37 // 生成顶点数组对象
38 glGenVertexArrays(VAO_NUMBER, &VAO_ID);
39
40 // 绑定顶点数组对象
41 glBindVertexArray(VAO_ID);
42
43 // 设置顶点属性
44 glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
45 glEnableVertexAttribArray(vPosition);
46 }
47
48 void display()
49 {
50 glClear(GL_COLOR_BUFFER_BIT);
51
52 glBindVertexArray(VAO_ID);
53 glDrawArrays(GL_TRIANGLES, 0, VERTICES_NUMBER);
54
55 glFlush();
56 }
57
58 int main(int argc, char **argv)
59 {
60 glutInit(&argc, argv);
61 glutInitDisplayMode(GLUT_RGBA);
62 glutInitWindowSize(512, 512);
63 glutInitContextVersion(3, 3);
64 glutInitContextProfile(GLUT_CORE_PROFILE);
65 glutCreateWindow(argv[0]);
66
67 glewExperimental = TRUE;
68 if (glewInit())
69 {
70 std::cerr << "Unable to initialize GLEW... Exiting..." << std::endl;
71 std::exit(EXIT_FAILURE);
72 }
73
74 Initialize();
75 glutDisplayFunc(display);
76 glutMainLoop();
77 }
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-32683-2.html
不然会很麻烦的
对于强盗
在北上广都没问题