4
\$\begingroup\$

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);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void drawScene() {
    setupScene();

    glColorMask(0, 0, 0, 1);

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

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


void render() {
    drawScene();
    bbutil_swap();
}

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

\$\endgroup\$
0

2 Answers 2

4
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .