Before reading all this and getting lost, my main question is how to unpack a single array of pixels and explain how open gl reads this data. (my background is not in C ++, but mostly python)
Your help is greatly appreciated.
im using maya (a 3d program) that has a MImage class for obtaining pixel image data. the return result is one array in which every 4 elements are RGBA this is what I need to unpack
pixels = [255, 255, 0, 255, 255, 255, 0, 255] //two yellow pixels and it keeps going with this pattern
The following code creates a 256 x 256 image with 4 channels
unsigned int size = 256;
unsigned int depth = 4;
float color[3] = {1, 1, 0};
unsigned char *pixels = new unsigned char[size * size * depth];
for(unsigned int i = 0; i < size; i += depth){
MScriptUtil::setUcharArray(pixels, i+0, (int)floorf(color[0] * 255.0f + 0.5f));
MScriptUtil::setUcharArray(pixels, i+1, (int)floorf(color[1] * 255.0f + 0.5f));
MScriptUtil::setUcharArray(pixels, i+2, (int)floorf(color[2] * 255.0f + 0.5f));
pixels[i + 3] = 255;
}
Studying this problem, I came across this fragment (which creates a validation template) that works with the last block of code and displays with what I'm trying to do
static GLubyte checkImage[256][256][4];
int i, j, c;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
this array becomes (instead of 256x256 I made it 2x2)
[[[255, 255, 255, 255], [255, 255, 255, 255]], [[255, 255, 255, 255], [255, 255, 255, 255]]]
with this I set GL_UNPACK_ALIGNMENT to 1 and everything works
, gl
,
glDisable ( GL_LIGHTING );
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &glTextureObject);
glBindTexture (GL_TEXTURE_2D, glTextureObject);
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_REPLACE);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);