-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenQuad.cpp
More file actions
40 lines (33 loc) · 1.22 KB
/
screenQuad.cpp
File metadata and controls
40 lines (33 loc) · 1.22 KB
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
#include "ScreenQuad.h"
#include <glad/glad.h> // 或者你使用的其他 OpenGL 加载库
#include "debug_utils.h" // 用于 GL_CHECK_ERROR()
ScreenQuad::ScreenQuad() {
setup(); // 在构造函数中完成初始化
}
void ScreenQuad::setup() {
float quadVertices[] = {
// positions // texCoords
-1.0f, 1.0f, 0.0f, 1.0f, // Top-left
-1.0f, -1.0f, 0.0f, 0.0f, // Bottom-left
1.0f, -1.0f, 1.0f, 0.0f, // Bottom-right
-1.0f, 1.0f, 0.0f, 1.0f, // Top-left (重复)
1.0f, -1.0f, 1.0f, 0.0f, // Bottom-right (重复)
1.0f, 1.0f, 1.0f, 1.0f // Top-right
};
vao_ = std::make_unique<VertexArray>();
vbo_ = std::make_unique<VertexBuffer>(quadVertices, sizeof(quadVertices), GL_STATIC_DRAW);
vao_->bind();
// 属性设置
// 位置属性 (layout location 0)
vao_->setAttribute(0, *vbo_, 2, GL_FLOAT, GL_FALSE, 0, 4 * sizeof(float), 0);
// 纹理坐标属性 (layout location 1)
vao_->setAttribute(1, *vbo_, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 4 * sizeof(float), 0);
vao_->unbind();
GL_CHECK_ERROR();
}
void ScreenQuad::render() const {
vao_->bind();
glDrawArrays(GL_TRIANGLES, 0, 6);
vao_->unbind();
GL_CHECK_ERROR();
}