I'm trying to convert a code from OpenGL to OpenGL ES 2.0 (for the BlackBerry PlayBook). So far what I got is this (just the part of the code that should draw the triangle):

void setupScene() {
    glClearColor(250, 250, 250, 1);
    glViewport(0, 0, 600, 1024);

void drawScene() {

    glColorMask(0, 0, 0, 1);

    const GLfloat triangleVertices[] = {
        100,   100,
        150,  0,
        200,   100

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, triangleVertices);
    glDrawArrays(GL_TRIANGLES, 0, 2);

void render() {

The problem is that when I launch the app instead of showing me the triangle the screen just flickers (very fast) from white to gray. Any idea what I'm doing wrong?

Also, here is the entire code if you need: Full source code


What you are trying to do is available in the project: http://code.google.com/p/opengles-book-samples/

The OpenGL ES 2.0 does not support the fixed rendering pipeline, so you will need to come up with your own shaders. Take a closer look at the utility functions to compile and load shaders, also, the "Hello Triangle" sample... Very good way to get started if you already know your way around OpenGL.


You have to use shaders. And I also believe the arguments of glDrawArrays are wrong - you need to pass the number of indices as the last one.

Oh, and you're using fairly large values for the triangle's position, but you have no view and projection matrix set up, so they will be way outside the screen.

As for the flickering, you need to call glClear per draw, not just once.

  • 1
    \$\begingroup\$ He's clearing it every draw render->setupScene->setupScene \$\endgroup\$ – kravemir Aug 5 '12 at 10:13
  • \$\begingroup\$ Ah, I should learn to read:) \$\endgroup\$ – maul Aug 5 '12 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.