The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL 1.2x to SDL2 - need some help with OpenGL
Dominus


Joined: 13 Oct 2009
Posts: 127
Hi,
someone had started to port Exult to SDL2 and it is somewhat working except for our OpenGL scaler. That guy stopped working on it and I wondered if you could help me moving on with this.
The problem is in https://github.com/rofl0r/exult/blob/master/imagewin/imagewin.cc (it's a mirror - our SVN is on SF and that is just now down)
beginning with line 766:
Code:
#ifdef HAVE_OPENGL
      // Get info. about video.
      const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
      if (!vinfo) {
         cout << "SDL_GetVideoInfo() failed: " << SDL_GetError()
              << endl;
         return false;
      }
      // Set up SDL video flags.
      int video_flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER |
                        SDL_HWPALETTE | SDL_RESIZABLE |
                        (fullscreen ? SDL_FULLSCREEN : 0);
      // Can surface be in video RAM?
      if (vinfo->hw_available)
         video_flags |= SDL_HWSURFACE;
      else
         video_flags |= SDL_SWSURFACE;
      if (vinfo->blit_hw) // Hardware blits?
         video_flags |= SDL_HWACCEL;
      // Want double-buffering.
      SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
      // Allocate surface.
      int hwdepth = vinfo->vfmt->BitsPerPixel;
      // +++++For now create 8-bit surface
      //   to avoid crashing places we
      //   haven't converted yet.
      if ((display_surface = inter_surface = SDL_SetVideoMode(w, h,
                                             hwdepth, video_flags)) != 0 &&
              (draw_surface = paletted_surface = SDL_CreateRGBSurface(
                                  SDL_SWSURFACE, w / scale, h / scale,
                                  8, 0, 0, 0, 0)) != 0) {
         inter_width = w;
         inter_height = h;
         game_width = draw_surface->w;
         game_height = draw_surface->h;
         //show_scaled = &Image_window::show_scaledOpenGL;
         return true;
      } else {
         cerr << "Couldn't allocate surface: " <<  SDL_GetError() << endl;
         free_surface();
      }
#else
      cerr << "OpenGL not supported" << endl;

#endif


The errors I get start of course with SDL_VideoInfo etc...
Code:
imagewin.cc:768:9: error: unknown type name 'SDL_VideoInfo'
                const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
                      ^
imagewin.cc:768:32: error: use of undeclared identifier 'SDL_GetVideoInfo'
                const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
                                             ^
imagewin.cc:775:21: error: use of undeclared identifier 'SDL_OPENGL'
                int video_flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER |
                                  ^
imagewin.cc:776:37: error: use of undeclared identifier 'SDL_RESIZABLE'
                                  SDL_HWPALETTE | SDL_RESIZABLE |
                                                  ^
imagewin.cc:780:19: error: use of undeclared identifier 'SDL_HWSURFACE'
                        video_flags |= SDL_HWSURFACE;
                                       ^
imagewin.cc:784:19: error: use of undeclared identifier 'SDL_HWACCEL'
                        video_flags |= SDL_HWACCEL;
                                       ^
imagewin.cc:792:42: error: use of undeclared identifier 'SDL_SetVideoMode'
                if ((display_surface = inter_surface = SDL_SetVideoMode(w, h

I saw the migration guide but my limited coding skills left me without any clue.

Can anyone help me out there?
Thanks and take care!
SDL 1.2x to SDL2 - need some help with OpenGL
Joseph Carter


Joined: 20 Sep 2013
Posts: 279
On Fri, Jan 09, 2015 at 11:21:47PM +0000, Dominus wrote:
Quote:
Hi,
someone had started to port Exult to SDL2 and it is somewhat working except for our OpenGL scaler. That guy stopped working on it and I wondered if you could help me moving on with this.

Email's a poor compiler, but I'll see if I can give you a push in the
right direction…


Quote:
The problem is in https://github.com/rofl0r/exult/blob/master/imagewin/imagewin.cc (it's a mirror - our SVN is on SF and that is just now down)
beginning with line 766:

Code:
#ifdef HAVE_OPENGL

This you can keep. :D


Quote:
// Get info. about video.
const SDL_VideoInfo *vinfo = SDL_GetVideoInfo();
if (!vinfo) {
cout << "SDL_GetVideoInfo() failed: " << SDL_GetError()
<< endl;
return false;
}

Obviously this function no longer exists. It's been replaced by
something that is only relevant to using SDL's 2D renderer. Which is
to say what you're doing with it below here isn't really how you were
supposed to be using it.


Quote:
// Set up SDL video flags.
int video_flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER |
SDL_HWPALETTE | SDL_RESIZABLE |
(fullscreen ? SDL_FULLSCREEN : 0);
// Can surface be in video RAM?
if (vinfo->hw_available)
video_flags |= SDL_HWSURFACE;
else
video_flags |= SDL_SWSURFACE;
if (vinfo->blit_hw) // Hardware blits?
video_flags |= SDL_HWACCEL;
// Want double-buffering.
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

int window_flags = SDL_WINDOW_OPENGL |
SDL_WINDOW_RESIZABLE;
if (fullscreen) {
window_flags |= SDL_WINDOW_FULLSCREEN;
}

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);


Quote:
// Allocate surface.
int hwdepth = vinfo->vfmt->BitsPerPixel;
// +++++For now create 8-bit surface
// to avoid crashing places we
// haven't converted yet.
if ((display_surface = inter_surface = SDL_SetVideoMode(w, h,
hwdepth, video_flags)) != 0 &&
(draw_surface = paletted_surface = SDL_CreateRGBSurface(
SDL_SWSURFACE, w / scale, h / scale,
8, 0, 0, 0, 0)) != 0) {
inter_width = w;
inter_height = h;
game_width = draw_surface->w;
game_height = draw_surface->h;
//show_scaled = &Image_window::show_scaledOpenGL;
return true;
} else {
cerr << "Couldn't allocate surface: " << SDL_GetError() << endl;
free_surface();
}

// Allocate window and context.
SDL_Window *window = SDL_CreateWindow("Exult", 0, 0, w, h,
window_flags);
if (window != NULL) {
SDL_GLContext glcontext =
SDL_GL_CreateContext(window);
if (glcontext != NULL) {
// Set those width/height vars if you
// need them

return true;
} else {
cerr << "Couldn't allocate OpenGL "
"context: " << SDL_GetError() <<
endl;
SDL_DestroyWindow(window);
}
} else {
cerr << "Couldn't allocate a window: " <<
SDL_GetError() << endl;
}


Quote:
#else
cerr << "OpenGL not supported" << endl;

#endif

Again, this part is fine. ;)


Quote:
The errors I get start of course with SDL_VideoInfo etc...

Code:
[.. old functions not found errors ..]
Quote:


I saw the migration guide but my limited coding skills left me without any clue.

Can anyone help me out there?
Thanks and take care!

See if the above helps give you a starting place. Basically you
never really needed a surface for the OpenGL screen in SDL 1.2, but
you kind of got one anyway. In SDL 2.0, you don't. And there's a
lot less need for querying the video hardware because a window is now
a proper window and not just a box trying to pretend to be a screen.

This may not provide exactly what you intend in all cases and there
could be a gaping syntax error in the above given that I'm typing
bleary-eyed into an email and not a source code file.

Joseph

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Dominus


Joined: 13 Oct 2009
Posts: 127
Thanks a lot. With this it at least compiled.
Crashes now with a segmentation fault when I choose the OpenGL scaler Smile

I'll see if I can find out more. Your post gave me a big starting point!
Dominus


Joined: 13 Oct 2009
Posts: 127
hmm, with your changes it tries to create a new window instead of using the existing one.
The big problem is how we did the OpenGL thing. We implemented it as a scaler, instead of as a renderer and that's probably just biting us in the behind now Smile
SDL 1.2x to SDL2 - need some help with OpenGL
Joseph Carter


Joined: 20 Sep 2013
Posts: 279
On Sat, Jan 10, 2015 at 10:10:08AM +0000, Dominus wrote:
Quote:
hmm, with your changes it tries to create a new window instead of using the existing one.
The big problem is how we did the OpenGL thing. We implemented it as a scaler, instead of as a renderer and that's probably just biting us in the behind now Smile

Your game is 2D? That makes some of what I saw make more sense now.

SDL does OpenGL _for you_ using its renderer. And Direct3D too. You
don't have to touch OpenGL for it to work.

Joseph

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Dominus


Joined: 13 Oct 2009
Posts: 127
thanks again, so I guess we'll need to deactivate this for SDL2