【问题标题】:OpenGL ES - using glDrawArrays()OpenGL ES - 使用 glDrawArrays()
【发布时间】:2012-04-16 04:05:10
【问题描述】:

我正在将一些代码从 OpenGL 移植到 ES 版本。我正在使用 glDrawArrays() 与glVertexPointer() 一起绘制一个三角形。但是,它不会在屏幕上绘制。完整代码为:

void init(void) 
{
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
}

void display(void)
{
    glEnableClientState (GL_COLOR_ARRAY);
    glClear (GL_COLOR_BUFFER_BIT);
    glColor4f (0.0, 0.0, 1.0, 1.0);
    glLoadIdentity ();           


    glTranslatef(0, 0, -20);


    const GLfloat triVertices[] = { 
        0.0f, 1.0f, 0.0f, 
        -1.0f, -1.0f, 0.0f, 
        1.0f, -1.0f, 0.0f 
    };

    glVertexPointer(3, GL_FLOAT, 0, triVertices);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableClientState(GL_VERTEX_ARRAY);
    glFlush ();
}

void reshape (int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    glMatrixMode (GL_MODELVIEW);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (400, 400); 
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();
    glutDisplayFunc(display); 
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
}

GLUT 打开窗口,它以黑色清除,但不绘制任何内容。 有人可以发现我做错了什么吗?谢谢。

【问题讨论】:

    标签: opengl-es


    【解决方案1】:

    我没有看到对 glEnableClientState(GL_VERTEX_ARRAY); 的呼叫。我也看到了glEnableClientState (GL_COLOR_ARRAY);,但没有打电话给glColorPointer()。也许你写了一个,而你的意思是另一个?

    【讨论】:

      猜你喜欢
      • 2011-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多