开发者

How to create a colored rectangle in OpenGL ES?

开发者 https://www.devze.com 2023-03-15 23:14 出处:网络
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开发者_

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

精彩评论

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

关注公众号