Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing the alpha channel correctly in OpenGl
    primarykey
    data
    text
    <p>After loading an image, I have the individual bytes for each channel loaded into an array of unsigned characters. It's passed to a function that projects it as a texture onto a quad. Everything seems to work properly other than the alpha channel, which shows up as the background color. I'm using OpenGL to draw the image. Would I benefit by adding a layering mechanism? Also, how can I achieve the transparent effect that I want?</p> <p>Note: This is the code that I have a feeling needs changed: </p> <pre><code>void SetUpView() { // Set color and depth clear value glClearDepth(1.f); glClearColor(1.f, 0.f, 0.f, 0.f); // Enable Z-buffer read and write glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); glEnable (GL_BLEND); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // Setup a perspective projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.f, 1.f, 1.f, 500.f); }; </code></pre> <p>Also, here's the code to render the quad.</p> <pre><code>void DrawTexturedRect(RectBounds *Verts, Image *Texture) { glBindTexture(GL_TEXTURE_2D, GetTextureID(Texture)); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelZoom(1, -1); glBegin(GL_QUADS); glTexCoord2f(0.0, 1.0); glVertex3f(Verts-&gt;corners[0].x, Verts-&gt;corners[0].y, Verts-&gt;corners[0].z); glTexCoord2f(1.0, 1.0); glVertex3f(Verts-&gt;corners[1].x, Verts-&gt;corners[1].y, Verts-&gt;corners[1].z); glTexCoord2f(1.0, 0.0); glVertex3f(Verts-&gt;corners[2].x, Verts-&gt;corners[2].y, Verts-&gt;corners[2].z); glTexCoord2f(0.0, 0.0); glVertex3f(Verts-&gt;corners[3].x, Verts-&gt;corners[3].y, Verts-&gt;corners[3].z); glEnd(); }; </code></pre> <p>The Image class holds an array of unsigned chars, obtained using OpenIL.</p> <p>Relevant code:</p> <pre><code>loaded = ilLoadImage(filename.c_str()); ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); unsigned char *bytes = ilGetData(); //NewImage is an instance of an Image. This is returned and passed to the above function. NewImage-&gt;data = bytes; </code></pre> <p><a href="http://img375.imageshack.us/img375/9585/j120192.png" rel="nofollow noreferrer">Problem http://img375.imageshack.us/img375/9585/j120192.png</a></p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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