[Gambas-user] gb3: gb.opengl will not render alpha channel of 2D texture

Kevin Fishburne kevinfishburne at ...1887...
Mon Aug 1 11:30:16 CEST 2011


On 08/01/2011 04:47 AM, Benoît Minisini wrote:
>>> If, in GltextureMapping.c:238:
>>> 	glTexImage2D(GL_TEXTURE_2D, VARGOPT(Level, 0), 3, image->width,
>>> 	
>>> 		image->height, VARGOPT(Border, 0), format, GL_UNSIGNED_BYTE,
>>> 		image->data);
>>>
>>> I replace the "3" by "4", as it is in line 225, I get the transparency.
>>>
>>> According to the documentation, this number is the number of color
>>> components in the texture, which should be 4 for RGBA.
>>>
>>> I suggest that this number should be 3 if the image format is RGB or BGR,
>>> and 4 if the image format is RGBA, RGBX, BGRA, tec.
>>>
>>> Another point. I opened the file GLUtextureImage.c (searching for
>>> GL.TexImage2D), and I noticed that GLUBUILD1DMIPMAPS use IMAGE_get to
>>> read its image argument (which does error checking), but not
>>> GLUBUILD2DMIPMAPS, which should lead to possible segfaults...
>> Interesting observations Benoît. I did get a segfault using
>> Glu.Build2DMipmaps(), though I corrected it by moving the call. Was a
>> strange error among many, which I'm still trying to correct. Mostly I
>> think it's my faulty logic.
>>
>> Tomek, who is having some trouble mailing the mailing list lately,
>> helped me get the alpha channel working correctly. I don't understand
>> the logic, but enabling the gb.opengl.glu component and adding the line
>> "Glu.Build2DMipmaps(t1)" to the end of the texture setup code enabled
>> the alpha channel. The final code looks like this:
>>
>> ‘ Set up texture.
>> Gl.BindTexture(Gl.GL_TEXTURE_2D, textures[0])
>> Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR)
>> Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR)
>> Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP)
>> Gl.TexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP)
>> Gl.TexImage2D(t1)
>> Glu.Build2DMipmaps(t1)
>>
>> No idea why the segfault occurred, but am glad I could work around it.
> Glu.Build2DMipmaps() could segfault if it receives a NULL image. Anyway, in
> revision #3958, you don't have to do all that trick: image alpha channel
> should be correctly taken into account in OpenGL APIs.

Awesome, thank you. I'll compile the newest revision and give it a try. 
I finally subscribed to the svn mailing list...love it.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271





More information about the User mailing list