|
Allegro 5 Multithread Issue |
Thinkal VB
Member #16,859
May 2018
|
al_init(); I called all the necessary functions to make a window from the main function. Then I used another thread to call al_clear_to_color(al_map_rgb(200, 100, 150)); but it shows error(not working). It's acting like as if the thread that called all the necessary functions like al_init() and etc..... are in control. Can anyone help me fix it? |
Elias
Member #358
May 2000
|
You can use al_set_target_bitmap to change the target display for drawing commands on the current thread. However note that this can be slow and lead to unexpected errors if you're not careful - best is to do your drawing commands on the same thread which called al_create_display. -- |
Thinkal VB
Member #16,859
May 2018
|
Hai Elias, thanks for answering I fixed it in a weird way. 1AClass::AClass() // constructor
2{
3/*initialize all the allegro variables*/
4al_set_target_bitmap(NULL);
5}
6
7void AClass::startRendering()
8{
9al_set_target_bitmap(al_get_backbuffer(display));
10
11while(keepRendering)
12{ /* take animations from que and render them */ }
13
14al_set_target_bitmap(NULL);
15}
However it is working, but sometimes it is throwing an exception. Is it a good way to get this done? Test : Load bitmap (an image) 88*2064 pixels Create bitmap (blank) 88*2064 pixels |
Chris Katko
Member #1,881
January 2002
|
Thinkal VB said: One more thing- can you explain why 3.44 KB PNG file, when loaded using al_load_bitmap(), takes ~3MB of memory space? That's easy! It's not compressed when you put it in memory! That's the whole point. If it was, you'd have to uncompress it every time you wanted to use it and then throw away that result and do it again the next time. Allocating and freeing a block of memory takes a lot time, and, why throw away the uncompressed version anyway if you already have it? -----sig: |
Thinkal VB
Member #16,859
May 2018
|
Thanks, Chris Kato You guys are amazing... |
relpatseht
Member #5,034
September 2004
|
It's normal. Uncompressed images take a lot of space (and the main reason why modern AAA titles supporting 4K displays are over 60GB pretty regularly). That said graphics cards do support some image compression formats, but these are specialized formats the card can decode in hardware. You wont see any typical image editor outputting them--you'll usually use a special conversion step to go from image editor output to a compressed texture format (and which one depends on the type of texture). DXT Compression. There are more formats than listed in that link, btw. I think there are either 7 or 8 now, though, you'll need recent hardware to access the latest formats.
|
dthompson
Member #5,749
April 2005
|
That'd probably be because you forgot to multiply that by the number of bits per channel total pixels = width * height bits per pixel = 32 = 8 bits * 4 channels (red, green, blue, alpha) minimum bits needed to store image = total pixels * bits per pixel Taking this into account, the minimum size for your 88x2064 image as stored in memory would be: 88 * 2064 * 32 = 5812224 bits This equates to about 750kB, which is a fair bit less than the 3MB you mentioned. However, there will be other things taking up space; we haven't yet accounted for all of the bitmap's metadata, struct padding, or any other memory that Allegro or libpng may have had to allocate to facilitate the loading of images. ______________________________________________________ |
Thinkal VB
Member #16,859
May 2018
|
Thank you dthompson for your enlightening support One more thing; I have a background texture - I guess it doesn't need alpha channel?. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Your paint program should have an option to save as a 24 bit png. Or you can just use .bmp. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Thinkal VB
Member #16,859
May 2018
|
Thank you Edgar Reynaldo for the replay |
Edgar Reynaldo
Major Reynaldo
May 2007
|
A note : The same image, encoded as .bmp or as .png, may be smaller as a png due to its compression. .bmp is not a compressed format. If you want good compression, export as a .jpg with various levels of quality. Quality level 70 still looks very much the same as the original, but gets really good compression. Thinkal VB said: Thank you Edgar Reynaldo for the replay You're welcome. I always like giving players another life. xD My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Thinkal VB
Member #16,859
May 2018
|
Thank you Edgar Reynaldo |
Chris Katko
Member #1,881
January 2002
|
Thinkal VB said: I will use 24 bit bmp - my paint doesn't have the 24 bit png. What? WHY? Also, you can always convert bmp to PNG using any other program afterwards. If you're on Linux, it's super easy, with plenty of terminal one-liners. -----sig: |
Thinkal VB
Member #16,859
May 2018
|
Thank you Chris Katko for replying |
relpatseht
Member #5,034
September 2004
|
Would you rather take less disk space, or load faster? The only format you should use for images is a compressed texture, as I said earlier.
|
Thinkal VB
Member #16,859
May 2018
|
Thank you relpatseht- for your kind suggestions and knowledge. I am learning new things every day...8-) |
|