Page 1 of 1

error with canvas

PostPosted: Sun Feb 19, 2012 5:07 pm
by SuperSonic
Hey people :D

So I have this problem, I was creating a project that would load/diplay bmps. What I did to test it out was create a canvas and on it's create actor event, I called the functions for loading and displaying a bitmap. What I got when I tried to add it was:
Ge error wrote:Error line 1: Declaration error

I thought this may be a problem with my functions. However, it will still pop up no matter what code I put there. I even tried using comments! Nothing I can do will make it go away. Can anyone help me? :P

Re: error with canvas

PostPosted: Sun Feb 19, 2012 9:20 pm
by skydereign
If I recall correctly the problem in your code could be elsewhere (in global code). That or you might need to reopen gE. If neither of those work the worst case would be to transfer the code to the other, but I'm pretty sure I've been able to locate the problem causing it in global code.

Re: error with canvas

PostPosted: Mon Feb 20, 2012 2:36 am
by SuperSonic
Ok, I found it. It was a problem with some definitions. But now I need more help. These are my functions :)
Code: Select all
int image[256][256][256][3];
int imagesize[256][2];

//function for loading bmps
void loadbmp(char *FP, int ID)
{
    //declare variables
    int i, j;
    int header[64];
 
    //open file
    FILE *bmp = fopen(FP, "r+b");
 
    //store header
    for(i = 0; i < 64; i++)
    {
        header[i] = fgetc(bmp);
    }
 
    //store image width and height
    imagesize[ID][0] = header[18] + header[19] * 256;
    imagesize[ID][1] = header[22] + header[23] * 256;
 
    //store rgb info
    for(j = 0; j < imagesize[ID][1]; j++)
    {
        for(i = 0; i < imagesize[ID][0]; i++)
        {
            image[ID][i][j][2] = fgetc(bmp);
            image[ID][i][j][1] = fgetc(bmp);
            image[ID][i][j][0] = fgetc(bmp);
        }
    }
 
    //close file
    fclose(bmp);
}


void displayimage(int ID, int X, int Y)
{
    int i, j;
    for(j = 0; j < imagesize[ID][1]; j++)
    {
        for(i = 0; i < imagesize[ID][0]; i++)
        {
            setpen(image[ID][i][j][0], image[ID][i][j][1], image[ID][i][j][2], 0, 1);
            putpixel(i +  X, j + Y);
        }
    }
}

To put this simple, they don't work (of course). But I think the problem is somewhere in the load bmp function and I think it has to do with the integers that I declare at the begining. Would you mind helping me find where I went wrong? That would be really great if you could :roll:

Re: error with canvas

PostPosted: Mon Feb 20, 2012 12:24 pm
by Game A Gogo
I see you're using my code!

I can spot that you are not loading it correctly if the images are not multiples of 4 in size and that the way you're loading the bitmaps are in reverse!
although I'm not exactly sure why it leads to you not seeing anything

Code: Select all
void loadbmp(char *FP, int ID)
{
    //declare variables
    int i, j;
    int header[64];

    //open file
    FILE *bmp = fopen(FP, "r+b");

    if(bmp)//Only try load if the file exist!
    {
        //store header
        for(i = 0; i < 64; i++)
        {
            header[i] = fgetc(bmp);
        }
   
        //store image width and height
        imagesize[ID][0] = header[18] + header[19] * 256;
        imagesize[ID][1] = header[22] + header[23] * 256;
   
        //store rgb info
        for(j = imagesize[ID][1]; j >= 0; j--)
        {
            for(i = 0; i < imagesize[ID][1]; i++)
            {
                image[ID][i][j][0] = fgetc(bmp);
                image[ID][i][j][1] = fgetc(bmp);
                image[ID][i][j][2] = fgetc(bmp);
            }
            fseek(bmp, imagesize[ID][0]%4, SEEK_CUR);//Incase the image size if not multiple of four
                                                                             //we need to make sure it loads properly
        }
   
        //close file
        fclose(bmp);
    }
}

Re: error with canvas

PostPosted: Mon Feb 20, 2012 7:19 pm
by SuperSonic
you wrote:I see you're using my code!

Yeah^^ I'm using a mixture of codes :P

I'll try out your code and see if it works. Thanks :P

Re: error with canvas

PostPosted: Mon Feb 20, 2012 11:32 pm
by SuperSonic
Hmm, it still doesn't work quite right =/

I uploaded my ged. Could you take a look at it? :D

http://www.mediafire.com/download.php?9qe1305q9n4b5p0