Corrupted image if variable is not static

Posted by Jaka Jancar on Stack Overflow See other posts from Stack Overflow or by Jaka Jancar
Published on 2010-03-28T18:12:45Z Indexed on 2010/03/28 18:23 UTC
Read the original article Hit count: 279

Filed under:
|
|

I'm doing the following:

static GLfloat vertices[3][3] = 
{    
    {0.0, 1.0, 0.0},
    {1.0, 0.0, 0.0},
    {-1.0, 0.0, 0.0}
};

glColor4ub(255, 0, 0, 255);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLES, 0, 9);
glDisableClientState(GL_VERTEX_ARRAY);

This works ok:

However, if I remove static from vertices and therefore re-create the data on the stack on each rendering, I get the following:

This happens both on the simulator and on the device.

Should I be keeping the variables around after I call glDrawArrays?

© Stack Overflow or respective owner

Related posts about opengl

Related posts about opengl-es