error with canvas

Non-platform specific questions.

error with canvas

Postby SuperSonic » Sun Feb 19, 2012 5:07 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: error with canvas

Postby skydereign » Sun Feb 19, 2012 9:20 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: error with canvas

Postby SuperSonic » Mon Feb 20, 2012 2:36 am

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:
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: error with canvas

Postby Game A Gogo » Mon Feb 20, 2012 12:24 pm

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);
    }
}
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: error with canvas

Postby SuperSonic » Mon Feb 20, 2012 7:19 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: error with canvas

Postby SuperSonic » Mon Feb 20, 2012 11:32 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest