Ok is see what you mean here, but when I read in the image data from the texture file I use the code below to read and bind the image data to a texture object.
void read_rgb_24bit(FILE *s, int width, int height)
{
unsigned char rgb;
unsigned char temp;
int bread;
int i;
int size = widthheight;
rgb = malloc_test(sizeof(int) * size * 3, "Texture Data", TextureMemTag);
if (rgb == NULL) return 0;
bread = fread (rgb, sizeof (unsigned char), size * 3, s);
if (bread != size * 3)
{
free_tag(TextureMemTag);
return 0;
}
for (i = 0; i < size * 3; i += 3)
{
temp = rgb[i];
rgb[i] = rgb[i + 2];
rgb[i + 2] = temp;
}
TextureFormat = GL_RGB;
bind_texture(1, width, height, TextureFormat, rgb);
}
void bind_texture(int id, int pix_width, int pix_height, GLenum format,
unsigned char data)
{
/ dull openGl stuff */
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
/* scaling a streching */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/* bind the texture */
glTexImage2D(GL_TEXTURE_2D, 0, format, pix_width, pix_height,
0, format, GL_UNSIGNED_BYTE, data);
}
So my image data is in an unsigned char *rgb not a 2D char array. Maybe I don’t understand how the image data is actually stored/used by openGL but how to I get from an unsigned char *rgb to the ‘origImage[X][y]’ in your code ? Then how to I get back to the unsigned char *data for binding from each ‘subImage[x][y]’ ?
I think that this is the bit I’m struggling to understand. Then if you add in the need to scale/pad the ‘origImage’ data if the texture is not a power of 2, I’m really confused ?
Any further help is appreciated,
Thanks
Ewan