Sign in to follow this  
lserlohn

OpenGL how to init OpenGL in a none-windowed program?

Recommended Posts

how to init OpenGL in a none-windowed program? I want to make a OpenGL program without a window, that is Rendering off screen and exporting to a bmp file. But I don't know how to init OpenGL in this none-windowed program. In a windowed program,there are always using CreateWindowEx() to create a window and then get back the HWND, and then : hDC = GetDC(HWND); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); But in my program ,there isn't any window,so how do I get the HWND hDC and hRC? Thanks.

Share this post


Link to post
Share on other sites
Haven't done this, but I guess you could try to create a memoryDC using CreateCompatibleDC, create a bitmap, call SelectObject to bind the DC to the bitmap and then use that DC to call wglCreateContext.

Share this post


Link to post
Share on other sites
Yes, you have to create Rendering Context with an own pixelformat with PFD_DRAW_TO_BITMAP flag. Then create a compatible DC and a bitmap and select it for the DC. Then you can render your scene directly to the memory. Maybe you have to know that it won't use any hardware acceleration, it will be done by CPU.

Share this post


Link to post
Share on other sites
Thanks, but this job is too costly, I really need hardware accelerate.

Is there a way to use hardware accelerate without creating a window?

or Is there any better idea? I want to "pack" the openGL program into a COM object.

Share this post


Link to post
Share on other sites
Would it be OK for your program to use a hidden window? So, create a window as usual, but never call ShowWindow on it? Then, use glReadPixels to read from the frame buffer and write that to a file.
(Again, I'm just guessing if this would work..)

Share this post


Link to post
Share on other sites
I did this a while ago and I don't totally remember what I did but from what I recall you definitely had to create a window and I think you had to realize it. After that you could hide it with no worries.

Share this post


Link to post
Share on other sites
Quote:
Original post by GKW
I did this a while ago and I don't totally remember what I did but from what I recall you definitely had to create a window and I think you had to realize it. After that you could hide it with no worries.

This seems familiar also to me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this