Hi all:
Me again with another problem. I should know this but
I DO NOT. I have a situation where I enter a file like
"apple.png" to display. Normally I would hard code it in my program
and just run it. But now, I need to type it in on the keyboard
to enter it in my program. I then copy it to a buffer, My question
is how do I convert what is in the buffer to what I need for
al_load_bitmap(). I hope I have been clear on what I need.
I have it already in the buffer. I have printed out the buffer
and it is correct. I just need to convert it to use in al_load_bitmap().
Thanks for your time! Have a great day!
Make a generic text box with a string. Add letters/numbers if typed. Handle backspace and others. When does enter, use to load bitmap.
Hi Daniel:
I already have that. As an example: I have entered apple.png.
I have copied that to a buffer. All is well. This is what al_load_bitmap
needs: al_load_bitmap("apple.png"). I have "apple.png" stored in the buffer.
What I need to know is: how to transfer "apple.png" from the buffer to the
al_load_bitmap() function. Thanks for your time!
What buffer? The key buffer or an actual string? Can't you use that to load the bitmap?
Hi Daniel:
I have a string buffer: char buf[50]; Yes I could use
it if I knew how. That is my question! Thanks.
Just use it.
If buf contains a valid filename then just plug it in. As long as you have the image addon installed.
ALLEGRO_BITMAP* bitmap = al_load_bitmap(buf);
Daniel:
See my attachment above. This works perfectly.
Comment out the sprintf, it does not work.
printf command shows buf contains the right info.
Code tags please. Saves me downloading a file.
Print your str variable. If it valid? Have you tried al_cstr? Just my guess, but I would say your str is not valid or garbage. How are you adding characters?
Hi Daniel:
Sorry I could not get back to you last night. I have been
looking at this problem this morning.
printf("%s", buf); prints out correctly.
printf("%s", al_cstr(str)); prints out correctly.
For some reason al_load_bitmap(); is not picking up the info from buf.
Never had this problem before!
I will start a new program and see if I can get it working.
Have a great day!
Can you post the entire file?
Hi Daniel:
Well, it looks like it is going to be a while. I now have
problems with my new program. Now it says it can't create the font.
Allegro5 SUCKS! I have had more problems getting Allegro5 to work
than anything I have ever used! Everything seems to be in order.
What I am trying to do is taking everything out of my original
program and make a new program with just the text and bitmap that
is giving the problem.
I will be back later!
As always, Allegro 5 doesn’t suck, but you don’t want to post all of your code, and I don’t know why. We are here to help you and show you why your code doesn’t work, but you won’t show use your code, so we cannot help you.
I just tried using an allegro ustr, copied to a char buffer, and used it to load an image using al_load_bitmap, works fine.
Allegro 5 doesn’t suck, your code sucks.
👍
No, post what you already had. Let's take a look and see what the snag could be.
Hi Dizzy:
Well, you got me and got me good. Probably should have not posted that.
Edgar, Mark, Matthew and all the others that helped develop this library,
that put their heart and soul into it, are NOT going to be happy that I
posted that. I will most likely be kicked off this site.
Anyway, while I am still here I want to answer your question. I only
ask questions. I do not post much code, reason being I work only in Linux.
Most here work in Microsoft Windows. I don't because it is too much work.
Edgar and Matthew are the only ones I know that have access to Linux. I
have posted code for Edgar a few times. With a question, most of the time
I only need a hint and I can sometimes figure the rest out myself. I write
sloppy code, not the best coder out there for sure.
Again, sorry I posted what I did. Maybe I can slip thru this time.
Have a great day!
Linux or Microsoft, it doesn't matter. It's all C (or maybe C++) code.
No one is going to kick you off this site. Unless you start speaking leet. That trend can stay gone! And when he says your code sucks, he means it in the nicest way. We joke around here. This site is pretty casual. Don't be afraid to ask.
We only want to see the code because we're guessing otherwise. You originally asked about a problem loading bitmaps. After some digging and code posting, we figured your actual problem was more about UTF8 string conversion to char string.
The section you posted is fine. There has got to be something else in your code and that's why we would like to see more of the code.
Hi Daniel:
I need more info before sending code:
How to use code tags.
I think I used them one time for Edgar.
Do you want just the code or the whole program.
There are a few images that go along with the program.
Hey Scooter, it’s all good only joking around, lots of my code sucks!!
When you want to post code, put it in <code></code> tags, and it will format it. If you click formatting help when writing a post/reply it will show you how to use the various tags.
I think the most important part of your code to see is how you take the text entry and put it into the ustr, then we should be able to see why it’s not working correctly.
Just the code please. If it's not too big. There is a post limit.
Could it be that when you call al_ustr_new(” ”) you create it with a space? Have you tried calling al_ustr_new(””) without the space? It may be that even though the string looks ok it actually had a space in front of it?
Hi Dizzy:
Yes it does have a space. I remember putting them there.
Should I remove them and report back?
Great job guys! Thanks!
edit:
There was a space. I removed it and now it works perfect!
Why did the space cause it NOT to work?
Remove the space.
Hi Daniel:
I did remove the space and now it works perfect.
Hard to believe that would keep it from working.
Great job guys! Thanks!
It would have worked if your file was called “ maggie.jpg” and not “maggie.jpg” !!!
Could also do some overkill to avoid using string literals in your USTR creation.
ALLEGRO_USTR* input = al_ustr_dup(al_ustr_empty_string());
some things to discuss
1. Before you load the updated image file, make sure you destroy the current image.
2. Not sure if these functions are getting called, but I saw a few times you load a font into font16; That should be loaded at the front. Once and done. Destroy when program close.
3. Make your life just a bit better and split this up into multiple functions.
// my main 6 functions int init(); // intialize program, return -1 on any failure void shutdown(); // this frees any allocated memory void loop(); // main loop int input(); // ALL and only events are processed here. No logic. no drawing. return -1 on close request int logic(); // update anything based on the latest input status return -1 on any issue or program close request void draw(); // ONLY place things should be drawn in the entire program
Check out my basic pp framework on Github
It's C++, but can easily be made into C.
If you're feeling ambitions, I made a simple TicTacToe game from the same framework code. Also on Github.
See in the input section. I'm only updating variables from the events triggered. These variables are then processed in the logic section. Any update and it sets my dirty bool to true. which triggers a redraw.
Hello Scooter
Please don't get so frustrated. It's only code after all, I know you want it to work, but that is part of the process. Every time you learn how it doesn't work, you're one step closer to making it work and never making that mistake again. Trust the process.
Edgar
And, take what we say with a grain of salt. We're just here to give suggestions, but no one way is perfect for everyone. What works for you is what you should do.
That fact that you got it running is great!