PDA

View Full Version : Undefined symbol & getpixel


Jones
2006.05.18, 04:06 PM
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:

#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!

Zekaric
2006.05.18, 05:01 PM
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

OneSadCookie
2006.05.18, 10:12 PM
If you were using sensible warning flags (http://tips.onesadcookie.net/tips/published/GCC+Warning+Flags) the compiler would have told you ;)

Jones
2006.05.20, 12:39 PM
If you were using sensible warning flags (http://tips.onesadcookie.net/tips/published/GCC+Warning+Flags) the compiler would have told you ;)

*bookmarked*

AnotherJake
2006.05.21, 03:28 AM
If you were using sensible warning flags (http://tips.onesadcookie.net/tips/published/GCC+Warning+Flags) the compiler would have told you ;)
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 (as in understand) newline EOFs yet... uneducated... lost... help!

OneSadCookie
2006.05.21, 03:29 AM
just put those flags into the "extra warning flags" section of your target settings

AnotherJake
2006.05.21, 03:45 AM
I'm sorry, that didn't communicate well. Let's try it again :)

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?

OneSadCookie
2006.05.21, 05:14 AM
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.