I am sorry for making another reply in my topic but I think it is better than making another topic. If this does not get noticed I guess I should make another topic.
So I tried to load some monochrome bitmaps on a texture.
I read the references on glPixelStore(), glTexImage2D,glPixelTransfer and glPixelMap. I thought I should use a Buffer Object binding GL_PIXEL_UNPACK Buffer to do things the “right” way. But I cant seem to make it work correctly and I have no idea what the problem might be.
So basically here is the code.
//t is the data buffer, just 0s and 1s interchanging to see if it prints
unsigned short t[2] = {0xAA,0xAA};
//this is the pixel map
GLushort monoPixelMap[2] = { 0,255};
GLuint bName[1];
glGenBuffers(1, bName);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,bName[0]);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 4, monoPixelMap, GL_STATIC_DRAW);
//is needed when we use GL_BITMAP to say which side the LSB is
glPixelStorei(GL_PACK_LSB_FIRST,true);
//mapsize here needs to be a power of two or else we get GL_INVALID_VALUE
glPixelMapusv(GL_PIXEL_MAP_I_TO_R,2,0);
glPixelMapusv(GL_PIXEL_MAP_I_TO_G,2,0);
glPixelMapusv(GL_PIXEL_MAP_I_TO_B,2,0);
//I don't think this is needed acording to reference of glPixelTransfer
//glPixelTransferi(GL_MAP_COLOR,true);
//tells how many bits OR bytes? to add when the offset changes (if it's like GL_INDEX_SHIFT) it should be bits.
glPixelTransferi(GL_INDEX_OFFSET,16);
glBindTexture(GL_TEXTURE_2D, texture[0]);
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,1, 4, 4, 0,GL_COLOR_INDEX,GL_BITMAP, t);
It does not work, it prints a whole white texture. I tried putting glGetError() after every glCall and checking it and the only place where I get an error is at glTexImage2D and that’s a GL_INVALID_OPERATION.
I guess it must have to do with the fact that I have a GL_UNPACK_PIXEL_BUFFER bound and I am not using it correctly somehow.
Could be one of the following :
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the
GL_PIXEL_UNPACK_BUFFER target and the buffer object’s data store is currently mapped.
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the
GL_PIXEL_UNPACK_BUFFER target and the data would be unpacked from the buffer
object such that the memory reads required would exceed the data store size.
GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to the
GL_PIXEL_UNPACK_BUFFER target and data is not evenly divisible
into the number of bytes needed to store in memory a datum indicated by type.
That’s all. Any assistance would be greatly appreciated.