Getting pixel colour in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kuratkull
    New Member
    • Jan 2007
    • 12

    Getting pixel colour in C

    Hello,

    I haven't asked If I wasn't really confused :)

    OK, so I am just beginning SDL programming in C, and I was running fine, until I tried getting a pixel colour.
    Basically, I am trying to run the code from this page:
    http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access

    This is the cut down version of my code:

    Code:
    [I]snip[/I]
    SDL_Color GetPixel ( SDL_Surface* Screen , int x , int y ) ; //define struct
    [I]snip[/I]
    int main( int argc, char* argv[] )
    {
        SDL_Init( SDL_INIT_VIDEO );
        SDL_Surface* Screen =  SDL_SetVideoMode( width, height , 32, DL_HWSURFACE | SDL_DOUBLEBUF ) ; //use Screen as surface
    [I]snip[/I]
    curr_col = GetPixel(Screen, ant[1], ant[2]); //DOESN'T WORK! this is line 36
    [I]snip[/I]
    boxRGBA(Screen,
    	ant[1], ant[2],
    	ant[3], ant[4],
    	ant[5], ant[6], ant[7], ant[8]); //DOES WORK
    [I]snip[/I]
    gcc output:
    Code:
    test.c: In function ‘main’:
    [B]test.c:36: error: incompatible types in assignment[/B]
    test.c:38: error: expected expression before ‘{’ token
    PS! I believe the line 38 error comes from the faulty(?) line 36, since it's a simple if cond.

    Any help would be much appreciated :)
    Thank you.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It looks like the return type of GetPixel() is not the same as the type of curr_col so the compiler can't make the assignment.

    Comment

    • kuratkull
      New Member
      • Jan 2007
      • 12

      #3
      Yes, that was it.
      I'm surprised I didn't think about it :(

      But still, a big thanks.

      Comment

      Working...