View Full Version : Texture and Transparencies

Jack Dingler
05-19-2006, 01:33 PM
I've made wonderful progress in getting label text working in 3D space in my app.

I'm rendering to a bitmap attached to a DC in Windows XP.

After finding an article in the FAQ, I learned that texture transparencies and depth testing is supported as expected under Windows in OpenGL 1.1

So I followed the instructions that said to render the texture last and disable the depth test. It worked! With some tinkering, but not quite... I rendered the texture first.

Now something is broken, I don't see the difference in the code. But my alpha bits are now ignored. The transparent portions of my texture are now visible and covers the image it rests on top of.

I need in this case, for the text in the texture to overlay my mesh objects when in front of them. The textures are positioned in 3D space. But I don't want to see the text bordered in the white field, as it's current displaying.

Anyone have any pointers on troubleshooting this or caveats to performing this function? Please? :)

My setup looks like this with some code removed for brevity.



#ifdef GL_VERSION_1_1
glBindTexture(GL_TEXTURE_2D, TextureName);

glTexCoord3d(0.0, 0.0, 0.0); glVertex3d(x1, y1, z);
glTexCoord3d(0.0, 1.0, 0.0); glVertex3d(x1, y2, z);
glTexCoord3d(1.0, 1.0, 0.0); glVertex3d(x2, y2, z);
glTexCoord3d(1.0, 0.0, 0.0); glVertex3d(x2, y1, z);


05-19-2006, 03:26 PM
Never played with rendering to a bitmap. Is there an advantage to this over, say, rendering to a FBO or a Pbuffer?

That would be my recommendation, using a RTT target, but I'm sure you have a good reason for doing it your way (some GDI dependencies?).

Jack Dingler
05-22-2006, 08:14 AM
The final output has to be a bitmap in order to pump it into a database field.

We're printing dynamic images of parts for reporting.

The final output must be a bitmap.

I am open to suggestions as to other ways to get there.

Jack Dingler
05-22-2006, 08:28 AM
Oh yeah, we need to hit 600 dpi with images currently up to 4500 X 1800 resolution. And we don't want to render where the user can see it. It's better to give them a progess bar, than have thousands of images flash in their face.

If there's a way to use a more advanced version of OpenGL than what windows provides, and still render to a bitmap, then that interests me.

Jack Dingler
05-22-2006, 08:48 AM
I'm looking for info on this FBO and pBuffer you speak of.

There's a reason I'm posting on the beginners forum. :)

Jack Dingler
05-23-2006, 01:21 PM
At this point, my transparencies aren't even working when rendering in windows.

I'm finding this frustrating as even backing my code up to versions that worked and were tested, previously is not solving the problem.

I'm not sure I understand how using pBuffers or FBOs affects blending of transparent textures.

I'm experiencing one of those moments when I'm sure I missing something simple, and just don't see it.

Jack Dingler
05-23-2006, 02:21 PM
And that's all it was. Something stupid.

I was setting my texture GL_RGB instead of GL_RGBA. but in a portion of code that was out of sight...

05-25-2006, 03:05 PM
I'm very curious how you manage the output of your rendered bitmap. If you've already discussed this elsewhere, or have an outside resource that you feel is helpful, any URLs you offer will be helpful. I too am a newbie and am interested in rendering my scenes to files (and/or database tables) and am a bit put off at the thought of dumping a buffer from glReadPixels() into a graphics library -- are you using a 3rd-party library like DevIL?

Jack Dingler
05-25-2006, 03:26 PM
Here are the essential steps I use to set up a context for drawing to a bitmap.


CreateBitmap(DestBMP, Width, Height, 32);

CBitmap * pOldBitmp = (CBitmap *) MemDC.SelectObject(&DestBMP);


05-25-2006, 04:00 PM

the "support gdi" part means that you are only using software rendering. So you do not use your 3D accelerator at all...
Doing everything on the CPU avoid the bandwidth requirement of glReadPixels(), but it is often better to let the videocard do its part.

Some good resources for rendering to a texture and retrieving it (explaining FBO and pbuffers) :
Their FAQ is interesting too :
http://www.gpgpu.org/wiki/FAQ#How_do_I_create_a_GPU_buffer_that_I_can_store_ data_in

Jack Dingler
05-26-2006, 08:08 AM
Will the FBO or pBuffer solution work in systems with no 3D accelerator?

Serge K
05-26-2006, 08:36 PM
Lots of advices, I see... :rolleyes:

Why do you set texture function to GL_DECAL?
It uses texture alpha to blend the texture with fragment color.

Texture Environments and Texture Functions (http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node88.html)