Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
274 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#pragma once | ||
#ifndef Light_h | ||
#define Light_h | ||
|
||
#include<GL/glew.h> | ||
#include "Shader.h" | ||
|
||
|
||
// 和 main.cpp 类似的立方体,现各面默认白色即可 | ||
GLfloat vertices[] = | ||
{ // position | ||
|
||
// z = -0.5 的矩形面 | ||
-0.5f, -0.5f, 0.5f, | ||
0.5f, -0.5f, 0.5f, | ||
0.5f, 0.5f, 0.5f, | ||
0.5f, 0.5f, 0.5f, | ||
-0.5f, 0.5f, 0.5f, | ||
-0.5f, -0.5f, 0.5f, | ||
|
||
// z = 0.5 的矩形面 | ||
-0.5f, -0.5f, -0.5f, | ||
0.5f, -0.5f, -0.5f, | ||
0.5f, 0.5f, -0.5f, | ||
0.5f, 0.5f, -0.5f, | ||
-0.5f, 0.5f, -0.5f, | ||
-0.5f, -0.5f, -0.5f, | ||
|
||
// x = -0.5 的矩形面 | ||
-0.5f, 0.5f, 0.5f, | ||
-0.5f, 0.5f, -0.5f, | ||
-0.5f, -0.5f, -0.5f, | ||
-0.5f, -0.5f, -0.5f, | ||
-0.5f, -0.5f, 0.5f, | ||
-0.5f, 0.5f, 0.5f, | ||
|
||
// x = 0.5 的矩形面 | ||
0.5f, 0.5f, 0.5f, | ||
0.5f, 0.5f, -0.5f, | ||
0.5f, -0.5f, -0.5f, | ||
0.5f, -0.5f, -0.5f, | ||
0.5f, -0.5f, 0.5f, | ||
0.5f, 0.5f, 0.5f, | ||
|
||
// y = -0.5 的矩形面 | ||
-0.5f, -0.5f, -0.5f, | ||
0.5f, -0.5f, -0.5f, | ||
0.5f, -0.5f, 0.5f, | ||
0.5f, -0.5f, 0.5f, | ||
-0.5f, -0.5f, 0.5f, | ||
-0.5f, -0.5f, -0.5f, | ||
|
||
// y = 0.5 的矩形面 | ||
-0.5f, 0.5f, -0.5f, | ||
0.5f, 0.5f, -0.5f, | ||
0.5f, 0.5f, 0.5f, | ||
0.5f, 0.5f, 0.5f, | ||
-0.5f, 0.5f, 0.5f, | ||
-0.5f, 0.5f, -0.5f, | ||
}; | ||
|
||
class Light | ||
{ | ||
public: | ||
Light() | ||
{ | ||
this->update(); | ||
} | ||
void Draw() | ||
{ | ||
glBindVertexArray(this->VAO); | ||
glDrawArrays(GL_TRIANGLES, 0, 36); | ||
glBindVertexArray(0); | ||
} | ||
private: | ||
GLuint VAO, VBO; | ||
void update() | ||
{ | ||
glGenVertexArrays(1, &this->VAO); | ||
glGenBuffers(1, &this->VBO); | ||
// connect the VAO and VBO | ||
glBindVertexArray(this->VAO); | ||
glBindBuffer(GL_ARRAY_BUFFER, this->VBO); | ||
// transfer the data | ||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); | ||
// set the attribute | ||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); | ||
glEnableVertexAttribArray(0); | ||
glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
glBindVertexArray(0); | ||
} | ||
}; | ||
|
||
|
||
#endif // !Light_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.