Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: DirectDraw and OpenGL

  1. #1
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    303

    DirectDraw and OpenGL

    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.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Austin, TX, USA
    Posts
    143

    Re: DirectDraw and OpenGL

    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?

    <shrug>

    Glossifah

  3. #3
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    303

    Re: DirectDraw and OpenGL

    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?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Austin, TX, USA
    Posts
    143

    Re: DirectDraw and OpenGL

    Ahh, I think I follow you. But, I'm afraid I don't know of a way to do such a thing.

    My apologies...

    Glossifah

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2000
    Location
    Szczecin, Poland
    Posts
    18

    Re: DirectDraw and OpenGL

    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.

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2000
    Location
    spanaway, wa, usa
    Posts
    17

    Re: DirectDraw and OpenGL

    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?
    "...gameplay is what counts..."

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Sep 2000
    Location
    Santa Clara, CA
    Posts
    1,096

    Re: DirectDraw and OpenGL

    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.

    - Matt

  8. #8
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    303

    Re: DirectDraw and OpenGL

    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.

    Psudocode:
    UpdateParticleSceneGDI();
    BltParticleSceneToGL();
    RenderGLScene();
    Swapbuffers();

    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.

  9. #9
    Guest

    Re: DirectDraw and OpenGL

    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!

    pATCheS

  10. #10
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    303

    Re: DirectDraw and OpenGL

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •