Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer
1  
He's clearing it every draw render->setupScene->setupScene –  Miro Aug 5 '12 at 10:13
    
Ah, I should learn to read:) –  maul Aug 5 '12 at 20:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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