Imagination PowerVR SDK Blog

glTexImage2D with width of 8


#1

Hi everyone,

 

I am using the imgtec ddk 1.5, GLESv1, and was wondering if someone can look at my code to see if I missed something, or if this is a known restriction with the pvr.

 

for (h=12; h<=20; h++) testGlTexImage2D( 10+(h-12)*40,10, 8,32,7,h); /* this does not work */

 

If the third parameter to testGlTexImage2D() is 16, it works ... otherwise, the textures are coming out all garbled.  I also tried calling glPixelStorei(GL_UNPACK_ALIGNMENT, 1); thinking it might affect things, but I did not notice any difference.

 

The closer h gets to 20, the worse it gets.  The upper right corner of the rectangle gets "chewed" out ... unfortunately I cannot get a screen capture at the moment ...

 

void testGlTexImage2D(int x, int y, int W, int H, int w, int h)
{
  GLuint textureID = 0;
  GLint textureFormat = GL_RGBA;
  GLint format = GL_UNSIGNED_BYTE;
  static GLushort indices[] = { 0, 1, 2, 0, 2, 3 };


  glEnable(GL_TEXTURE_2D);
  glGenTextures(1, &textureID);
  glBindTexture(GL_TEXTURE_2D, textureID);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

  glTexImage2D(GL_TEXTURE_2D, 0, textureFormat, W, H, 0, textureFormat, format, NULL);

 

  int EXTRA = 10000;
  int size = 4*w*h+2*EXTRA;
  unsigned char *mem = malloc(size);
  if (mem == NULL)
    {
      fprintf(stderr,"Out of Memoryn");
    }
  else
    {
      memset(mem,0xff,size);
      unsigned int *pixelData = (unsigned int*)&(mem[EXTRA]);
      int xx,yy;
      for (xx=0; xx<w; xx++)
        for (yy=0; yy<h; yy++)
          pixelData[yy*w+xx] = (xx == 0 || xx == (w-1) || yy == 0 || yy == (h-1)) ? 0xFFFF00FF : 0x0;

 

      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w,h, textureFormat,format, pixelData);
      free(mem);
    }

  /* translate the starting drawing coordinates */
  glPushMatrix();
  glTranslatef(x, y, 0.f);

  float aX = w;
  float aY = h;
  float fX = aX/W;
  float fY = aY/H;

  GLfloat area[] = {
    //    x   y   z  u   v
    /*0*/  0, aY, 0,  0, fY,
    /*1*/  0,  0, 0,  0,  0,
    /*2*/ aX,  0, 0, fX,  0,
    /*3*/ aX, aY, 0, fX, fY
  };

  glVertexPointer(3, GL_FLOAT, 5 * sizeof (GLfloat), area);
  glTexCoordPointer(2, GL_FLOAT, 5 * sizeof (GLfloat), &area[3]);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);

  glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);

  /* restore back our matrix stack if needed */
  glPopMatrix();
  glDeleteTextures(1,&textureID);
  glesPrintGLError();
}

 

Thanks for any insight.