Sign in to follow this  

(solved) Problem with struct

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What you have is a const struct BitmapStruct *bitmap_settings[] but you initialized it like a const struct BitmapStruct bitmap_settings[];

In other words, it's creating a pointer from GFX_TILESET_0 and assigning that as bitmap_settings[0], then taking "gfx/tileset0.bmp", turning that into a pointer and setting bitmap_settings[1] to that pointer, and so on.

Share this post


Link to post
Share on other sites
Hidden
With bracers, I get even more errors:

gfx.c:36: warning: braces around scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')
gfx.c:36: warning: excess elements in scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')
gfx.c:36: warning: excess elements in scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')
gfx.c:36: warning: excess elements in scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')
gfx.c:36: warning: excess elements in scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')
gfx.c:36: warning: excess elements in scalar initializer
gfx.c:36: warning: (near initialization for `bitmap_settings[0]')

Tried changing filename[64] to *filename and still no luck....

What do I have to do?

Share this post


Link to post
Hidden
I solved it. It took some experimenting, but here's the final (working) code:


struct BitmapStruct {
int bitmap_id;
char filename[64];
int width;
int height;
int number_of_tiles;
GLint filter;
};

extern const struct BitmapStruct bitmap_settings[];





const struct BitmapStruct bitmap_settings[] = {
{ GFX_TILESET_0, "gfx/tileset0.bmp", TILE_SIZE, TILE_SIZE, 256, GL_NEAREST },
{ GFX_TILESET_1, "gfx/tileset1.bmp", TILE_SIZE, TILE_SIZE, 256, GL_NEAREST }
};




Added bracers, and changed *bitmap_settings[] to bitmap_settings[] in both the header and main program.

Share this post


Link to post
Specifying image size in code is not a good idea. A better way is to write something like AddBitmap(char *filename), which would load an image file from disk, find the correct height, width etc, install the resource in the suitable place and return a handle to it.

That way your program won't break if you decide to resize some graphics.

Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this