BGI graphics in C.

This is a discussion on BGI graphics in C. within the C Programming forums, part of the General Programming Boards category; Hi Im doing a little crap thing for school. I used the putimage, getimage with XOR etc to put stuff ...

  1. #1
    DeSeis
    Guest

    BGI graphics in C.

    Hi
    Im doing a little crap thing for school.
    I used the putimage, getimage with XOR etc to put stuff arround the screen. Did it like that :

    unsigned char *buff[6]; <<< buffer for the images that are saved
    from the screen.

    and used the getimage like this:

    getimage(x,y,x2,y2,buff[1]);

    at that point it saves it to buff 1 and when i use
    putimage(x,y,buff[1],COPY_PUT); it goes out ok.

    but if i will add another getimage (for another image) it will like destroy all last saves in the buffer and overwrite it over all the array. so when i will use putimage(buff[1]) i wont get the one i saved at the first place, i will get the last thing i saved (even when it is saved on another buff (like buff[5]

    Any idea?!
    its killing me.
    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    > getimage(x,y,x2,y2,buff[1]);
    Before you do this, you need to allocate some memory

    Perhaps like this....
    buff[1] = malloc ( (x2-x)*(y2-y) );

    BUT!!!
    check the manual page, to ensure you allocate enough memory for the amout of data getimage will write.

  3. #3
    DeSeis
    Guest
    Well i did something like that:

    buff[3]=malloc(20*20);

    i get:

    cannont convert *void to * unsigned char *

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Apparently your compiler wants a cast.

    buf[x] = (unsigned char *) malloc( 20*20 );

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    DeSeis
    Guest
    Thank u brothers.

  6. #6
    DeSeis
    Guest
    My object size is 20*20 in pixels.
    isnt it too much to allocate 400?!
    Coz i get weird results after 1st..

    buff[1] getting ok.
    buff[2] is fuxored.
    buff[3] is ok.
    wtf?
    whats going on?
    i Set all to allocate 400.

    example:
    buff[i]=(char *)malloc(400);
    ..

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    > cannont convert *void to * unsigned char *
    Try compiling this using a C compiler, and not a C++ compiler.

    Renaming your source files from .cpp to .c is usually a good start.

    > My object size is 20*20 in pixels.
    Are you sure it's not 21*21 ?

    Like i mentioned previously, RTM!!!

    getimage(0,0,20,20,buff[1]);
    might be copying a 21*21 pixel image, which would definitely cause you a problem, if you thought that 20*20 was enough.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with BGI graphics: Linker Error
    By darklord1984 in forum C++ Programming
    Replies: 9
    Last Post: 11-10-2007, 10:16 AM
  2. A question about the old BGI graphics libary
    By p3t3r1 in forum C Programming
    Replies: 0
    Last Post: 04-30-2006, 11:19 AM
  3. BGI Error: Graphics not initialized (use 'initgraph');
    By Jasin14 in forum C Programming
    Replies: 4
    Last Post: 10-02-2002, 12:58 PM
  4. BGI Graphics
    By drdroid in forum C++ Programming
    Replies: 14
    Last Post: 06-03-2002, 02:07 PM
  5. Graphics In C (BGI)
    By GaPe in forum C Programming
    Replies: 6
    Last Post: 01-01-2002, 03:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21