Note that there are some explanatory texts on larger screens.

plurals
  1. PODDS texture transparency rendered black Opengl
    primarykey
    data
    text
    <p>I am currently trying to render textured objects in Opengl. Everything worked fine until I wanted to render a texture with transparency. Instead of showing the the object transparent it just rendered in total black.</p> <p>The method fo loading the texture file is this:</p> <pre><code>// structures for reading and information variables char magic[4]; unsigned char header[124]; unsigned int width, height, linearSize, mipMapCount, fourCC; unsigned char* dataBuffer; unsigned int bufferSize; fstream file(path, ios::in|ios::binary); // read magic and header if (!file.read((char*)magic, sizeof(magic))){ cerr&lt;&lt; "File " &lt;&lt; path &lt;&lt; " not found!"&lt;&lt;endl; return false; } if (magic[0]!='D' || magic[1]!='D' || magic[2]!='S' || magic[3]!=' '){ cerr&lt;&lt; "File does not comply with dds file format!"&lt;&lt;endl; return false; } if (!file.read((char*)header, sizeof(header))){ cerr&lt;&lt; "Not able to read file information!"&lt;&lt;endl; return false; } // derive information from header height = *(int*)&amp;(header[8]); width = *(int*)&amp;(header[12]); linearSize = *(int*)&amp;(header[16]); mipMapCount = *(int*)&amp;(header[24]); fourCC = *(int*)&amp;(header[80]); // determine dataBuffer size bufferSize = mipMapCount &gt; 1 ? linearSize * 2 : linearSize; dataBuffer = new unsigned char [bufferSize*2]; // read data and close file if (file.read((char*)dataBuffer, bufferSize/1.5)) cout&lt;&lt;"Loading texture "&lt;&lt;path&lt;&lt;" successful"&lt;&lt;endl; else{ cerr&lt;&lt;"Data of file "&lt;&lt;path&lt;&lt;" corrupted"&lt;&lt;endl; return false; } file.close(); // check pixel format unsigned int format; switch(fourCC){ case FOURCC_DXT1: format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break; case FOURCC_DXT3: format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break; case FOURCC_DXT5: format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break; default: cerr &lt;&lt; "Compression type not supported or corrupted!" &lt;&lt; endl; return false; } glGenTextures(1, &amp;ID); glBindTexture(GL_TEXTURE_2D, ID); glPixelStorei(GL_UNPACK_ALIGNMENT,1); unsigned int blockSize = (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ? 8 : 16; unsigned int offset = 0; /* load the mipmaps */ for (unsigned int level = 0; level &lt; mipMapCount &amp;&amp; (width || height); ++level) { unsigned int size = ((width+3)/4)*((height+3)/4)*blockSize; glCompressedTexImage2D(GL_TEXTURE_2D, level, format, width, height, 0, size, dataBuffer + offset); offset += size; width /= 2; height /= 2; } textureType = DDS_TEXTURE; return true; </code></pre> <p>In the fragment shader I just set the gl_FragColor = texture2D( myTextureSampler, UVcoords )</p> <p>I hope that there is an easy explanation such as some code missing. In the openGL initialization i glEnabled GL_Blend and set a blend function.</p> <p>Does anyone have an idea of what I did wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload