Hi, I’m making a splashscreen class for myself. And now i’ve run into a
problem with centering the image on the monitor. Now the sdl window appears
where my windowmanager puts it. How do I control its position?
I tried putting (x,y) coordinates in dstrect for SDL_BlitSurface(), but the
window still appears at the same location, but my image doesn’t show at all.
I presume that it’s in the center of the screen, but the window is still at
(0, 0).
I’ll paste my code here:
SplashScreen::SplashScreen(char *fileName)
{
SDL_Surface *splash = IMG_Load(fileName);
if(!splash) {
cerr << "Error while loading image: " << SDL_GetError() << endl;
return;
}
SDL_Surface *mscreen = SDL_SetVideoMode(splash->w, splash->h, 16,
SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_NOFRAME);
if(!mscreen) {
cerr << "Error while creating video surface: " << SDL_GetError() << endl;
return;
}
int wm_w, wm_h = 0;
SDL_SysWMinfo info;
if(SDL_GetWMInfo(&info)) {
#ifdef LINUX
wm_w = DisplayWidth(info.info.x11.display, 0);
wm_h = DisplayHeight(info.info.x11.display, 0);
#endif
#ifdef WIN32
// TODO: need to get windows specific code for screen size
#endif
}
SDL_Rect dstrect;
dstrect.x = wm_w / 2;
dstrect.y = wm_h / 2;
SDL_BlitSurface(splash, NULL, mscreen, &dstrect);
SDL_Flip(mscreen);
SDL_Delay(3000);
SDL_FreeSurface(splash);
SDL_FreeSurface(mscreen);
}
O.–
“There are 10 types of people - those who know binary and those who don’t.”