Texture and Transparencies

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? :slight_smile:

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

glShadeModel(GL_SMOOTH);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

#ifdef GL_VERSION_1_1
glBindTexture(GL_TEXTURE_2D, TextureName);
#endif

glBegin(GL_QUADS);
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);
glEnd();

glFlush();
glDisable(GL_TEXTURE_2D);

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?).

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.

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.

I’m looking for info on this FBO and pBuffer you speak of.

There’s a reason I’m posting on the beginners forum. :slight_smile:

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.

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…

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?

Here are the essential steps I use to set up a context for drawing to a bitmap.

CDC MemDC;
MemDC.CreateCompatibleDC(NULL);

CreateBitmap(DestBMP, Width, Height, 32);

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

mGLContext.InitContext(MemDC, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI, 32);

mGLContext.InitContext(MemDC, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI, 32);

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) :
http://www.gpgpu.org/developer/
Their FAQ is interesting too :
http://www.gpgpu.org/wiki/FAQ#How_do_I_create_a_GPU_buffer_that_I_can_store_data_in

Will the FBO or pBuffer solution work in systems with no 3D accelerator?

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.
Try GL_REPLACE.

Texture Environments and Texture Functions