Installing SDL_image & SDL_mixer

Member
Posts: 312
Joined: 2006.10
Post: #1
Hey, I'm aving a prbem installing those two. I downloaded the two frameworks and copied them to both /system/library/frameworks and /Library/Frameworks... and when I go to compile it says the file don't exist. I did add them to the project though... Is there something else I need todo?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You should download the development packages for each, which include the header files.

You should never modify anything in /System/, either.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #3
ok, thanks Smile

Where can I find them if they aren't listed here: http://www.libsdl.org/projects/SDL_image/
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #4
There is only one binary version of SDL_image and SDL_mixer for Mac OS X. You won't find a special development version like you can find for Linux and Windows. The single Mac OS X version should work.

To get SDL_image code to compile with Xcode, I had to add the search path to the SDL_image header files. The Header Search Paths setting is part of the Search Paths build settings collection. The path should be the following:

/Library/Frameworks/SDL_image.framework/Headers

In addition to adding the SDL_image and SDL_mixer frameworks to your project, you must also add the SDL framework to your project. Make sure you included the SDL_image and SDL_mixer header files in your source code.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #5
Thanks, it works now Smile
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #6
Hey again, I thought I would use this thread instead of starting a new thread... For some reason this code doesn't play the images... I'm using the Lazy Foo tutorials to learn SDL so I can port a game I never finished using Lua (on the PSP with Luaplayer). Any help would be highly appreciated, thanks! Grin
Code:
/* Simple program:  Create a blank window, wait for keypress, quit.

   Please see the SDL documentation for details on using the SDL API:
   /Developer/Documentation/SDL/docs.html
*/

#include "SDL.h"
#include "SDL_image/SDL_image.h"
#include <OpenGL/gl.h>
#include <math.h>
#include <stdio.h>    
#include <stdlib.h>
#include <strings.h>

const int SCREEN_WIDTH = 480;
const int SCREEN_HEIGHT = 272;
const int SCREEN_BPP = 32;

SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

//The event structure
SDL_Event event;

/*class PLAYER {
public:*/
    SDL_Surface *imageLeft = NULL;
    SDL_Surface *imageRight = NULL;
    int x = 220;
    int y = 10;
//};

//PLAYER player;

SDL_Surface *load_image( char *filename )
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image using SDL_image
    loadedImage = IMG_Load( filename );
    
    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old image
        SDL_FreeSurface( loadedImage );
    }
    
    //Return the optimized image
    return optimizedImage;
}

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

    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}
    
    
/*void InitGL();
void Display();

void InitGL() {
    //glClearColor( 0, 0, 0, 0 );
    
    glEnable(GL_TEXTURE_2D);                        // Enable Texture Mapping ( NEW )
    glShadeModel(GL_SMOOTH);                        // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                    // Black Background
    glClearDepth(1.0f);                            // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST);                        // Enables Depth Testing
    glEnable (GL_LIGHTING); //enable the lighting
    glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
    glDepthFunc(GL_LEQUAL);                            // The Type Of Depth Testing To Do
    //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    
    
}

void Display() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);            // Clear Screen And Depth Buffer
    glLoadIdentity();                            // Reset The Current Matrix
    glTranslatef(0.0f,0.0f,-5.0f);                        // Move Into The Screen 5 Units
    glPushMatrix();

    

    
    SDL_GL_SwapBuffers();
}    */
  
int main(int argc, char *argv[])
{
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;    
    }
    
    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
    
    //If there was in error in setting up the screen
    if( screen == NULL )
    {
        return 1;      //Set the window caption
    }
        
    SDL_WM_SetCaption( "Super Monkey Poop Fight", NULL );
    
    // Load Images
    /*player.*/imageLeft = load_image( "images/monkey1standl.png" );
    /*player.*/imageRight = load_image( "images/monkey1standr.png" );
    background = load_image( "images/background.png" );
    
    while(1) {
        
        //If there's an event to handle
        if( SDL_PollEvent( &event ) )
        {
            //If a key was pressed
            if( event.type == SDL_KEYDOWN )
            {
                //Set the proper text
                switch( event.key.keysym.sym )
                {
                    case SDLK_LEFT:
                        /*player.*/x -= 4;
                        apply_surface( /*player.*/x, /*player.*/y, /*player.*/imageLeft, screen );
                        break;
                    case SDLK_RIGHT:
                        /*player.*/x += 4;
                        apply_surface( /*player.*/x, /*player.*/y, /*player.*/imageRight, screen );
                        break;
                    case SDLK_q:
                        //Free the image
                        SDL_FreeSurface( imageLeft );
                        SDL_FreeSurface( imageRight );
                        SDL_FreeSurface( background );
                        
                        //Quit SDL
                        SDL_Quit();     
                        break;
                }
            }
            
        }
        
        //Apply the background to the screen
        apply_surface( 0, 0, background, screen );

        SDL_Flip( screen );
    }
    
    return 0;
    
}

BTW, I tried using a class, but it gave me errors, so I commented out any class related stuff so I can back later to use them... So it may look messy Rasp
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #7
The probable cause of your problem is that your program can't find the image files. SDL sets the initial working directory to the directory above the application bundle. Unless your images folder is in the same folder as the application bundle, the program will fail to load the images. You have three ways to solve the problem.

  1. Move your images folder to the same folder as the application bundle. You wouldn't want to do this for a shipping game, but it will work as a temporary solution if you want to test your code.
  2. Change the calls to load_image so it points to the location of your images folder. Mac OS X applications usually store image files in the Resources folder inside the application bundle. You would have to change your calls to load_image to something like YourGame.app/Contents/Resources/images/ImageFile.png.
  3. Modify the setupWorkingDirectory function in the file SDLMain.m so the working directory is set to where your images folder is.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #8
Thanks, but I tried the 2nd optio and it didn't work... I have this now
Code:
/*player.*/imageLeft = load_image( "thing.app/Contents/Resources/images/monkey1standl.png" );
    /*player.*/imageRight = load_image( "thing.app/Contents/Resources/images/monkey1standr.png" );
    background = load_image( "thing.app/Contents/Resources/images/background.png" );
Do I have to change something in the load_image func?
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #9
Check to see if the images folder is in the application bundle. Control-click your application in the Finder and choose Show Package Contents to look inside the bundle. If the images folder is inside the Resources folder, then I'm not sure what the problem is.

If there is no images folder in the application bundle, the folder is not getting copied when Xcode builds your project. Remove the images folder from your project and add it again. When adding the folder, a sheet will open. Make sure you select the radio button that says Create Folder References for any added folders.

If the images folders is inside the Resources folder of the Groups and Files list, it should be copied to the application bundle's Resources folder when Xcode builds the project. To make sure, click the disclosure triangle next to the name of your target in the Groups and Files list. Click the disclosure triangle next to Copy Bundle Resources. Make sure the images folder is there. If it's not, select the images folder from the Groups and Files list and drag it to Copy Bundle Resources.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Trouble using SDL_image with XCode 3.2.3 Snow Leopard code4fun 1 4,336 Sep 22, 2010 10:47 PM
Last Post: OneSadCookie
  SDL_image and bmp loading Duane 13 8,534 Dec 21, 2009 09:14 AM
Last Post: Skorche
  SDl_mixer and image bronxbomber92 3 3,509 Dec 15, 2006 12:27 PM
Last Post: bronxbomber92
  Using SDL_mixer to play ogg sound (not music) effects kordova 3 6,366 Sep 1, 2006 12:29 PM
Last Post: kordova
  SDL_mixer exception at Mix_PlayMusic kordova 2 3,426 Sep 1, 2006 04:09 AM
Last Post: kordova