views:

40

answers:

0

I've subclassed CCNode and would like to blitz an image stored in a member GLubyte* buffer on each draw call. This results in a black square being drawn, and a sibling CCLabel node is now also completely black.

So there are two issues:

  1. Why isn't the square white? I'm memset-ing the buffer to 0xffffffff.
  2. There must be something wrong with my OpenGL calls in the draw method, since it affects the drawing of another node. Can anyone say what?

data initialization:

exponent = e;
width = 1 << exponent;
height = 1 << exponent;
imageData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
memset(imageData, 0xff, 4 * width * height * sizeof(GLubyte));

draw method:

- (void) draw
{
  float w = 100.0f;

  GLfloat vertices[] = {
    0.0f, 0.0f, 0.0f,
       w, 0.0f, 0.0f,
    0.0f,    w, 0.0f,
       w,    w, 0.0f
  };

  const GLshort texture_coordinates[] = {
    0, 0,
    1, 0,
    0, 1,
    1, 1,
  };

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, width, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

  glVertexPointer(3, GL_FLOAT, 0, vertices);
  glTexCoordPointer(2, GL_SHORT, 0, texture_coordinates);

  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}