Hello. I have a structure:
And a function to initialize that structure:
This is what I don't understand:
How do I assign the output of al_map_rgb to that structure's member?
-- Edit
Seems al_map_rgb always returns 0 via printf.
In any event, the desired usage of the color is here:
This only ever produces black.
Try using al_unmap_rgb() (https://www.allegro.cc/manual/5/al_unmap_rgb). It does the reverse of al_map_rgb() and retrieves the three colours (RGB) for you.
Any function that takes an ALLEGRO_COLOR value you can use your color value directly. But if you want to retrieve the stored RGB values, you will need to call al_unmap_rgb() to retrieve them.
But if you want to retrieve the stored RGB values, you will need to call al_unmap_rgb() to retrieve them.
Nay, sorry, that's not my goal. I edited my post to make my intended-usage more clear.
Thank you for your reply.
Ah, okay, than with your desired usage, it will work just fine as that takes an ALLEGRO_COLOR.
You must not call most allegro functions (like al_map_rgb) before al_init.
You must not call most allegro functions (like al_map_rgb) before al_init.
*sigh* Okay. That works. You've obviously seen this before?
I feel mildly similar to when I first wrote this:
Thank you, Edgar.
Meh, just consider it an initiation rite. Everyone always misses stuff like that. You wouldn't think al_map_rgb would matter, but they cache values, so it does.
Welcome to the club. May I suggest you join our little -TINS- KrampusHack this year?
Hello. I have a structure:
Just to nitpick, this would be easier to understand if you left root pointing to the first element, and used a new variable it or iterator (or whatever) to move through the array. It's also easier to split the special last case out of the loop.
Everyone always misses stuff like that.
I've been messing with DOS stuff again, and was fiddling with a little program to show the colors in CGA video mode 4. I couldn't get it to work right for 6 HOURS (although in my defense I couldn't seem to catch it in GDB and none of the windowed debuggers I have will work for more than 2 minutes)
It was supposed to show the top 25% as one color (black), then each additional quarter of the screen showed the other 3 colors, but this showed the top 50% as black.
Can you spot the problem?
Can you spot the problem?
Hmmm... never worked with CGA mode before, only VGA. The only thing I can think of is your character pointers rather than unsigned character pointers?
You make me want to mess with DOS again. I miss that. What are you using to compile this with? I used to use DJGPP to compile with when I first learned C under DOS. I still have ALL my old source code as I'm a packrat and keep even the stupid little things, including many code examples I got from Allegro people back in the '90s!
never worked with CGA mode before, only VGA
Broad hint: The problem has nothing to do with hardware or CGA, just a coding error. I went so far as to trying it in system memory on Linux and examined the memory with a debugger, which still had the problem.
Or if you wanna cheat...
My treacherous little fingers muscle memory went and snuck in the semicolon at the end of that for(;;) loop on line 49 so the body of the loop doesn't get executed
As to the other questions, I was tired of OpenGL inconsistencies etc. so I decided to just blit a memory buffer to a window with graphic primitives similar to Allegro 4, and one day thought "I wonder how slow it would be in DOS" although CGA resolution is too small for just about any sort of interface beyond a pixel-y game. I'm using Watcom and nasm in case I feel like giving something to the freedos crowd as those are their preferences.
I've hijacked this thread far enough.
If you want to visualize something use %x
Ah!!! I don't know how I didn't spot that, but I have made the same mistake. In fact, it is probably my most common mistake to make! I had to read your spoiler to see it, but now it seems so obvious. Such a simple mistake, but a nasty one and difficult to find.
I can see how a debugger wouldn't catch that as it is still valid code... though I would think that a decent IDE would warn you of it given the code following it. Is there a flag to warn of such things? I know I would turn it on if there was.
Apple's compiler gives this (even with no 'warning' flags applied)
$ gcc ak.c ak.c:49:19: warning: for loop has empty body [-Wempty-body] for(;i<4000;i++);
(though obviously none of the rest of it compiles anyway)
So it's definitely possible for the compiler to detect this - maybe you just need a newer version?
Apple's compiler gives this (even with no 'warning' flags applied)
I don't have the original anymore (just a one-off test) but
run through Slackware current gcc version 5.5.0 gave an error as
"warning: array subscript is above array bounds [-Warray-bounds]"
with -O2 -Wall options. Changing line 12 to read
array[4] = i;
got it to compile with no warnings or errors
The latest DJGPP has gcc version 9.3.0 (!) which gave these warnings
t.c: In function 'main': t.c:12:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation] 12 | for(i=0;i<10;i++); | ^~~ t.c:13:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for' 13 | array[LIMIT] = i; | ^~~~~ t.c:13:8: warning: array subscript 1000 is above array bounds of 'unsigned int[1000]' [-Warray-bounds] 13 | array[LIMIT] = i; | ~~~~~^~~~~~~ t.c:6:14: note: while referencing 'array' 6 | unsigned int array[LIMIT]; | ^~~~~
OTOH, I seem to remember an old ALLEGRO.TXT as saying something about such a loop being used for a delay
"If the compiler complains, try changing it to
for(i=0;i<1000;i++) {};
to beat the compiler into submission."
array[LIMIT] is definitely out of bounds if you set the LIMIT to 1000, then use this, the maximum is only 999, so this should be array[LIMIT-1].
But anyhow, yeah, for loops were common for delays, which is why I originally seen it as valid (even if poor) code. I would expect a warning when it is followed with braces and/or indented code though.
Nice to see DJGPP is still going.
You're making me want to fire up some old DOS projects again.
Also, did you notice the semicolon on line 11?