Page 1 of 1

[solved]sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 1:42 am
by short
Solution: make sure friend copies all .dll files in the sdl_image zip file and not just the required ones to make it compile. =)



My friend and I are working on a project together. A simple pong game. We wanted to figure out how to work with networking, and get a pong-over-the-internet-clone working.

I wrote a bunch of code, shows a background, some paddles, and a ball. Easy enough. We have a SVN set up, so when he gets home he gets a copy and follows the same steps I do to get the file compiled.

He runs it, none of the images are showing up. None of them. We have the exact same code, the exact same setup. Except his is 64bit windows 7, and I have 32bit windows xp.

The images show up fine on my machine (win xp), but they do not work on his (64bit windows 7). Anybody have any ideas? I think it might be a bug, but I have no idea in what. Especially since windows7 is brand new. I'll post my main.cpp file:

Code: Select all

#include "NetPong.h"

using namespace std;


// DEFINES
#define IMAGE_BACKGROUND ".\\content\\images\\background.png"
#define IMAGE_LEFTPADDLE ".\\content\\images\\red side.png"
#define IMAGE_RIGHTPADDLE ".\\content\\images\\blue side.png"
#define IMAGE_BALL ".\\content\\images\\ball.png"

/* CONSTANTS */
	 const int SCREEN_WIDTH = 640;
	 const int SCREEN_HEIGHT = 480;
	 const int SCREEN_BPP = 32; //Bits per pixel, we are using 32 bit color.
	 const int NUM_PADDLES = 2;
	 const double PADDLE_SPEED = 1.725;


/* DATA STRUCTURES */
	 SDL_Event event; 


//The surfaces that will be used 
	 SDL_Surface *background = NULL; 
	 SDL_Surface *screen = NULL; 

	 

	 GameObject * paddleArray[NUM_PADDLES];
	 GameObject * ball;


int main(int argc, char* args[])
{
	 bool quit = false;
	 paddleArray[0] = new GameObject(0,(SCREEN_HEIGHT / 2), IMAGE_LEFTPADDLE);
	 paddleArray[1] = new GameObject((SCREEN_WIDTH - 50), (SCREEN_HEIGHT / 2), IMAGE_RIGHTPADDLE);
	 ball = new GameObject((SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2), IMAGE_BALL); 
	 if( init() == false)	  // initialize SDL subsystem, if they failed exit with error code 0x01
	 {
		  return 1;
	 }
	 if(load_Files() == false) // if failed exit with error code 0x01
	 {
		  return 1;
	 }
	 while(quit == false)
	 { 
		  apply_surface(0, 0, background, screen); // ALWAYS FIRST!!!!! 
		  apply_surface((int)ball->getX(), (int)ball->getY(), ball->getSurface(), screen);
		  apply_surface((int)paddleArray[0]->getX(), (int)paddleArray[0]->getY(), paddleArray[0]->getSurface(), screen );
		  apply_surface((int)paddleArray[1]->getX(), (int)paddleArray[1]->getY(), paddleArray[1]->getSurface(), screen);

		  //If there's an event to handle
		  if( SDL_PollEvent( &event ) )
		  { 
			   if( event.type == SDL_QUIT ) //if the user clicks the little X in the upper right corner.
			   {
					quit = true;
			   }
		  }

		  //Get the keystates
		  Uint8 *keystates = SDL_GetKeyState( NULL );

		  //If LEFT
		  if( keystates[ SDLK_UP] )
		  {
			   paddleArray[1]->setY(paddleArray[1]->getY() - PADDLE_SPEED);
		  }
		  if( keystates[ SDLK_DOWN ] )
		  {
			   paddleArray[1]->setY(paddleArray[1]->getY() + PADDLE_SPEED);
		  }

		  if( keystates[ SDLK_w] )
		  {
			   paddleArray[0]->setY(paddleArray[0]->getY() - PADDLE_SPEED);
		  }

		  if( keystates[ SDLK_s] )
		  {
			   paddleArray[0]->setY(paddleArray[0]->getY() + PADDLE_SPEED);
		  }


		  //Swap the current and back buffer.
		  if( SDL_Flip( screen ) == -1 )
		  {
			   return 1;
		  }
	 }

	 cleanUp();

	 return 0; // no errors
}

void cleanUp()
{
	 //Free the surfaces 
	 SDL_FreeSurface( background ); 

	 SDL_Quit();

}

bool init()
{
	 if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) 
	 { 
		  return false; 
	 }
	 //set up the screen.
	 screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

	 if(screen == NULL)
	 {
		  return false;
	 }
	 SDL_WM_SetCaption("NetPong", NULL); //Set the window caption:
	 return true;
}

bool load_Files()
{
	 //Load the images 
	 background = load_image(IMAGE_BACKGROUND);

	 paddleArray[0]->setSurface(load_image(IMAGE_LEFTPADDLE));
	 paddleArray[1]->setSurface(load_image(IMAGE_RIGHTPADDLE));

	 ball->setSurface(load_image(IMAGE_BALL));

	 return true;
}

SDL_Surface *load_image( std::string filename ) 
{
	 SDL_Surface* loadedImage = NULL; //Temporary storage for the image that's loaded
	 SDL_Surface* optimizedImage = NULL;  //The optimized image that will be used 

	 //Load the image 
	 loadedImage = IMG_Load( filename.c_str() ); 

	 if( loadedImage != NULL ) 
	 {
		  optimizedImage = SDL_DisplayFormat( loadedImage ); //Create an optimized image 
		  SDL_FreeSurface( loadedImage );//Free the old image 

		  //Map the color key
          Uint32 colorkey = SDL_MapRGB( optimizedImage->format, 0xFF, 0x00, 0xFF );

          SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey ); // set the color key
	 } 
	 return optimizedImage; //Return the optimized image 
} 

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) 
{
	 SDL_Rect offset; //Make a temporary rectangle to hold the offsets 
	 
	 offset.x = x; //Give the offsets to the rectangle 
	 offset.y = y;

	 SDL_BlitSurface( source, NULL, destination, &offset ); //Blit the surface 
} 

Re: sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 2:46 am
by K-Bal
Is he running the program from his IDE? Maybe the execution directory is the project folder and you have all your images in the /bin folder?

Ciao,
Marius

Re: sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 11:40 am
by short
We are both using MVC++, it wouldn't be changing the folder locations unfortunately. Were using the svn so it should all be the exact same thing.

I'll have him triple check though.

Re: sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 12:00 pm
by MarauderIIC
Check your working directories?

Re: sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 1:24 pm
by K-Bal
MarauderIIC wrote:Check your working directories?
That is what I meant ;)

Re: sdl, windows 7 weirdness?

Posted: Wed May 13, 2009 11:21 pm
by short
If the working directory for both of us is blank (msdn says the default is the directory the executable is in), and if it works on mine, would it not be the same for him?

Re: sdl, windows 7 weirdness?

Posted: Thu May 14, 2009 10:02 am
by K-Bal
short0014 wrote:If the working directory for both of us is blank (msdn says the default is the directory the executable is in), and if it works on mine, would it not be the same for him?
In MSVC it should be the project directory.

Re: sdl, windows 7 weirdness?

Posted: Thu May 14, 2009 3:36 pm
by MarauderIIC
If you run your program using the command line, the images have to be in the same dir as the executable. If you run the program from the ide, the images have to be in the project directory with the source, I think.