Trying to Draw a 2D Triangle in OpenGL ES 2.0
Posted
by
Nathan Campos
on Game Development
See other posts from Game Development
or by Nathan Campos
Published on 2012-08-05T02:41:10Z
Indexed on
2012/09/04
15:55 UTC
Read the original article
Hit count: 620
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
© Game Development or respective owner