开发者

How to create a colored rectangle in OpenGL ES?

I might want to start learning OpenGL ES. I'm curious about how much code it takes to create a colored rectangle. I fear it takes like 50 lines of code to do this. Does anyone have a link or c开发者_如何学Pythonode snippet at hand which shows this?


I'm assuming OpenGL-ES 1, ES-2 requires some (not so complicated) shader and attribute juggling.

void colored_rect(GLfloat left, GLfloat bottom, GLfloat right, GLfloat top, GLfloat R, GLfloat G, GLfloat B)
{
    GLfloat rect[] = {
        left, bottom,
        right, bottom, 
        right, top,
        left, top
    };
    glEnableClientState(GL_VERTEX_ARRAY);
    glColor3f(R,G,B);
    glVertexPointer(2, GL_FLOAT, 0, rect);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜