Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Get window device context (hDC) and GL reource context (hGLRC)  (Read 634 times)

0 Members and 1 Guest are viewing this topic.

Aire

  • Newbie
  • *
  • Posts: 2
    • View Profile
I was trying to get this so I can pass them to openxr which needs to know about these handles.

I saw 2 ways of doing this and expected both ways to give me the same address but they don't so I'm a bit confused by this and I'm not sure what I'm missing here.

1st way is to just use wglGetCurrentDC() and wglGetCurrentContext(). I figured this would be fine since all of this is done on the main thread during initialization anyway but I wanted to be sure that I was grabbing the context of the window generated by SFML.


So I started to see if I could do it this way (2nd way)
sf::RenderWindow window(...);
auto win_handle  = window.getSystemHandle();
auto win_context = GetDC(win_handle ); // the hDC address I get back from doing this does not match the address I get back from wglGetDeviceContext

// Im not really sure how to get to the hGLRC since it is private.

 

Is there a way to get both the hDC and hGLRC from SFML, even it's like what I'm trying to do in the code part?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Get window device context (hDC) and GL reource context (hGLRC)
« Reply #1 on: July 18, 2023, 11:00:12 pm »
I kind of question whether you can really intermix OpenXR and the graphics module, which still uses OpenGL 2.1 or requires a compatibility context.

Probably the easiest approach would be to create your own window with some simple Win32 API code. If you then still want to use SFML for say the input handling, you could construct an SFML window from the window handle.

I briefly checked with binary1248, who (re)wrote most of the OpenGL context handling code, and he said that you can't really get the hGLRC from SFML.
You might be able to use wglGetCurrentContext if you do everything on the main thread and have SFML never do any context switches, but that's really just a stretch.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything