OpenGL ES 绘图形状
OpenGL ES Drawing Shapes
我正在学习 OpenGL ES 以呈现原生 android 开发。我可以画一个三角形。但是我不能画出一个以上的三角形。我只想绘制一个矩形,但如果我告诉 glVertexPointer 函数超过 3 个顶点,那么它不会绘制。我尝试使用 GL_TRIANGLES 和 GL_TRIANGLE_STRIP.
我做错了什么?
struct Quad
{
GLfloat Vertices[18];
const GLbyte nNumVerts;
Quad(GLfloat i_fWidth, GLfloat i_fHeight) : nNumVerts(6)
{
GLfloat wide = i_fWidth / 2;
GLfloat high = i_fHeight / 2;
Vertices[0] = -wide; Vertices[1] = high; Vertices[2] = 0.0f;
Vertices[3] = -wide; Vertices[4] = -high; Vertices[5] = 0.0f;
Vertices[6] = wide; Vertices[7] = -high; Vertices[8] = 0.0f;
Vertices[9] = -wide; Vertices[10] = high; Vertices[11] = 0.0f;
Vertices[12] = wide; Vertices[13] = -high; Vertices[14] = 0.0f;
Vertices[15] = wide; Vertices[16] = high; Vertices[17] = 0.0f;
}
};
void Renderer::Render()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
// If I change "m_Quad.nNumVerts" to '3' instead of '6' it will draw a triangle
// Anything higher than '3' and it doesn't draw anything
glVertexPointer(m_Quad.nNumVerts, GL_FLOAT, 0, m_Quad.Vertices);
glDrawArrays(GL_TRIANGLES, 0, m_Quad.nNumVerts);
eglSwapBuffers(m_pEngine->pDisplay, m_pEngine->pSurface);
}
glVertexPointer
的第一个参数是每个顶点的值的数量,在这种情况下它应该留在3
。
glVertexPointer(3, GL_FLOAT, 0, m_Quad.Vertices);
我正在学习 OpenGL ES 以呈现原生 android 开发。我可以画一个三角形。但是我不能画出一个以上的三角形。我只想绘制一个矩形,但如果我告诉 glVertexPointer 函数超过 3 个顶点,那么它不会绘制。我尝试使用 GL_TRIANGLES 和 GL_TRIANGLE_STRIP.
我做错了什么?
struct Quad
{
GLfloat Vertices[18];
const GLbyte nNumVerts;
Quad(GLfloat i_fWidth, GLfloat i_fHeight) : nNumVerts(6)
{
GLfloat wide = i_fWidth / 2;
GLfloat high = i_fHeight / 2;
Vertices[0] = -wide; Vertices[1] = high; Vertices[2] = 0.0f;
Vertices[3] = -wide; Vertices[4] = -high; Vertices[5] = 0.0f;
Vertices[6] = wide; Vertices[7] = -high; Vertices[8] = 0.0f;
Vertices[9] = -wide; Vertices[10] = high; Vertices[11] = 0.0f;
Vertices[12] = wide; Vertices[13] = -high; Vertices[14] = 0.0f;
Vertices[15] = wide; Vertices[16] = high; Vertices[17] = 0.0f;
}
};
void Renderer::Render()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
// If I change "m_Quad.nNumVerts" to '3' instead of '6' it will draw a triangle
// Anything higher than '3' and it doesn't draw anything
glVertexPointer(m_Quad.nNumVerts, GL_FLOAT, 0, m_Quad.Vertices);
glDrawArrays(GL_TRIANGLES, 0, m_Quad.nNumVerts);
eglSwapBuffers(m_pEngine->pDisplay, m_pEngine->pSurface);
}
glVertexPointer
的第一个参数是每个顶点的值的数量,在这种情况下它应该留在3
。
glVertexPointer(3, GL_FLOAT, 0, m_Quad.Vertices);