[GL] Masked sprite in 16 bits.
anto80

Hello all.

I would like to know if it's possible to display a masked sprite in 16 bits with Allegro GL.

/* the desktop is 16 bpp */
int nColDepth;
GLuint tex_nb;

nColDepth = 16;
set_color_depth(nColDepth);
allegro_gl_set(AGL_COLOR_DEPTH, nColDepth);  

tex_nb = allegro_gl_make_texture_ex(nFlags, bmpTex, internal_format);
/* I have tried with internal_format=GL_RGBA8 and =GL_RGB8 */

- With a 16 bit desktop, and with nColDepth=16, it crashes if nFlags contains the bit AGL_TEXTURE_HAS_ALPHA or AGL_TEXTURE_MASKED. Here are the last words of Allegro.log :

* Note * make_texture_ex: Preselected texture format: 0x1907, type: 0x8363
* Note * munge_bitmap: Need to perform depth conversion from 16 to 16 bpp.
* Note * munge_bitmap: Flipping bitmap.
* Note * munge_bitmap: Copying bitmap.
* Note * munge_bitmap: Inserting alpha channel.

If i don't put any of these 2 bit-flags, it works, but obviously without alpha channel and without mask color (draw the rectangle entirely).
Maybe it has something to do with the internal_format value: GL_RGBA8,GL_RGB8,other: what would you suggest for a masked bitmap?

- With a 32 bit desktop, and with nColDepth=32, all works fine, regardless of the nFlags value.

You may wonder why 16 bpp, although 32 bpp works perfectly... The answer is that i want to test some other possibilities, to see how many FPS are saved this way, and if it does worth it...

Thank you in advance for your help.

Bob

If your bitmap does not actually contain an alpha channel (which is the case for 16-bit), you probably want to use the AGL_TEXTURE_MASKED flag. AGL_TEXTURE_HAS_ALPHA is only used on 32-bit bitmaps where the alpha channel contains actual alpha values (insetad of 0, which is what Allegro typically loads there).

However, the log you've pasted does not match what the code should be doing for AGL_TEXTURE_MASKED. Is this correct?

anto80
Quote:

If your bitmap does not actually contain an alpha channel (which is the case for 16-bit), you probably want to use the AGL_TEXTURE_MASKED flag. AGL_TEXTURE_HAS_ALPHA is only used on 32-bit bitmaps where the alpha channel contains actual alpha values (insetad of 0, which is what Allegro typically loads there).

I agree with you totally. I am using 16 bit bitmaps in this case, with the mask-color equals to RGB(255,0,255), and the AGL_TEXTURE_MASKED flag.
For your information these bitmap are created internally by create_bitmap(), then cleared by clear_to_color(makecol(255,0,255));
for example I put a glyph on it like this textprintf(bmpTmp, font, 0,0, makecol(255,0,0), "a");

Quote:

However, the log you've pasted does not match what the code should be doing for AGL_TEXTURE_MASKED. Is this correct?

The log file correspond to what is described just above. Even the line "* Note * munge_bitmap: Inserting alpha channel."
Yes, it is the AGL_TEXTURE_MASKED flag.

Bob

This line can't be right:

* Note * munge_bitmap: Need to perform depth conversion from 16 to 16 bpp.

The code in AGL is:

1 
2 int depth = bitmap_color_depth(bmp);
3 int force_copy = 0;
4 
5[snip]
6 
7 /* We need a texture that can be used for masked blits.
8 * Insert an alpha channel if one is not there.
9 * If it's already there, replace it by 0/1 as needed.
10 */
11 if ((flags & AGL_TEXTURE_MASKED) && !(flags & AGL_TEXTURE_ALPHA_ONLY)) {
12 need_alpha = 1;
13 
14 switch (depth) {
15 case 15:
16 if (!allegro_gl_extensions_GL.EXT_packed_pixels) {
17 depth = 32;
18 }
19 break;
20 case 8:
21 case 16:
22 case 24:
23 case 32:
24 depth = 32;
25 break;
26 }
27 force_copy = 1;
28 }
29 
30[snip]
31
32 /* Do we need to do a color depth conversion or bitmap copy? */
33 if (depth != bitmap_color_depth(bmp) || force_copy) {
34 
35 TRACE(PREFIX_I "munge_bitmap: Need to perform depth conversion from %i "
36 "to %i bpp.\n", bitmap_color_depth(bmp), depth);

As you can see, a depth of 16 should force AGL to upconvert the bitmap to 32 bits. That's not happening according to your log file.

anto80

I can assure you i didn't altered the code nor the log file.

I'll post my actual code in a few minutes so you will see.

Bob

In that case, please attach the source to a small program to demonstrate the problem. Also please attach the full allegro.log file.

Thanks.

anto80

Main example :

1/* [edit] uptaded code. */
2#include <stdio.h>
3#include <allegro.h>
4#include <alleggl.h>
5#include <winalleg.h>
6#include <windows.h>
7 
8int main(void)
9{
10 int nColDepth;
11 
12 nColDepth = 16;//32;
13 
14 allegro_init();
15 install_allegro_gl();
16 
17 install_timer();
18 install_keyboard();
19 install_joystick(JOY_TYPE_AUTODETECT);
20 install_mouse();
21 set_color_depth(nColDepth);
22 set_trans_blender(255, 255, 255, 128);
23 text_mode(-1);
24
25 /*--- Alleg GL inits --------------------------------------------------*/
26 allegro_gl_clear_settings();
27 allegro_gl_set(AGL_COLOR_DEPTH, nColDepth);
28 allegro_gl_set(AGL_Z_DEPTH, 8); // for 3D polygon sorting
29 allegro_gl_set(AGL_WINDOWED, 1);
30 allegro_gl_set(AGL_DOUBLEBUFFER, 1);
31 allegro_gl_set(AGL_RENDERMETHOD, 1);
32 allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH);
33 allegro_gl_set(AGL_REQUIRE, AGL_DOUBLEBUFFER|AGL_RENDERMETHOD|AGL_COLOR_DEPTH);
34
35 if (set_gfx_mode(GFX_OPENGL,
36 640, 480,
37 0, 0))
38 {
39 allegro_message("Error initializing\n");
40 exit(1);
41 }
42 glMatrixMode(GL_PROJECTION); /* I am setting a state where I am editing the projection matrix... */
43 glLoadIdentity(); /* Clearing the projection matrix... */
44 glOrtho(0, 640, 0, 480, -1, 1); /* Creating an orthoscopic view matrix going from -1 -> 1 in each dimension on the screen (x, y, z). we will always draw our 2D objects at z equal to zero. */
45 glMatrixMode(GL_MODELVIEW); /* Now editing the model-view matrix. */
46 glLoadIdentity(); /* Clearing the model-view matrix. */
47 glDisable(GL_DEPTH_TEST); /* Disabling the depth test (z will not be used to tell what object will be shown above another, only the order in which I draw them.) */
48 glEnable(GL_TEXTURE_2D); /* Enable texturing on all models for now on. */
49 glEnable(GL_BLEND);
50
51 glClearColor(0.0, 0.0, 0.0, 0.0); /* Set the background color to black */
52 
53 BITMAP* bmp1 = create_bitmap(32, 32);
54 clear_to_color(bmp1, makecol(255,0,255));
55 textprintf(bmp1, font, 0,0, makecol(0,0,255), "ab"); /* blue */
56 
57 GLuint tex_nb1 = allegro_gl_make_texture_ex(
58 AGL_TEXTURE_FLIP|AGL_TEXTURE_MASKED,
59 bmp1, GL_RGBA8); // <-- crashes HERE.
60 
61 destroy_bitmap(bmp1);
62 
63 return 0;
64}
65END_OF_MAIN()

The allegro.log:

1al-main INFO: Allegro initialised (instance 1)
2al-gfx INFO: Called set_gfx_mode(1330072644, 640, 480, 0, 0).
3al-gfx INFO: Firt call, remembering console state.
4* Note * default_gfx_init: Trying to set up windowed mode...
5* Note * win_init(): Requested color depth: 16 Desktop color depth: 16
6* Note * win_init(): Setting up window.
7* Note * win_init(): Driver selected fullscreen: No
8* Note * win_init(): Setting pixel format.
9* Note * select_pixel_format(): Trying to set up temporary RC
10* Note * select_pixel_format(): ChoosePixelFormat()
11* Note * select_pixel_format(): SetPixelFormat()
12* Note * select_pixel_format(): CreateContext()
13* Note * select_pixel_format(): MakeCurrent()
14* Note * select_pixel_format(): GetExtensionsStringARB()
15* Note * select_pixel_format(): GetProcAddress()
16* Note * get_num_pixel_formats(): Attempting to use WGL_pf.
17* Note * select_pixel_format(): 42 formats.
18* Note * select_pixel_format(): Testing pixel formats:
19Format 1:
20 
21[...] /* formats 1 to 3 */
22
23Format 4:
24 Decoding:
25 Acceleration: Yes RGBA: 5.6.5.0 Accum: 16.16.16.16
26 DblBuf: 1 Zbuf: 16 Stereo: 0 Aux: 0 Stencil: 0 Shift: 11.5.0.0
27 Sample Buffers: 0 Samples: 0
28 Decoded bpp: 16
29 Score is : 585
30 
31[...] /* formats 5 to 41 */
32 
33Format 42:
34 Decoding:
35 Can't draw to window
36
37* Note * select_pixel_format(): Best config is: 4
38Decoding:
39 Acceleration: Yes RGBA: 5.6.5.0 Accum: 16.16.16.16
40 DblBuf: 1 Zbuf: 16 Stereo: 0 Aux: 0 Stencil: 0 Shift: 11.5.0.0
41 Sample Buffers: 0 Samples: 0
42 Decoded bpp: 16
43 Score is : 841
44
45* Note * win_init(): GLScreen: 640x480x16
46
47OpenGL Version: 1.3.0 - Build 4.14.10.4342
48Vendor: Intel
49Renderer: Intel 845G
50
51GLU Version : 1.2.2.0 Microsoft Corporation
52
53
54al-gfx INFO: The driver will wait for vsync.
55al-gfx INFO: set_gfx_card success for 640x480x16.
56* Note * make_texture_ex: flags: AGL_TEXTURE_FLIP|AGL_TEXTURE_MASKED|, bitmap 32x32, 16 bpp. internalformat: 0x8058
57* Note * make_texture_ex: Preselected texture format: 0x1907, type: 0x8363
58* Note * munge_bitmap: Need to perform depth conversion from 16 to 16 bpp.
59* Note * munge_bitmap: Flipping bitmap.
60* Note * munge_bitmap: Copying bitmap.
61* Note * munge_bitmap: Inserting alpha channel.

Hmm..... now that i posted it, it seems there's something to do with the line "Acceleration: Yes RGBA: 5.6.5.0 Accum: 16.16.16.16". That is to say, i think i have to change this bit arrangement [5-6-5-0] to something else with the 'A' value>0.
What do you think about that?

Bob

Your code does not compile.

$ gcc temp.c -o temp.exe -mwindows -W -Wall -Wno-unused -O2 -ffast-math -fomit-
frame-pointer -mtune=i686 -mno-cygwin -lagl  -lalleg -luser32 -lgdi32 -lglu32 -
lopengl32 -L/lib/mingw -lmoldname -lmsvcrt
temp.c: In function `_mangled_main':
temp.c:22: warning: `text_mode' is deprecated (declared at /usr/local/include/al
legro/alcompat.h:153)
temp.c:28: error: `nDisplayFlags' undeclared (first use in this function)
temp.c:28: error: (Each undeclared identifier is reported only once
temp.c:28: error: for each function it appears in.)
temp.c:28: error: `DISPFLG_WINDOWED' undeclared (first use in this function)
temp.c:43: error: `WINDOW_W' undeclared (first use in this function)
temp.c:43: error: `WINDOW_H' undeclared (first use in this function)
temp.c:54: warning: `textprintf' is deprecated (declared at /usr/local/include/a
llegro/alcompat.h:175)

Also, can you attach the image file you are using?

Thanks.

anto80

Sorry i had some defines in my MSVC project settings... My fault, sorry. I have updated the code. Should be correct now.

Quote:

Also, can you attach the image file you are using?

As i said in my 2nd post, the bitmap is created internally. the code is here:

BITMAP* bmp1 = create_bitmap(32, 32);
clear_to_color(bmp1, makecol(255,0,255));
textprintf(bmp1, font, 0,0, makecol(0,0,255), "ab"); /* blue */

Bob

It works for me.

1 
2OpenGL Version: 2.0.1
3Vendor: NVIDIA Corporation
4Renderer: GeForce FX 5900/AGP/SSE/3DNOW!
5 
6GLU Version : 1.2.2.0 Microsoft Corporation
7 
8 
9al-gfx INFO: The driver will wait for vsync.
10al-gfx INFO: set_gfx_card success for 640x480x16.
11* Note * make_texture_ex: flags: AGL_TEXTURE_FLIP|AGL_TEXTURE_MASKED|, bitmap 32x32, 16 bpp. internalformat: 0x8058
12* Note * make_texture_ex: Preselected texture format: 0x1907, type: 0x8363
13* Note * munge_bitmap: Need to perform depth conversion from 16 to 32 bpp.
14* Note * munge_bitmap: Flipping bitmap.
15* Note * munge_bitmap: Copying bitmap.
16* Note * munge_bitmap: Inserting alpha channel.

What version of AllegroGL do you have?

anto80

AllegroGL : Latest (0.2.5CVS)

OpenGL: latest drivers for my video card (updated last week).

OpenGL Version: 1.3.0 - Build 4.14.10.4342
Vendor: Intel
Renderer: Intel 845G

Bob
Quote:

AllegroGL : Latest (0.2.5CVS)

0.4.0-RC4 is the latest. That said, this code in particular has not changed since.

The only thing I can recommend at this point is to step through the agl_make_texture_ex() call and try and find out why it thinks it needs to do a 16->16 conversion instead of 16->32.

Milan Mimica

Just be sure, try create_bitmap_ex(32, 32, 16) instead of create_bitmap.

anto80

You were right. create_bitmap_ex(32, w, h) prevents from crashing. The bitmap Thanks.

Milan Mimica

I meant create_bitmap_ex(16, w, h), sorry. The create_bitmap_ex(32, w, h) prevents crashing because It creates a 32-bit bitmap and that's not what you want.

Thread #586613. Printed from Allegro.cc