I’d first like to say hello to everyone before I start off. So…hello!
Note, this part is just me describing my story before this problem, so you don’t have to read.
I’ve used SDL 1.2 on a previous game of mine a year ago that turned out great ( for my first game with it of course ). After which I made the switch to SFML 1.6 because from reading the documentation of it I could have a more object-oriented library to work with. I enjoyed using it aside from certain limitations that SDL didn’t have. I would have probably kept using it due to me spending several days working on my own back-end for a game with it. After I finished days worth of work and wanted to start using what I made to create a level for the game however, I noticed problems such as the screen going black upon start-up when I used a custom view on the window. I checked my logic many times and saw no problems, so I thought it wise to post the relevant code to the SFML forums and describe my problem. Nobody could find a problem with my code, so they said to upgrade to SFML 2.0 and it might solve the issue. After spending another day or two re-writing my code with SFML 2.0 it
still wouldn’t work, and nobody else would respond to my posts so I gave up with SFML for the time being. Now I’m going back to SDL and am trying to re-write my back-end with it.
#End description.
I tried working through Lazy Foo’s SDL tutorials to get SDL set-up and tested before I start working with it. However, I couldn’t get an SDL_Surface to blit to the screen even with using his code to do so. Here’s the tutorial if it helps anyone:
http://lazyfoo.net/SDL_tutorials/lesson01/index2.php
The code compiled perfectly as well as linking, but my issue is that it never blitted to the screen as it did when I last did this tutorial a year ago. I thought I should check to see if perhaps the image was returning as NULL, which it was. My slightly changed code is here:
Code:
/This source code copyrighted by Lazy Foo’ Productions (2004-2012)
and may not be redestributed without written permission./
//Include SDL functions and datatypes
#include “SDL.h”
#include
int main( int argc, char* args[] )
{
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
//Load image
hello = SDL_LoadBMP( "hello.bmp" );
//Determins if the surface pointer isn't pointing to a memory
//loaded image.
if( hello == NULL )
{
std::cout << "Image is null." << std::endl;
}
//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );
//Update Screen
SDL_Flip( screen );
//Pause
SDL_Delay( 2000 );
//Free the loaded image
SDL_FreeSurface( hello );
//Quit SDL
SDL_Quit();
return 0;
}
It will not blit to the screen, and it does do the if loop I added into the original Lazy Foo code from lesson 1. I’m using SDL-1.2.14 on a Windows XP SP3 machine with my IDE and compiler being Visual Studio 2008 ( not Express ). Like most people posting their problems here say; I’d be grateful if someone could help me out.