Does anyone know if you can use the device context that can be extracted from a DirectDraw surface as a rendering context for OpenGL? I’m trying to do double-buffered rendering using both OpenGL and something else since some functionality I need (plotting LOTS of individual pixels very quickly) is too slow in OpenGL. But so far all I’ve found out how to do it to use GDI to plot the pixels but you can’t use GDI on the backbuffer apparently so it flickers.
The registers on a hardware accelerated card are shared between the RC’s of DirectX and OpenGL, no? Wouldn’t that be more problematic than sticking to one API?
What do you mean? The thing is, I already have some code written that makes HEAVY use of individual pixel plotting and from what I’ve been told, OpenGL’s pixel plotting is really slow. However, I’ve found that I need to plot the pixels to another surface (bitmap?) and then blt it to my OpenGL scene. So, I could continue using GDI or DirectDraw if there was a way to do a fast blt from one DC to OpenGL’s RC’s backbuffer. Is this possible? If not, is there even a slow way to do it?
Ahh, I think I follow you. But, I’m afraid I don’t know of a way to do such a thing.
OpenGL rendering to a DirectDraw surface is possible with some hardware but may be not on other. Video drivers don’t have to support this. So you cant do the OpenGL rendering to
a DirectDraw surface, even if it works on your particular system. What you can do, is to create a DIB section GDI object, render to it, do any direct bit access you want then blit this DIB section to screen using normal GDI blitting functions.
I read in one of the posts that you can grab a unsigned char pointer of the current opengl buffer and draw to that buffer using the pointer and just blit it to the screen or something like that? Does anyone know what im talking about?
OpenGL simply doesn’t mix with other APIs very well. You can mix OpenGL with GDI, but you have to be very careful of the synchronization hazards (you must glFinish OpenGL before using GDI, and you must GdiFlush GDI before using OpenGL). Otherwise, there is absolutely no guarantee of any particular ordering of the results.
Two obvious options would be drawing points or using DrawPixels.
Actually, I’m not necessarily wanting to render OpenGL stuff to another surface, but rather render to a DirectDraw surface (or DC) using GDI or something and then merge (blt) that with my OpenGL rendered scene. Example: I constantly update a surface by writing pixels to it representing particles. But I also want to render some spaceships and stuff using OpenGL. So, I want to be able to blt what I’ve got on the other surface to the OpenGL RC or color buffer and then do my OpenGL rendering over that.
So, as you can see, I want to be able to copy my GDI rendered scene to OpenGL’s RC’s backbuffer and then render with OpenGL over that and then swap the buffers for flickerless dispaly.
Here’s what I would do: Use DirectDraw to create a surface, get a handle to it, have OpenGL draw to that, use the GDI to draw the particle scene, and blit it to the screen surface as necessary. Almost instant flicker-free high-speed method of using three totally different APIs. Hard to combine APIs, huh? Personally, I’d use OpenGL for everything, because it’s easier to get higher quality graphics, and you can do alpha-blending for the particles mcraighead, I never knew OpenGL could be used to draw individual pixels; I’ll have to chack that out!
Thanks alot! But one question still remains: how do I set OpenGL up to render to a DirectDraw surface’s DC? I would think it would be the same as a regular DC since it’s the same thing but I’m brand-spankin’ new to this and I’ve only seen how to set OpenGL up by requesting DC’s from Windows by specifying pixelformats etc… What do you do with the whole pixelformat thing or does it just work the same way? Also, I guess it would be handled a little differently than you would handle it in a normal case since you wouldn’t be using an attached backbuffer. Instead what you’re saying is to render to a single buffer using OpenGL and then Blt the contents of that buffer to my primary buffer? That sounds like it would work. So, actually, now that I think of it, I wouldn’t even need to use a DirectDraw surface with OpenGL, I’d just need a single-buffered DC for OpenGL, another DC for my particle stuff, and then my primary buffer for the actual output. I’d build my particle scene, render my OpenGL scene, and then merge the two to the primary buffer. Does all this sound about right to you? Thanks again!
hehe sorry bud, I can’t help you with that one. I’ve seen it done before, but I haven’t actually done it, as I had no need to use GDI and OpenGL at the same time. Go to www.voodoovb.com (?) and check out the sample code. It’s all in VB, so if necessary, use a text editor. All the files except for .frx and maybe some others are in ASCII format.
oops that’s not the right VooDoo-VB. Go to voodoovb.cjb.net, that’s the one. Go to the tutorials section. You can find (almost) anything relating to DirectX, like DirectSound, DirectDraw, the works.
PS - Anyone here play Descent 3 on PXO? I’m trying to find more good pilots to fly against
Thanks! I visited that first one and it didn’t quite fit your description.
hehe i know. I had to do a search to find the right one. They have lots more tutorials than they used to, but still pretty good. I’m about to get out of this class (i’m in school ) so I’ll type @ home.