iDevGames Forums

Full Version: Undefined symbol & getpixel
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Jones

I was googling to find a method to get pixel colors so I could test for colorkeys in my collision system.

The command I found was getpixel(). I quickly slapped it into version3 of my code:

Code:
#include <SDL/sdl.h>

/*    A structure type for holding 2D pixel addresses.    */
typedef struct {
    int pixelX;
    int    pixelY;
} col_pixelCoord;

int r, g, b;

/*    Collision function; makes and tests the pixel charts.    */
int testPixelCollision(SDL_Surface *col_Surface_1, SDL_Surface *col_Surface_2, int col_red, int col_green, int col_blue) {
    
    //    Is there a collision? (1 = yes, 0 = no).
    int col_isThereCollision = 0;
    
    //    Arrays for holding each surface's pixel data.
    col_pixelCoord col_pixelData_surface1[col_Surface_1->w * col_Surface_1->h];
    col_pixelCoord col_pixelData_surface2[col_Surface_2->w * col_Surface_2->h];

    //    SDL_rect objects for each surface.
    SDL_Rect col_rect_surf1;
    SDL_GetClipRect(col_Surface_1, &col_rect_surf1);
    SDL_Rect col_rect_surf2;
    SDL_GetClipRect(col_Surface_2, &col_rect_surf2);
    
    /*    Calculate surface 1's map.    */
        //    Starting values for the collumn and row holders.
        int col_i = 0;
        int col_u = 0;
        //    Pixel count, starts at one so as not to fill slot 0 of the array.
        int col_pixelsCounted_surf1 = 0;
        //    Take a collumn.
        for (; col_i < col_Surface_1->w;) {
            //    Take the item from the row of that collumn.
            for (; col_u < col_Surface_1->h;) {
                Uint32 pixel = getpixel(col_Surface_1, col_i, col_u);
                SDL_GetRGB(pixel, col_Surface_1->format, &r, &b, &g);
                
                if (r != col_red && g != col_green && b != col_blue) {
                /*    Important bit:    Storing the pixel coordinates.    */
                col_pixelsCounted_surf1++;
                col_pixelData_surface1[col_pixelsCounted_surf1].pixelX = col_i + col_rect_surf1.x;
                col_pixelData_surface1[col_pixelsCounted_surf1].pixelY = col_u + col_rect_surf1.y;
                //    If we're at the last item of that row of that collumn...
                if (col_u == col_Surface_1->h) {
                    col_i++;    //    Next collumn.
                    col_u = 0;    //    First item of that row of the next collumn.
                }
                else {
                    col_u++;
                }
                }
            }
        }
        
    /*    Calculate surface 2's map.    */
        //    Starting values for the collumn and row holders.
        int col_o = 0;
        int col_p = 0;
        //    Pixel count, starts at one so as not to fill slot 0 of the array.
        int col_pixelsCounted_surf2 = 0;
        //    Take a collumn.
        for (; col_o < col_Surface_2->w;) {
            Uint32 pixel = getpixel(col_Surface_2, col_i, col_u);
            SDL_GetRGB(pixel, col_Surface_2->format, &r, &b, &g);

            
            //    Take the item from the row of that collumn.
            for (; col_p < col_Surface_2->h;) {
            
                if (r != col_red && g != col_green && b != col_blue) {
                /*    Important bit:    Storing the pixel coordinates.    */
                col_pixelsCounted_surf2++;
                col_pixelData_surface2[col_pixelsCounted_surf2].pixelX = col_o + col_rect_surf2.x;
                col_pixelData_surface2[col_pixelsCounted_surf2].pixelY = col_p + col_rect_surf2.y;
                //    If we're at the last item of that row of that collumn...
                if (col_o == col_Surface_2->h) {
                    col_o++;    //    Next collumn.
                    col_p = 1;    //    First item of that row of the next collumn.
                }
                else {
                    col_p++;
                }
                }
            }
        }

    /*    Ok, the big important bit; Cross testing the pixel charts.    */
        //    Reuse some counters.
        col_i = 1;
        col_o = 1;
        while (col_i <= col_pixelsCounted_surf1) {
            while (col_o <= col_pixelsCounted_surf2) {
                if (col_pixelData_surface1[col_i].pixelX == col_pixelData_surface2[col_i].pixelX && col_pixelData_surface1[col_o].pixelY == col_pixelData_surface2[col_o].pixelY) {
                    col_isThereCollision = 1;
                    goto col_finishCollisionTest;
                }
                col_o++;
            }
            col_i++;
        }

    col_finishCollisionTest:
    return col_isThereCollision;
}

But the compiler returns:

Undefined symbol _getpixel!

Does that mean that getpixel is a user made function that I do not have installed? Or perhaps it is just some silly mistake in my code.

Thanks for the help!
getPixel is something you would have to write. It's not part of libSDL. Although not a difficult thing to find in libsdl doc wiki. Cut and paste into your program somewhere.

http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access
If you were using sensible warning flags the compiler would have told you Wink

Jones

OneSadCookie Wrote:If you were using sensible warning flags the compiler would have told you Wink

*bookmarked*
OneSadCookie Wrote:If you were using sensible warning flags the compiler would have told you Wink
Off-Topic: I already do all of those except for the newline EOF. Is there an Xcode setting to add them? I don't get [edit](as in understand)[/edit] newline EOFs yet... uneducated... lost... help!
just put those flags into the "extra warning flags" section of your target settings
I'm sorry, that didn't communicate well. Let's try it again Smile

I already have all those other flags in my `other warning flags'. What I mean is, adding -Wnewline-eof, as per your tips page, throws up the red flags on all the files. How do I correct that and add newlines to the ends of those files to get rid of the error flags? Is there an Xcode setting to do that?
no, Xcode won't automatically add them. You can do it yourself, manually, or you could use eg. perl to fix up all your existing files.
Reference URL's