-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphics_01.cpp
109 lines (109 loc) · 3.54 KB
/
Graphics_01.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//#include<iostream>
//
//// GLEW
//#define GLEW_STATIC
//#include<GL/glew.h>
//
//// GLFW
//#include<GLFW/glfw3.h>
//#include "Shader.h"
//
//const GLint WIDTH = 800, HEIGHT = 600;
//
//int main() {
// glfwInit();
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
//
// GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "GOD MA", nullptr, nullptr);
// // next two lines are for mac retina display
// int screenWidth, screenHeight;
// glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
//
// if (nullptr == window) {
// std::cout << "Failed to create GLFW window" << std::endl;
// glfwTerminate();
// return -1;
// }
// glfwMakeContextCurrent(window);
// glewExperimental = GL_TRUE;
//
// if (GLEW_OK != glewInit()) {
// std::cout << "Failed to initialize GLEW" << std::endl;
// return -1;
// }
//
// Shader ourShader = Shader("res/shaders/core1.vs", "res/shaders/core1.fs");
//
// GLfloat vertices[] = {
// // position //color
// 0.5f,0.5f,0.0f, 1.0f,0.0f,0.0f, //top right
// 0.5f,-0.5f,0.0f, 1.0f,0.0f,0.0f, //bottom right
// -0.5f,-0.5f,0.0f, 1.0f,0.0f,0.0f, //bottom left
// -0.5f,0.5f,0.0f, 1.0f,0.0f,0.0f, //top left
// };
//
// unsigned int indices[] = {
// 0,1,3,
// 1,2,3
// };
//
// // the data should be transfered to the memory on Graphics Card
// GLuint VAO, VBO;
// glGenVertexArrays(1, &VAO);
// glGenBuffers(1, &VBO);
// // connect the VAO and VBO
// glBindVertexArray(VAO);
// glBindBuffer(GL_ARRAY_BUFFER, VBO);
// // transfer the data
// glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// // set the attribute
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
// glEnableVertexAttribArray(0);
// glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));
// glEnableVertexAttribArray(1);
//
// GLuint EBO;
// glGenBuffers(1, &EBO);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// glBindBuffer(GL_ARRAY_BUFFER, 0);
// glBindVertexArray(0);
//
// while (!glfwWindowShouldClose(window))
// {
// float time = glfwGetTime();
// printf("%f\n",time);
// float redValue = sin(time) / 2.0f + 0.5f;//设置颜色值范围0--1
// float greenValue = 1 - redValue; //设置颜色值范围0--1
// int vertexColorLocation = glGetUniformLocation(ourShader.Program, "ourColor");//获取uniform的位置索引
// glUniform4f(vertexColorLocation, redValue, greenValue, 0.0f, 1.0f);//红-黑-红渐变色
// //if((int)time%2==0)// 红-绿交替出现
// // glUniform4f(vertexColorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
// //else
// // glUniform4f(vertexColorLocation, 0.0f, 1.0f, 0.0f, 1.0f);
// glViewport(0, 0, screenWidth, screenHeight);
// glfwPollEvents();
// glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT);
//
// ourShader.Use();
// glUniform1f(glGetUniformLocation(ourShader.Program, "time"), time);
// glBindVertexArray(VAO);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
// glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// glBindVertexArray(0);
// glfwSwapBuffers(window);
// }
//
// glfwTerminate();
// glDeleteVertexArrays(1, &VAO);
// glDeleteBuffers(1, &VBO);
// glDeleteBuffers(1, &EBO);
// return 0;
//}