Hi,
I’m making my first attempt to learn the SDL. ?All I want to do is put up a
background image as a test. ?All indications are that everything works (No
errors returned) except that the screen just goes black. ?Any help would be
appreciated.
Thanks
Here is the code:
/***************************************************************************
? ? ? ? ? ? ? ? ? ? ? ? ? main.cpp ?- ?description
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-------------------
? ? begin ? ? ? ? ? ? ? ?: Tue Dec 17 11:07:10 PST 2002
? ? copyright ? ? ? ? ? ?: © 2002 by Eric L. Damron
? ? email ? ? ? ? ? ? ? ?: @Eric_Damron
?***************************************************************************/
/***************************************************************************
?* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *
?* ? This program is free software; you can redistribute it and/or modify ?*
?* ? it under the terms of the GNU General Public License as published by ?*
?* ? the Free Software Foundation; either version 2 of the License, or ? ? *
?* ? (at your option) any later version. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *
?* ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *
?***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream.h>
#include <stdlib.h>
#include <SDL/SDL.h>
int ?initVideo(SDL_Surface *screen)
{
? /* Initialize SDL’s video system and check for errors */
? if (SDL_Init(SDL_INIT_VIDEO) != 0) {
? ? printf(“Unable to initialize SDL: %s \n”, SDL_GetError());
? ? return 1;
? }
? /* Make sure SDL_Quit gets called when the program exits! */
? atexit(SDL_Quit);
? /* Attempt to set a 1024x768 hicolor video mode */
? screen = SDL_SetVideoMode(1024, 768, 16, SDL_FULLSCREEN);
? if (screen == NULL) {
? ? printf(“Unable to set video mode: %s\n”, SDL_GetError());
? ? return 1;
? }
? /* If we got this far, everything worked */
? return 0;
}
int loadSplash(SDL_Surface *screen)
?{
? SDL_Surface *splashScreen;
? SDL_Rect src, dest;
? splashScreen =
SDL_LoadBMP("/home/eric/Projects/KDevelop/fuzzy/graphics/SplashScreen.bmp");
? if (splashScreen == NULL) {
? ? printf(“Unable to load bitmap.\n”);
? ? ?return 1;
? }
? src.x = 0;
? src.y = 0;
? src.w = splashScreen->w;
? src.h = splashScreen->h;
? dest.x = 0;
? dest.y = 0;
? dest.w = splashScreen->w;
? dest.h = splashScreen->h;
? SDL_BlitSurface(splashScreen, &src, screen, &dest);
? SDL_UpdateRect(screen, 0, 0, 0, 0);
? SDL_Delay(3000);
? SDL_FreeSurface(splashScreen);
? return 0;
}
int main(int argc, char *argv[])
{
? SDL_Surface *screen;
? initVideo(screen);
? loadSplash(screen);
? return 0;
}