![]() |
|
[a5] al_create_bitmap() not creating mipmap in OPENGL |
Mark Oates
Member #1,146
March 2001
![]() |
Ok, so when creating an ALLEGRO_BITMAP with al_create_bitmap(), then drawing some content onto it and then using that bitmap, it exhibits some strange behavior in certain circumstances. Specifically, if you have set al_set_bitmap_flags(ALLEGRO_MIPMAP) and are in ALLEGRO_OPENGL. I think the odd behavior alludes to the possibility that a mipmap is just not created. Here is an example program that illustrated the odd behavior: 1
2
3
4#include <allegro5/allegro.h>
5#include <allegro5/allegro_color.h>
6#include <allegro5/allegro_primitives.h>
7
8
9
10ALLEGRO_BITMAP *create_generated_bitmap()
11{
12 ALLEGRO_STATE prev;
13 al_store_state(&prev, ALLEGRO_STATE_TARGET_BITMAP);
14
15
16 // create our bitmap
17 ALLEGRO_BITMAP *generated_bitmap = al_create_bitmap(512, 512);
18 al_set_target_bitmap(generated_bitmap);
19
20 // clear the color to "ugly computer teal"
21 al_clear_to_color(al_map_rgba_f(0, 0.25, 0.25, 1.0));
22
23 // just draw some lines and junk
24 al_draw_line(20/2, 20/2, 960/2, 724/2, al_color_name("dodgerblue"), 20);
25 al_draw_line(20/2, 700/2, 660/2, 234/2, al_color_name("deeppink"), 30);
26 al_draw_line(700/2, 20/2, 860/2, 1024/2, al_color_name("brown"), 40);
27 al_draw_line(900/2, 70/2, 760/2, 824/2, al_color_name("orange"), 30);
28
29 // put a border on that shit
30 al_draw_rectangle(0, 0, al_get_bitmap_width(generated_bitmap), al_get_bitmap_height(generated_bitmap),
31 al_color_name("red"), 20);
32
33
34 // restore our previous drawing state
35 al_restore_state(&prev);
36
37 return generated_bitmap;
38}
39
40
41
42int main(int argc, char* argv[])
43{
44 // init stuff
45 al_init();
46 al_init_primitives_addon();
47
48
49 // set the mode and create the display
50 al_set_new_display_flags(ALLEGRO_OPENGL);
51 ALLEGRO_DISPLAY *display = al_create_display(960, 600);
52
53
54 // generate our bitmap
55 al_set_new_bitmap_flags(ALLEGRO_MIPMAP);
56 ALLEGRO_BITMAP *bitmap = create_generated_bitmap();
57
58
59 // draw at 1.0 scale (normal)
60 al_draw_bitmap(bitmap, 20, 20, 0);
61 // draw at 0.8 scale
62 al_draw_scaled_bitmap(bitmap, 0, 0, 512, 512, 300, 60, 512*0.8, 512*0.8, 0);
63 // draw at 0.6 scale
64 al_draw_scaled_bitmap(bitmap, 0, 0, 512, 512, 600, 120, 512*0.6, 512*0.6, 0);
65
66
67 // flip it
68 al_flip_display();
69
70
71 // give it some time
72 al_rest(2);
73}
Running the program should look something like this: But it looks like this (presumably because when scaling the bitmap, the hardware is trying to crossfade between a smaller mipmap that just isn't there, so it starts to look transparent) I can "fix" the issue by cloning the bitmap after drawing everything to it, (and then destroying the original for good measure), like this: // GENERATED BITMAP in OPENGL with ALLEGRO_MIPMAP fix: ALLEGRO_BITMAP *cloned = al_clone_bitmap(generated_bitmap); al_destroy_bitmap(generated_bitmap); generated_bitmap = cloned; Extra notes:
It may also be related to these 2 threads: My hardware is an the Intel card, as Bruce Pascoe mentions in the 2nd thread. I haven't tried it on other hardware.
-- |
|