-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphics_03.cpp
242 lines (242 loc) · 8.03 KB
/
Graphics_03.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//#include<iostream>
//#include<math.h>
//
////GLEW
//#define GLEW_STATIC
//#define PI acos(-1)
//#include<GL/glew.h>
//
////GLFW
//#include<GLFW/glfw3.h>
//
//#include "Shader.h"
//#include "Moon.h"
//#include "Camera.h"
//
//#include <glm/glm.hpp>
//#include <glm/gtc/matrix_transform.hpp>
//#include <glm/gtc/type_ptr.hpp>
//#include <glm/gtx/rotate_vector.hpp>
//
//const GLint WIDTH = 800, HEIGHT = 600;
//void KeyCallback(GLFWwindow* window, int key, int scnacode, int action, int mode);
//void ScrollCallback(GLFWwindow* window, double xOffset, double yOffset);
//void MouseCallback(GLFWwindow* window, double xPos, double yPos);
//void DoMovement();
//bool keys[1024];
//Camera camera(glm::vec3(0.0f, 0.0f, 2.0f));
//GLfloat deltaTime = 0.0f;
//GLfloat lastTime = 0.0f;
//GLfloat lastX = WIDTH / 2.0f;
//GLfloat lastY = HEIGHT / 2.0f;
//bool firstMouse = true;
//
//
//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, "LEZ", 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);
// glfwSetKeyCallback(window, KeyCallback);
// // glfwSetCursorPosCallback(window, MouseCallback);
// glfwSetScrollCallback(window, ScrollCallback);
// glewExperimental = GL_TRUE;
//
// if (GLEW_OK != glewInit()) {
// std::cout << "Failed to initialize GLEW" << std::endl;
// return -1;
// }
//
// glEnable(GL_DEPTH_TEST);
// glDepthFunc(GL_LESS);
// glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//
// Shader ourShader = Shader("res/shaders/core3.vs", "res/shaders/core3.fs");
// Shader moonShader = Shader("res/shaders/moon.vs", "res/shaders/moon.fs");
//
// Moon moonModel = Moon();
//
//
// GLfloat vertices[] = {
// //position //color
// -0.5f,-0.5f,-0.5f, 1.0f,0.0f,0.0f,
// 0.5f,-0.5f,-0.5f, 1.0f,0.0f,0.0f,
// 0.5f,0.5f,-0.5f, 1.0f,0.0f,0.0f,
// 0.5f,0.5f,-0.5f, 1.0f,0.0f,0.0f,
// -0.5f,0.5f,-0.5f, 1.0f,0.0f,0.0f,
// -0.5f,-0.5f,-0.5f, 1.0f,0.0f,0.0f,
//
// -0.5f,-0.5f,0.5f, 0.0f,1.0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0f,
// };
//
// // 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);
//
//
// glBindBuffer(GL_ARRAY_BUFFER, 0);
// glBindVertexArray(0);
//
// glm::vec3 moonPos = glm::vec3(0.0f, 0.0f, 1.5f);
//
// while (!glfwWindowShouldClose(window))
// {
// float time = glfwGetTime();
// GLfloat currentTime = glfwGetTime();
// deltaTime = currentTime - lastTime;
// lastTime = currentTime;
// glViewport(0, 0, screenWidth, screenHeight);
// glfwPollEvents();
// DoMovement();
// glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//
// glm::mat4 projection = glm::perspective(glm::radians(camera.GetZoom()), (float)screenWidth / (float)screenHeight,
// 0.1f, 100.0f);
//
// moonPos = glm::rotate(moonPos, glm::radians(0.5f), glm::vec3(0.0f, 1.0f, 0.0f));
// glm::mat4 view = camera.GetViewMatrix();
// glm::mat4 transform = glm::mat4(1.0f);
// transform = glm::translate(transform, moonPos);
// transform = glm::rotate(transform, glm::radians(20.0f) * static_cast<GLfloat>(glfwGetTime()), glm::vec3(1.0, 1.0, 1.0));
// transform = glm::scale(transform, glm::vec3(0.1f, 0.1f, 0.1f));
// moonShader.Use();
// glUniformMatrix4fv(glGetUniformLocation(moonShader.Program, "transform"), 1, GL_FALSE, glm::value_ptr(transform));
// glUniformMatrix4fv(glGetUniformLocation(moonShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
// glUniformMatrix4fv(glGetUniformLocation(moonShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(view));
// moonModel.Draw(moonShader);
//
//
// ourShader.Use();
// transform = glm::mat4(1.0f);
// // transform = glm::translate(transform, glm::vec3(0.0f, 0.0f, -2.0f));
// transform = glm::rotate(transform, glm::radians(20.0f)*static_cast<GLfloat>(glfwGetTime()), glm::vec3(sin(23.5*PI/180), cos(23.5*PI/180), 0.0f));
// transform = glm::rotate(transform, glm::radians(-23.5f), glm::vec3(0.0f, 0.0f, 1.0f));
// transform = glm::scale(transform, glm::vec3(0.5f, 0.5f, 0.5f));
// GLuint transLoc = glGetUniformLocation(ourShader.Program, "transform");
// glUniformMatrix4fv(transLoc, 1, GL_FALSE, glm::value_ptr(transform));
// glUniformMatrix4fv(glGetUniformLocation(ourShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));
// glUniformMatrix4fv(glGetUniformLocation(ourShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(view));
// glBindVertexArray(VAO);
// glDrawArrays(GL_TRIANGLES, 0, 36);
// glBindVertexArray(0);
// glfwSwapBuffers(window);
// }
//
// glfwTerminate();
// glDeleteVertexArrays(1, &VAO);
// glDeleteBuffers(1, &VBO);
// return 0;
// }
//
//void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mode) {
// if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
// glfwSetWindowShouldClose(window, GL_TRUE);
// }
// if (key >= 0 && key < 1024) {
// if (action == GLFW_PRESS) {
// keys[key] = true;
// }
// else if (action == GLFW_RELEASE)
// {
// keys[key] = false;
// }
// }
//}
//
//void DoMovement() {
// if (keys[GLFW_KEY_W] || keys[GLFW_KEY_UP])
// {
// camera.ProcessKeyboard(FORWARD, deltaTime);
// }
// if (keys[GLFW_KEY_S] || keys[GLFW_KEY_DOWN])
// {
// camera.ProcessKeyboard(BACKWARD, deltaTime);
// }
// /*if (keys[GLFW_KEY_A] || keys[GLFW_KEY_LEFT])
// {
// camera.ProcessKeyboard(LEFT, deltaTime);
// }
// if (keys[GLFW_KEY_D] || keys[GLFW_KEY_RIGHT])
// {
// camera.ProcessKeyboard(RIGHT, deltaTime);
// }*/
//}
//void ScrollCallback(GLFWwindow* window, double xOffset, double yOffset) {
//
//}
//void MouseCallback(GLFWwindow* window, double xPos, double yPos) {
// if (firstMouse) {
// lastX = xPos;
// lastY = yPos;
// firstMouse = false;
// }
// GLfloat xOffset = xPos - lastX;
// GLfloat yOffset = lastY - yPos;
//
// lastX = xPos;
// lastY = yPos;
//
// camera.ProcessMouseMovement(xOffset, yOffset);
//}
//