Results 1 to 2 of 2

Thread: glCompressedTexImage2D doesn't work?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2017
    Posts
    11

    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:

    Code :
    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.

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2017
    Posts
    11
    The image was invalid due to an endian issues.

Similar Threads

  1. second UBO doesn't work
    By mlkn_mlkn in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-11-2015, 12:34 PM
  2. int vertex doesn't work
    By CodeAllergy in forum OpenGL: GLSL
    Replies: 3
    Last Post: 02-14-2012, 04:42 PM
  3. Why doesn't my shared lib work?
    By BBB in forum OpenGL: Linux
    Replies: 4
    Last Post: 05-24-2005, 06:47 AM
  4. It doesn't work...
    By GunCraP in forum OpenGL: User Software
    Replies: 0
    Last Post: 01-03-2003, 01:46 AM
  5. Why doesn't this work
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-11-2002, 02:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean