SDL->SDL2 w/opengl woes

I went through the hurdle of porting my SDL/OpenGL game to SDL2 with
OpenGL. I’m using the version of SDL2 from the libsdl site, not hg.
I’m running 64bit win7, my app is 32bit.

First, the migration guide in the wiki and this example I stumbled
upon using google: https://gist.github.com/exavolt/2360410 …seem to
be wrong.

I followed those, and ended up with an application that shows a black
screen. Using gDEBugger I found that there’s no context, so I created
one using SDL_GL_CreateContext. Still a black screen, bug gDEBugger
now showed that there’s a context and the textures got loaded fine.
Also, back buffer showed correct stuff.

After more googling I found that I should use SDL_GL_SwapWindow
instead of SDL_RenderPresent, and suddenly I got picture.

The two remaining issues I have are that if I go fullscreen (via
SDL_WINDOW_FULLSCREEN) I get a black screen, but if I alt-tab out and
back, everything works fine(?!), and I can’t seem to get vsync working
(SDL_RENDERER_PRESENTVSYNC, SDL_GL_SetSwapInterval(1)).

There’s probably still other things broken with my port as the game
I’m working on at the moment doesn’t use several features of my
framework (like text input), but these are my experiences so far…

Yeah… that example you linked to is all sorts of wrong. Adding a renderer
(which may or may not use the OpenGL backend on your platform, you
definitely can’t assume) indicates to the library that the application
should use SDL’s 2D drawing/blitting pipeline. If your game is written in
ordinary OpenGL, don’t touch the renderer side of things. All you need to
do is the following:

  • Call SDL_Init() with at least the SDL_INIT_VIDEO flag
  • Lay out your application’s GL context requirements via
    SDL_GL_SetAttribute() (e.g for SDL_GL_CONTEXT_MAJOR_VERSION,
    SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_DEPTH_SIZE, SDL_GL_DOUBLEBUFFER )
  • Call SDL_CreateWindow with SDL_WINDOW_OPENGL as one of the flags
  • Create a context from that window with SDL_GL_CreateContext()

Sorted. Draw stuff with OpenGL as usual, call SDL_GL_SwapWindow() when
you’re done. SDL_GL_SetSwapInterval( 1 ) should enable vsync.On 11 July 2013 00:25, Jari Komppa <jari.komppa at gmail.com> wrote:

I went through the hurdle of porting my SDL/OpenGL game to SDL2 with
OpenGL. I’m using the version of SDL2 from the libsdl site, not hg.
I’m running 64bit win7, my app is 32bit.

First, the migration guide in the wiki and this example I stumbled
upon using google: https://gist.github.com/exavolt/2360410 …seem to
be wrong.

I followed those, and ended up with an application that shows a black
screen. Using gDEBugger I found that there’s no context, so I created
one using SDL_GL_CreateContext. Still a black screen, bug gDEBugger
now showed that there’s a context and the textures got loaded fine.
Also, back buffer showed correct stuff.

After more googling I found that I should use SDL_GL_SwapWindow
instead of SDL_RenderPresent, and suddenly I got picture.

The two remaining issues I have are that if I go fullscreen (via
SDL_WINDOW_FULLSCREEN) I get a black screen, but if I alt-tab out and
back, everything works fine(?!), and I can’t seem to get vsync working
(SDL_RENDERER_PRESENTVSYNC, SDL_GL_SetSwapInterval(1)).

There’s probably still other things broken with my port as the game
I’m working on at the moment doesn’t use several features of my
framework (like text input), but these are my experiences so far…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yeah… that example you linked to is all sorts of wrong. Adding a renderer
(which may or may not use the OpenGL backend on your platform, you
definitely can’t assume) indicates to the library that the application
should use SDL’s 2D drawing/blitting pipeline. If your game is written in
ordinary OpenGL, don’t touch the renderer side of things. All you need to
do is the following:

  • Call SDL_Init() with at least the SDL_INIT_VIDEO flag
  • Lay out your application’s GL context requirements via
    SDL_GL_SetAttribute() (e.g for SDL_GL_CONTEXT_MAJOR_VERSION,
    SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_DEPTH_SIZE,
    SDL_GL_DOUBLEBUFFER )
  • Call SDL_CreateWindow with SDL_WINDOW_OPENGL as one of the
    flags
  • Create a context from that window with SDL_GL_CreateContext()

Sorted. Draw stuff with OpenGL as usual, call SDL_GL_SwapWindow()
when you’re done. SDL_GL_SetSwapInterval( 1 ) should enable vsync.

Thanks. Discarding the renderer fixed the strange problems I was
having. As for vsync, it was probably working, I just had set my
monitor to 120hz =)

Next, I tried to add haptics. I have an old joypad that has rumble
functionality; as a gotcha I haven’t tried if it actually vibrates
with any software in win7 (should get a new, supported pad I
suppose…) However;

SDL_NumHaptics() says 1.
SDL_JoystickIsHaptic() says 1.
SDL_HapticOpenFromJoystick() says NULL.
SDL_HapticOpen(0) returns a pointer, but the device doesn’t vibrate with it.

Am I missing something obvious, or should I just assume the pad
doesn’t work? =) (used SDL_INIT_HAPTIC and SDL_HapticRumbleInit /
SDL_HapticRumblePlay).

The haptic issue sounds like a bug. Can you build a debug version of SDL
and trace into SDL_HapticOpenFromJoystick()?

Also make sure you’re using the very latest RC, since we fixed a bug with
that last week.

Cheers!On Fri, Jul 12, 2013 at 9:44 AM, Jari Komppa <jari.komppa at gmail.com> wrote:

Yeah… that example you linked to is all sorts of wrong. Adding a
renderer
(which may or may not use the OpenGL backend on your platform, you
definitely can’t assume) indicates to the library that the application
should use SDL’s 2D drawing/blitting pipeline. If your game is written in
ordinary OpenGL, don’t touch the renderer side of things. All you need to
do is the following:

  • Call SDL_Init() with at least the SDL_INIT_VIDEO flag
  • Lay out your application’s GL context requirements via
    SDL_GL_SetAttribute() (e.g for SDL_GL_CONTEXT_MAJOR_VERSION,
    SDL_GL_CONTEXT_MINOR_VERSION, SDL_GL_DEPTH_SIZE,
    SDL_GL_DOUBLEBUFFER )
  • Call SDL_CreateWindow with SDL_WINDOW_OPENGL as one of the
    flags
  • Create a context from that window with SDL_GL_CreateContext()

Sorted. Draw stuff with OpenGL as usual, call SDL_GL_SwapWindow()
when you’re done. SDL_GL_SetSwapInterval( 1 ) should enable vsync.

Thanks. Discarding the renderer fixed the strange problems I was
having. As for vsync, it was probably working, I just had set my
monitor to 120hz =)

Next, I tried to add haptics. I have an old joypad that has rumble
functionality; as a gotcha I haven’t tried if it actually vibrates
with any software in win7 (should get a new, supported pad I
suppose…) However;

SDL_NumHaptics() says 1.
SDL_JoystickIsHaptic() says 1.
SDL_HapticOpenFromJoystick() says NULL.
SDL_HapticOpen(0) returns a pointer, but the device doesn’t vibrate with
it.

Am I missing something obvious, or should I just assume the pad
doesn’t work? =) (used SDL_INIT_HAPTIC and SDL_HapticRumbleInit /
SDL_HapticRumblePlay).


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The haptic issue sounds like a bug. Can you build a debug version of SDL
and trace into SDL_HapticOpenFromJoystick()?

Also make sure you’re using the very latest RC, since we fixed a bug with
that last week.

Cheers!

I’ve ordered an xbox controller, as that’s what most people appear to
be using these days. If the same issue appears there, I’ll start
debugging…

In the mean time, yes, the rc zip file had changed, tried with the
latest and the same bug is still there. Wouldn’t it make sense to name
the RCs somehow, just so that people know which version they’re using?
=)

2013/7/12, Jari Komppa <jari.komppa at gmail.com>:

I’ve ordered an xbox controller, as that’s what most people appear to
be using these days. If the same issue appears there, I’ll start
debugging…

Because DirectInput is deprecated but XInput only supports 360
controllers so many recent PC games only support those >_>’ It’s
annoying, especially since it’s hardcoded for those (good luck making
a controller with different inputs!). I think that using raw input
it’s possible to make up for the lack of DirectInput, but I don’t
think developers caught up on that yet.

Oh well, enough off-topic.

Ugh.? Gotta love Microsoft decision-making.

Guy 1: "DirectInput is a good, well-established API that’s actually useful to all sorts of device manufacturers.? But now that we’re in the input device business, that’s bad for us!? What will we do?"
Guy 2: "Oh, that’s easy, we’ll just deal with competition the way we always do.? Create a new, incompatible interface and officially declare the old one to be No Good Anymore."
Guy 1: “…and then make it so that our crappy Dual Shock knockoff is the only thing that supports it.? Brilliant!”________________________________
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Sent: Friday, July 12, 2013 11:32 AM
Subject: Re: [SDL] SDL->SDL2 w/opengl woes

2013/7/12, Jari Komppa <jari.komppa at gmail.com>:

I’ve ordered an xbox controller, as that’s what most people appear to
be using these days. If the same issue appears there, I’ll start
debugging…

Because DirectInput is deprecated but XInput only supports 360
controllers so many recent PC games only support those >_>’ It’s
annoying, especially since it’s hardcoded for those (good luck making
a controller with different inputs!). I think that using raw input
it’s possible to make up for the lack of DirectInput, but I don’t
think developers caught up on that yet.

Oh well, enough off-topic.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How did you get that discussion verbatim? I thought that conversation was
secure!On Fri, Jul 12, 2013 at 2:37 PM, Mason Wheeler wrote:

Ugh. Gotta love Microsoft decision-making.

Guy 1: "DirectInput is a good, well-established API that’s actually useful
to all sorts of device manufacturers. But now that we’re in the input
device business, that’s bad for us! What will we do?"
Guy 2: "Oh, that’s easy, we’ll just deal with competition the way we
always do. Create a new, incompatible interface and officially declare the
old one to be No Good Anymore."
Guy 1: “…and then make it so that our crappy Dual Shock knockoff is the
only thing that supports it. Brilliant!”


From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: SDL Development List
Sent: Friday, July 12, 2013 11:32 AM
Subject: Re: [SDL] SDL->SDL2 w/opengl woes

2013/7/12, Jari Komppa <jari.komppa at gmail.com>:

I’ve ordered an xbox controller, as that’s what most people appear to
be using these days. If the same issue appears there, I’ll start
debugging…

Because DirectInput is deprecated but XInput only supports 360
controllers so many recent PC games only support those >_>’ It’s
annoying, especially since it’s hardcoded for those (good luck making
a controller with different inputs!). I think that using raw input
it’s possible to make up for the lack of DirectInput, but I don’t
think developers caught up on that yet.

Oh well, enough off-topic.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Checked whether I could get sdl2 debug dll built for the heck of it,
and to my utter surprise it compiled on the first try.

Trace:
SDL_SYS_HapticOpenFromJoystick
SDL_SYS_HapticOpenFromDevice8
IDirectInputDevice8_SetCooperativeLevel fails
ret 0x800700aa The requested resource is in use. HRESULT

2013/7/12, Jari Komppa <jari.komppa at gmail.com>:

IDirectInputDevice8_SetCooperativeLevel fails
ret 0x800700aa The requested resource is in use. HRESULT

o_____O

Well at least that probably explains why it’s throwing out an error,
but what else could be hogging the haptic support of the joystick?

As a little addendum, I fired up nfs:hot pursuit, and it manages to
make the pad to vibrate, so it should be possible.On Fri, Jul 12, 2013 at 10:29 PM, Jari Komppa <@Jari_Komppa> wrote:

Checked whether I could get sdl2 debug dll built for the heck of it,
and to my utter surprise it compiled on the first try.

Trace:
SDL_SYS_HapticOpenFromJoystick
SDL_SYS_HapticOpenFromDevice8
IDirectInputDevice8_SetCooperativeLevel fails
ret 0x800700aa The requested resource is in use. HRESULT

How did you get that discussion verbatim? I thought that conversation was secure!

He works for the NSA and has a backdoor into Outlook Express :)On 13/07/2013, at 5:23 AM, Jonathan Dearborn wrote:


john skaller
@john_skaller
http://felix-lang.org