glCompressedTexImage2D doesn't work?

I’m trying to load in compressed texture data, my program worked before when I was using uncompressed bitmap data, but now that I’m trying to load in compressed data all my sprites just render as black. And I’m not finding anything in glGetError().

My loading thread is separate from my rendering thread, but I don’t think that’s relevant because the same setup worked with the bitmap data, and each thread has it’s own GL context.

The code I’m using to load it is this:


fseek(file, offset[i], SEEK_SET);

uint8_t compression_type;
uint32_t length;
fread(&compression_type, 1, 1, file);
fread(&length, 4, 1, file);
length = byte_swap(length);

std::vector<uint8_t> image_data(length, 0);

fread(image_data.data(), 1, length, file);

glGenTextures(1, &texture[i]);
glBindTexture(GL_TEXTURE_2D, texture[i]);

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

if(i >= 2)
{
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ALPHA);
}

switch(compression_type)
{
case 1:
	glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, width, height, 0, length, image_data.data());
	break;
case 3:
	glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, width, height, 0, length, image_data.data());
	break;
case 5:
	glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, width, height, 0, length, image_data.data());
	break;
default:
	throw std::runtime_error("unknown compression type");
	break;
}

Is there anything wrong here? Alternately: is there some dummy data I can load into the vector that will produce a texture that’s just red or something? I don’t think the loading protocol is wrong, because I can load the images using squish::decompress, then rendering it with Qt by transposing it onto a QImage.

The image was invalid due to an endian issues.