Thread: Gd graphics library help

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    35

    Gd graphics library help

    This is the output for my poker hand evaluator.
    The shapes are made using lines, rectangles and circles.

    This is how id expect it too look
    Gd graphics library help-c1-jpg

    However when i have a Club, Spade or heart as the suit for the first card this is what i get at the output
    Gd graphics library help-c2-jpg

    Here is the code for drawing the Club:
    Code:
    gdImageString( gdImage, gdFontGetGiant(),  (80+(WordLineUpX*140)), (55+(WordLineUpY*195)),  "Clubs", black );
                 gdImageString( gdImage, gdFontGetGiant(),  (50+(WordLineUpX*140)), (175+(WordLineUpY*195)),  "Busby", red ); 
                 gdImageFilledRectangle( gdImage, 105+(WordLineUpX*140), 130+(WordLineUpY*195), 95+(WordLineUpX*140), 170+(WordLineUpY*195), black );
                 gdImageFilledRectangle( gdImage, 80 +(WordLineUpX*140), 165+(WordLineUpY*195), 120+(WordLineUpX*140), 170+(WordLineUpY*195) , black );
                 gdImageFilledEllipse( gdImage,   100+(WordLineUpX*140), 115+(WordLineUpY*195), 30, 30, black );
                 gdImageFilledEllipse( gdImage,   80 +(WordLineUpX*140), 140+(WordLineUpY*195), 30, 30, black );
                 gdImageFilledEllipse( gdImage,   120+(WordLineUpX*140), 140+(WordLineUpY*195), 30, 30, black );
    WordLineUpX is what shifts the cards along depending if its card 1,2,3,4 or 5. and WordLineUpY is what shifts it up and down for hand 1 and 2.

    I dont know the cause of the error, pretty sure its to do with the WordLineUpX being 0, but I'm really not sure. I've tried other things to make it work and it still gives the same result

    Thank you in advance for any help

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,684
    Did you do this first; copied from your last thread. Drawing an image in C

    Code:
    gdImageSetThickness( gdImage, 2 );
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    Yes that simple drawing of the diamond existed before this code, i was working intensively on it yesterday, and became increasingly more familiar with using the gd graphics library. Do you know why it might be doing this??
    Thanks,

    Ben

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,684
    Quote Originally Posted by BenBusby View Post
    Yes that simple drawing of the diamond existed before this code, i was working intensively on it yesterday, and became increasingly more familiar with using the gd graphics library. Do you know why it might be doing this??
    Thanks,

    Ben
    That disagrees with your prior statement. You said it happens on the first card.
    There is no card before the first card in your screen shoots.

    EDIT: Do you understand that if the thickness is NOT set it could be very large?
    That is why I suggested adding this line!

    gdImageSetThickness( gdImage, 2 );


    Tim S.
    Last edited by stahta01; 04-11-2013 at 09:12 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    First comment out any drawing for hearts, clubs and spades. Does it draw a blank card correctly?

    Add the drawing back bit by bit, making sure that each individual shape is drawn correctly (ie draw only 1 rect by commenting out the other rect and ellipses, does the rect appear in the correct place? If so comment it out and comment in the next rect.)

    >>gdImageFilledRectangle( gdImage, 105+(WordLineUpX*140), 130+(WordLineUpY*195), 95+(WordLineUpX*140), 170+(WordLineUpY*195), black );

    This is drawn in reverse ie x left = 105 and x right = 95. The docs say it draws top left to bottom right. Is that confusing the drawing? (don't think this is the error or it would always draw 'spades' incorrectly)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    As stahta01 pointed out it may be the width setting. Your examples have the 2nd card as a Diamond.

    Do you get the same error repeated for more than just the first card (if the 2nd card is not a Diamond)? (ie all drawing fails until the the fist diamond is draw, in which the drawing code sets the thinckness for all future drawing, so then all drawing succeeds.)

    BTW Royal Flush beats 4 of a kind and 5 of a kind (ie 5 3s) is usually impossible in poker (least from what I remember from my time as a croupier, before I started spotting trains...).
    Last edited by novacain; 04-11-2013 at 11:05 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. .net graphics library
    By xddxogm3 in forum C# Programming
    Replies: 3
    Last Post: 12-01-2010, 12:29 PM
  2. Using graphics library
    By arch in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2008, 04:31 PM
  3. Best Graphics Library for 2d RTS?
    By arew264 in forum Game Programming
    Replies: 4
    Last Post: 04-18-2007, 12:05 PM
  4. DOS graphics library
    By dieselpower in forum C++ Programming
    Replies: 10
    Last Post: 06-04-2003, 06:41 AM
  5. Graphics library?
    By Paninaro in forum C Programming
    Replies: 6
    Last Post: 06-24-2002, 08:35 PM

Tags for this Thread