views:

1155

answers:

3

I'm trying to work out a way to mix OpenGL rendering and GDI in Windows. Previously I've been rendering my OpenGL contents into a framebuffer object, extracting it and then blitting it into the windows GDI graphics context and then drawing my GDI stuff over the top. This is really crippling the framerate.

I'd like to do the opposite to what I am doing now, so my OpenGL rendering is done directly to the window and then I render GDI stuff to a bitmap which is uploaded to a texture and then overlayed using a quad. The GDI stuff doesn't change all that much so I don't need to redraw it every frame, I can just cache the texture.

I can almost get it working, the problem is that I can't seem to get the correct alpha values from the GDI bitmap so text and lines get horrible jaggies.

Does anyone have any useful resources for how to do this? Is it even possible to get GDI or GDI+ to write to the alpha channel in the way I need?

+2  A: 

I think it'd be easier if you just used raw OpenGL to render rather than the GDI. Just create some wrapper functions and call them instead of the GDI.

Daemin
A: 

Is all that really necessary? You ought to be able to just use GDI functions to draw on the same device context as your OpenGL.

MandyK
A: 

How about using stenciling. Replicate your texture in the stencil buffer. Use GL_NOTEQUAL as the test function with a reference value equal to the texture's background value. Render OpenGL stuff first, then enable stenciling, then render your textured rectangle.

You don't specify if this is a 2D or 3D problem. Jaggies may be a depth problem in a 3D world where everything is almost in the same plane. If your working in 3D make sure the textured rectangle is in front of everything else or modify the z-buffer.

jeffD