SDL 1.2x to SDL2 - need some help with OpenGL

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!

Thanks a lot. With this it at least compiled.
Crashes now with a segmentation fault when I choose the OpenGL scaler :slight_smile:

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

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.

JosephOn Sat, Jan 10, 2015 at 10:10:08AM +0000, Dominus wrote:

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 :slight_smile:

Heyya,

If you were using OpenGL for scaling in the way that I?m thinking, i.e.: a small resolution like 384x224 upscaled to something more modern like 768x448 (x2) or 1152x672 (x3), you might be interested in knowing that SDL_RenderSetLogicalSize and SDL_RenderSetScale can help accomplish much the same. I did so myself when moving my game from SDL1 to SDL2.

I set the logical size to the original resolution used in the game (384x224), with a scale factor of 2, 2 (x2) or 3, 3 (x3) with a window size to match whatever the result of the original resolution multiplied by the scale factor is.

In addition, I explicitly set the renderer’s scale quality to “nearest”, instead of “linear” (anti-aliasing), and load the pre-scaled images of the appropriate scale factor into memory for use by the applicable game assets. This step can be skipped or tweaked further, depending on how picky you are on preserving the original image quality. In my case, this was preserving the scale2x filtering (of which I had the option of doing at run-time, or from disk).

Cheers,
Jeffrey Carpenter <@Jeffrey_Carpenter>

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1572 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20150114/d508190d/attachment-0001.bin