【发布时间】:2018-11-07 10:24:56
【问题描述】:
以下是我用来绘制矩形的部分代码。 我可以在显示屏上看到矩形,但与显示平面上的象限和坐标混淆了。
int position_loc = glGetAttribLocation(ProgramObject, "vertex");
int color_loc = glGetAttribLocation(ProgramObject, "color_a");
GLfloat Vertices[4][4] = {
-0.8f, 0.6f, 0.0f, 1.0f,
-0.1f, 0.6, 0.0f, 1.0f,
-0.8f, 0.8f, 0.0f, 1.0f,
-0.1f, 0.8f, 0.0f, 1.0f
};
GLfloat red[4] = {1, 0, 1, 1};
glUniform4fv(glGetUniformLocation(ProgramObject, "color"), 1, red);
PrintGlError();
glEnableVertexAttribArray(position_loc);
PrintGlError();
printf("\nAfter Enable Vertex Attrib Array");
glBindBuffer(GL_ARRAY_BUFFER, VBO);
PrintGlError();
glVertexAttribPointer(position_loc, 4, GL_FLOAT, GL_FALSE, 0, 0);
PrintGlError();
glBufferData(GL_ARRAY_BUFFER, sizeof Vertices, Vertices, GL_DYNAMIC_DRAW);
PrintGlError();
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
PrintGlError();
所以记住上面的顶点
GLfloat Vertices[4][4] = {
x, y, p, q,
x1, y1, p1, q1,
x2, y2, p2, q2,
x3, y3, p3, q3,
};
什么是 p,q .. p1,q1.. ?最后两点是根据什么确定的? 它如何影响 x,y 或 x1,y1 .. 等等?
【问题讨论】:
-
这组顶点是否以
4x4矩阵的形式用于3D渲染或2D渲染?我问这个是因为4x4矩阵的使用和应用在2D和3D之间是不同的。 -
@FrancisCugler 4x4 正在用于 2D 渲染。
标签: c++ opengl shader draw egl