problem in using with MFC

Hai,
i am using openGL in VC++. In onPaint before do the openGL drawing i am loading some DTED map using some other library with the same HDC object. Then i am drawing something using openGL API then i called SwapBuffer(hDc) then the previous drawings were erased and only the drawings which is drawn using openGL API is remaining.
If i didn’t put the SwapBuffer(hDc) then the openGL drawings are not rendered. How can i get the combined output.

Regards
Radhakrishnan

You cannot reliably mix GL with GDI rendering. I suggest you copy the GDI rendered elements to a texture, and draw that as background, then render GL elements on top of that. Or ideally, re-implement the GDI rendering routines with GL, if possible.

In other words, get the DC, get the DIB handle, read back the bitmap, copy that bitmap data directly to texture with glTexImage2D. Then render a full screen GL_QUADS with this texture. Then draw your GL elements on top as usual.

If you use GL2.0, you don’t have to worry about non-square textures, if its < GL2.0, you can allocate a bigger-than-necissary texture with power of two size, and use only part of it. This may complicate the bitmap copy process a bit, but this may already be slightly difficult because DIBs may have 4-byte padding for each row of pixels (like the BMP image file format).

On a side note, it is possible however to draw GDI elements on top of GL (after calling SwapBuffers iirc), but this is also not recommended and generally unreliable (flicker may occur with double-buffered frame buffers). Last time I tried this was in Win95/98 days, it may not even work under XP anymore and even less likely under Vista.

So generally: avoid mixing GDI with GL like the pest.

Hope that helps.