Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading BMP image with SDL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Johnell   Members   -  Reputation: 352

Like
0Likes
Like

Posted 26 April 2012 - 06:14 AM

I am trying to load a .bmp image with SDL but i'm not sure were to put the image so it can be found. When I add the file in the project folder and run this code I get the following output in the console: /Users/user/Library/Developer/Xcode/DerivedData/SDLExperiment-dsfnjwhgojekaeehoaipimlpnoqb/Build/Products/Debug
The image could not be located due to the following error: Couldn't open hello.bmp



#include <SDL.h>
#include <iostream>
using namespace std;
int main( int argc, char* args[] )
{
	SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
	char title[50] = "";
  
SDL_Init (SDL_INIT_EVERYTHING);

screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

hello = SDL_LoadBMP("hello.bmp");
	if (hello == NULL)
{
		cout << getcwd(title, 120) << endl;
  cout << "The image could not be located due to the following error: "
		<< SDL_GetError() << endl;
	  
	 return 1;
}
SDL_BlitSurface(hello, NULL, screen, NULL);
SDL_Flip(screen);
  
SDL_Delay(2000);

SDL_FreeSurface(hello);

SDL_Quit();

return 0;
}


Sponsor:

#2 Dunge   Members   -  Reputation: 405

Like
0Likes
Like

Posted 26 April 2012 - 08:49 AM

This is not a question about SDL or about loading bitmap but more about directory structure. I'm not used to Xcode and I find your project path to be quite long, but usually the application will search the file in a relative path to the working directory. Under Windows, when you double click an .exe, the working directory is the same as the executable. Under visual studio when you run the application from the IDE it's by default the directory of the .sln file, but can be modified in the project settings. I'm guessing it's about the same for Xcode.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS