Jump to content
  • Advertisement
Sign in to follow this  
RetroBilly

OpenGL How can I create context without a window?

This topic is 2601 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a video game library which is not intended to handle the process of creating a window or other platform s[color="#333333"][font="arial, helvetica, clean, sans-serif"]pecific tasks. The idea worked fine when I was using DirectX but DirectX only works on windows so I've had to move to OpenGL. Now I have to create a hidden window so that I can create a context from it. I could include glut into my project to handle this but that will be the only thing I use it for and it seems slightly ghetto to me.[/font]
[color="#333333"][font="arial, helvetica, clean, sans-serif"] [/font]
[color="#333333"][font="arial, helvetica, clean, sans-serif"]To me it seems like there is no reason I should have to create a window just to create a context. I'm not even using the window for anything, it's just kinda sitting in the background hidden doing nothing...[/font]

Share this post


Link to post
Share on other sites
Advertisement

I'm writing a video game library which is not intended to handle the process of creating a window or other platform s[color="#333333"][font="arial, helvetica, clean, sans-serif"]pecific tasks. The idea worked fine when I was using DirectX but DirectX only works on windows so I've had to move to OpenGL. Now I have to create a hidden window so that I can create a context from it. I could include glut into my project to handle this but that will be the only thing I use it for and it seems slightly ghetto to me.[/font]
[color="#333333"][font="arial, helvetica, clean, sans-serif"] [/font]
[color="#333333"][font="arial, helvetica, clean, sans-serif"]To me it seems like there is no reason I should have to create a window just to create a context. I'm not even using the window for anything, it's just kinda sitting in the background hidden doing nothing...[/font]


And it seems you even don't need a graphics API, if you are sitting in the background doing nothing. :)


Let's be more serious. What's the purpose of your code if you don't have a window to draw on it?

You cannot create a context without a window. Furthermore, the pixel format must be identical in all windows drawn in with the same GL context.

Share this post


Link to post
Share on other sites
If you are creating a 3D helping library, just let the user pass it's windows handle as a parameter to your function creating the api context and use it there.

Share this post


Link to post
Share on other sites

If you are creating a 3D helping library, just let the user pass it's windows handle as a parameter to your function creating the api context and use it there.


Exactly what I originally did but I needed to share the resources between the windows so I just created a context using a hidden window and used wglMakeCurrent with the hDC of the window I'm rendering to and the hRC created from the hidden window. This works great but again I don't understand why I need the hidden window to create the context in the first place?

Share this post


Link to post
Share on other sites
Think of yourself as an artist.

The paint is the OpenGL primitives, the canvas is the window.

You can't create a masterpiece without a canvas.

Share this post


Link to post
Share on other sites

Think of yourself as an artist.

The paint is the OpenGL primitives, the canvas is the window.

You can't create a masterpiece without a canvas.


How can you consider something a canvas when it's invisible? I never draw to the window and only use it to create a context to act as a container to hold my resources...

Share this post


Link to post
Share on other sites
I was able to create a context without a window using CreateCompatibleDC(NULL) but it's only OpenGL 1.1. Can someone explain why it's only version 1.1 and is there anyway I can change the version?

Share this post


Link to post
Share on other sites

I was able to create a context without a window using CreateCompatibleDC(NULL) but it's only OpenGL 1.1. Can someone explain why it's only version 1.1 and is there anyway I can change the version?


You've got version 1.1 because you don't have a hardware acceleration. So, you can't change that version.


All your drawing code, if there is any, will be at least two orders of magnitude slower. And, yes, there is nothing beyond GL 1.1 in that case.

[quote name='Katie']wglCreateContextAttribsARB possibly?[/quote]

wglCreateContextAttribsARB enables creating GL 3.0+ contexts, and it also requires a handle to a DC (hence a window). Further more, it requires an old GL context in order to be created.

Share this post


Link to post
Share on other sites
Try CreateDC(L"DISPLAY", NULL, NULL, NULL). Not sure if it's guaranteed to work though. Works for me on Windows 7. With an NVidia card the context cannot be made current on that DC, but a pixel format can be set and a GL context created which can later be made current on a window DC. When I try with an ATI card it can also be made current on that DC without a window.
Then again on the ATI card CreateCompatibleDC(NULL) works just as well for me. You should definitely create a window to avoid things not working on some drivers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!