![]() |
|
al_get_opengl_texture |
azerty_damned
Member #12,589
February 2011
|
Hi, al_get_opengl_texture() returns a texture with garbage in data I'm using Allegro 5.0.1 with MacOS X 10.5.8. Here is my method to load a bitmap and return its OpenGL id: 1void Texture::load(const char *filename)
2{
3 pBmp = al_load_bitmap(absoluteBundleResourcePath(filename));
4 if (pBmp == NULL)
5 throw Exception("*** Can't load image!");
6
7 if (!al_is_compatible_bitmap((ALLEGRO_BITMAP *) pBmp))
8 {
9 al_destroy_bitmap((ALLEGRO_BITMAP *) pBmp);
10 throw Exception("*** Image not compatible with OpenGL!");
11 }
12
13 iID = al_get_opengl_texture((ALLEGRO_BITMAP *) pBmp);
14 if (iID == 0)
15 {
16 al_destroy_bitmap((ALLEGRO_BITMAP *) pBmp);
17 throw Exception("*** Can't get OpenGL id!");
18 }
19
20 bLoaded = true;
21}
22
23void Texture::bind() const
24{
25 glBindTexture(GL_TEXTURE_2D, iID);
26}
So, what is going (am I doing) wrong? Thanks in advance for any answer, |
Elias
Member #358
May 2000
|
What is it supposed to look like? -- |
azerty_damned
Member #12,589
February 2011
|
Hi, Here is the original texture... |
Elias
Member #358
May 2000
|
Hm, does the picture work fine if you draw it with al_draw_bitmap? Else can you make a small example program reproducing the problem? -- |
azerty_damned
Member #12,589
February 2011
|
Hi, Here is the program that reproduces the problem. I hope it is clear enough. 1/*
2 * Bitmap used as OpenGL texture problem
3 */
4#include <cstdlib>
5#include <allegro5/allegro.h>
6#include <allegro5/allegro_image.h>
7#include <allegro5/allegro_opengl.h>
8#include <OpenGL/glu.h>
9
10static int SCR_W = 1024;
11static int SCR_H = 768;
12
13int main(int argc, char **argv)
14{
15 (void) argc;
16 (void) argv;
17
18 if (!al_init()) exit(1);
19
20 // Configure display
21 al_set_new_display_flags(ALLEGRO_OPENGL | ALLEGRO_WINDOWED);
22 al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE);
23 al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 8, ALLEGRO_REQUIRE);
24 al_set_new_display_option(ALLEGRO_FLOAT_DEPTH, 1, ALLEGRO_REQUIRE);
25
26 ALLEGRO_DISPLAY *pDisplay;
27 pDisplay = al_create_display(SCR_W, SCR_H);
28 if (pDisplay == NULL) exit(1);
29
30 // Mandatory
31 al_install_keyboard();
32 al_init_image_addon();
33
34 // Configure OpenGL
35 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
36 glEnable(GL_DEPTH_TEST);
37 glDepthMask(GL_TRUE);
38 glDepthFunc(GL_LEQUAL);
39 glEnable(GL_CULL_FACE);
40 glCullFace(GL_BACK);
41 glEnable(GL_TEXTURE_2D);
42
43 // Load bitmap
44 ALLEGRO_BITMAP *pBmp = al_load_bitmap("reflect.tiff");
45 GLuint iID = al_get_opengl_texture(pBmp);
46
47 // Prepare event queue
48 ALLEGRO_EVENT event;
49 ALLEGRO_EVENT_QUEUE *pQueue = al_create_event_queue();
50 al_register_event_source(pQueue, al_get_keyboard_event_source());
51 al_register_event_source(pQueue, al_get_display_event_source(pDisplay));
52
53 // Enter main loop
54 bool bLeave = false;
55 while (!bLeave)
56 {
57 // Clear buffers
58 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
59
60 // 2D mode
61 glMatrixMode(GL_PROJECTION);
62 glLoadIdentity();
63 gluOrtho2D(0, SCR_W, SCR_H, 0);
64
65 glMatrixMode(GL_MODELVIEW);
66 glLoadIdentity();
67
68 // Blit 2D texture
69 GLint w = al_get_bitmap_width(pBmp);
70 GLint h = al_get_bitmap_height(pBmp);
71 glBindTexture(GL_TEXTURE_2D, iID);
72 glBegin(GL_QUADS);
73 glNormal3f(0.0f, 0.0f, 1.0f);
74 glTexCoord2f(0.0f, 0.0f); glVertex2i(0, h);
75 glTexCoord2f(1.0f, 0.0f); glVertex2i(w, h);
76 glTexCoord2f(1.0f, 1.0f); glVertex2i(w, 0);
77 glTexCoord2f(0.0f, 1.0f); glVertex2i(0, 0);
78 glEnd();
79
80 // Show backbuffer
81 al_flip_display();
82
83 // Check events
84 if (!al_is_event_queue_empty(pQueue))
85 {
86 while (al_get_next_event(pQueue, &event))
87 {
88 switch (event.type)
89 {
90 case ALLEGRO_EVENT_DISPLAY_CLOSE:
91 bLeave = true;
92 break;
93 }
94 }
95 }
96 }
97
98 // Properly leave program
99 al_destroy_event_queue(pQueue);
100
101 al_destroy_bitmap(pBmp);
102
103 al_shutdown_image_addon();
104
105 if (al_is_keyboard_installed())
106 al_uninstall_keyboard();
107
108 if (al_is_system_installed())
109 al_uninstall_system();
110
111 // Be done
112 exit(0);
113}
114
115// EOF
|
Elias
Member #358
May 2000
|
Works fine here in Linux. I had to disable vsync, depth_size and float_depth though and convert the .tiff to a .png. Can you try making those changes and see if the problem is fixed? -- |
azerty_damned
Member #12,589
February 2011
|
Hi Elias, I've used a png file and removed all the calls to al_set_new_display_option() but the result is the same... Maybe this is a MacOS X specific issue? I also have the problem when I use al_draw_bitmap()... Thanks for your help... |
Elias
Member #358
May 2000
|
azerty_damned said: I also have the problem when I use al_draw_bitmap() Is ex_bitmap also broken? -- |
azerty_damned
Member #12,589
February 2011
|
Hello Elias, ex_bitmap works but not ex_draw_bitmap... ex_bitmap uses a .pcx file; ex_draw_bitmap a .png, so I've saved my texture as .pcx and the problem has disappeared. But I don't want to use PCX, because of I've compiled the Allegro library with this version of GCC: Using built-in specs. |
Evert
Member #794
November 2000
![]() |
Ok, PowerPC. That could be important. I can try your example later (on 10.6) to see if it works here. |
Elias
Member #358
May 2000
|
.png (as well as .tiff) is handled by the OSX image loader. .pcx is read directly. So guess we have a good indication now that the OSX image loader is broken. Since you are using 10.5 but all devs are using 10.6 I'm fairly certain that's the problem. OSX must somehow load images differently under 10.5. Is there a way to debug 10.5 specific problems under 10.6? [edit:] Oh, didn't see PowerPC, that could be another reason of course, swapped byte order always can cause problems. -- |
Evert
Member #794
November 2000
![]() |
Elias said: Since you are using 10.5 but all devs are using 10.6 I'm fairly certain that's the problem. OSX must somehow load images differently under 10.5. Is there a way to debug 10.5 specific problems under 10.6?
Probably. Just compile an executable that is designed to run under 10.5. I don't think that's the problem though. |
Matthew Leverton
Supreme Loser
January 1999
![]() |
As I've reported many times, the native loader does not work properly on 10.4/PPC. The screenshot is the same type of results I get. I fixed some endian issues with the locking code, but that didn't fix the horizontal garbage of some images. The libpng/libjpeg loaders work fine. |
azerty_damned
Member #12,589
February 2011
|
Hi, I've installed libpng15 and zlib (/usr/local/lib) but I don't know how to tell cmake to use them instead of native image loaders. Can you help me? Thanks... |
Matthew Leverton
Supreme Loser
January 1999
![]() |
Grep the cmake log or txt files or something like: cmake .. -DWANT_NATIVE_IMAGE_LOADER=off |
azerty_damned
Member #12,589
February 2011
|
Hi Matthew, It is working now, thank you. Is there any hope to see the problem with native loaders on ppc solved in the future? |
|