|
This thread is locked; no one can reply to it. |
1
2
|
bitmap structure |
lourentz hek
Member #5,044
September 2004
|
I'm trying to make a bitmap structure so that I can load multiple bitmaps at once in a function. The problem is that I get an error when I want to load the bitmap. So far I have come up with this code:
Do you know how I can load these bitmaps? |
Gideon Weems
Member #3,925
October 2003
|
That's a bit hard-coded, you know, but I guess it's fine if you've just started learning the library. When you say that you're getting an error, what exactly happens? Are you checking the value of broer.voor1 against NULL? broer.voor1 = load_bitmap("broer1.bmp",NULL); if(broer.voor1 == NULL) exit(42); In order for your code to work, broer1.bmp must exist in the current directory and Allegro must be set up properly already. |
miran
Member #2,407
June 2002
|
Uhm, don't you need to make an instance of your structure in order to be able to use it? Or does that C declaration of the structure already do that? -- |
CGamesPlay
Member #2,559
July 2002
|
miran: That isn't a C definition, It's a C++ one He name the struct characters_praten, and created an instance named broer. -- Ryan Patterson - <http://cgamesplay.com/> |
miran
Member #2,407
June 2002
|
Really? Well, you learn something new every day. Then maybe he's trying to load the bitmap outside of a function? -- |
lourentz hek
Member #5,044
September 2004
|
Well. The compiler shows 3 errors: error C2143: syntax error : missing ';' before '.' error C2501: 'broer' : missing storage-class or type specifiers error C2371: 'broer' : redefinition; different basic types |
dudaskank
Member #561
July 2000
|
in C you can do this too... I think :p Toque a balada do amor inabalável, eterna love song de nós dois |
ReyBrujo
Moderator
January 2001
|
Matt Smith
Member #783
November 2000
|
Me too. I always typedef a struct with the same name as its tag. It makes casting and defining instances (especially for pointers) obvious and simple. BITMAP is itself declared this way, as are all the common Allegro structs. |
CGamesPlay
Member #2,559
July 2002
|
lourentz hek: You must be trying to set broer.voor1 on the global scope. You have to do it inside of a function. He doesn't need to typedef the structs if he's using C++. -- Ryan Patterson - <http://cgamesplay.com/> |
Evert
Member #794
November 2000
|
Quote: I would use it this way: So would I, but struct something { /* some stuff */ } somevar; is perfectly valid C code where somevar is of type struct something. |
Tobias Dammers
Member #2,604
August 2002
|
Quote:
error C2143: syntax error : missing ';' before '.' error C2501: 'broer' : missing storage-class or type specifiers error C2371: 'broer' : redefinition; different basic types
Have you included <allegro.h>? Any other headers? Looks like the compiler doesn't understand you struct definition, although it is, in itself, valid C code; maybe BITMAP* is not defined. Oh yes: do you compile this as a C or a C++ program?
--- |
Evert
Member #794
November 2000
|
I'd also recommend not mixing two languages in your sourcecode - this will only be confusing and ugly in the long run. I won't say you should use English throughout (although I've myself adopted English as my primary language when doing anything programming related, or even anything computer related), but I'd avoid things like characters_praten. |
Tobias Dammers
Member #2,604
August 2002
|
Hehe, two languages... I first thought you mean C and C++... anyway, since all C and C++ keywords are actually English words, I use English names for everything else, too. Sort of easier to read. Especially for people on a forum who are trying to help you. Knowing what a variable name means usually gives a good hint on what the programmer wants it to do. (ik spreek dan toevallig zelf wél Nederlands, but most people here don't). --- |
Avenger
Member #4,550
April 2004
|
For me, not using english when using my computer just seems.. Weird
|
Thomas Fjellstrom
Member #476
June 2000
|
ditto. -- |
Evert
Member #794
November 2000
|
Quote: (ik spreek dan toevallig zelf wél Nederlands, but most people here don't). Ik moet altijd even omschakelen als ik een zin twee talen zie staan. Meestal begrijp ik de eerste keer dat ik het lees niet wat er staat... So yeah, probably best to be consistent and just use English... but I can understand people not doing that. |
Tobias Dammers
Member #2,604
August 2002
|
Yeah, I was making a point here. Though I get quite thorough practice when I rehearse with my bands, with members from the Netherlands, Germany, Belgium, Spain, Cuba and Suriname. Pretty cool actually, I'm learning Spanish while I work... --- |
Matt Smith
Member #783
November 2000
|
How about a code editor which always shows all variables in the local language? If Korean hurts your eyes, press a button! |
lourentz hek
Member #5,044
September 2004
|
It's working fine now. Thanks for you help. I only have one last question. Is it possible to declare the structure outside a function let's say in a header? |
miran
Member #2,407
June 2002
|
That's where you're supposed to declare it If you declare instances of the structure though, you should declare them as extern in the header and then later define them in the .cpp file:
I'm not sure about the exact rules in C but I don't think it's much different... -- |
A J
Member #3,025
December 2002
|
slightly off topic, but its a BITMAP structure question... why did someone re-define the windows bitmap structure memebers in allegro to use unsigned long, when the M$ document lists it as DWORD. ___________________________ |
Thomas Fjellstrom
Member #476
June 2000
|
DWORD == unsigned 32 bits. current unsigned long? unsigned 32bits. -- |
Oscar Giner
Member #2,207
April 2002
|
A J said: why did someone re-define the windows bitmap structure memebers in allegro to use unsigned long, when the M$ document lists it as DWORD.
WinDef.h said: typedef unsigned long DWORD; so what's the problem? -- |
A J
Member #3,025
December 2002
|
unsigned long on 64bit system is AFAIK 64bit. ___________________________ |
|
1
2
|