I took the example program from thread 617536 and get it to work OK.
Then I try to use a shader on a bitmap so I change the code:
As new vertex.glsl and fragment.glsl I wanted to use these at 2/3 of the page under "Example: Swapping Color Channels".
edit: changing those shaders to this:
attribute vec2 al_texcoord; attribute vec4 al_pos; varying vec2 varying_texcoord; uniform mat4 al_projview_matrix; void main(void) { varying_texcoord = al_texcoord; gl_Position = al_projview_matrix * al_pos; }
uniform sampler2D al_tex; varying vec2 varying_texcoord; void main(void) { gl_FragColor = texture2D(al_tex, varying_texcoord).bgra; }
helps but introduces a flicker to the screen. Why would that be?
You seem to be drawing bitmap 'bmp' onto itself using the shader.
Possibly this is something you would like to do by design (though I would half expect this to be causing an undefined behavior in OpenGl).
Usually what we do is draw the original bitmap ('bmp' in your case) onto the 'display' using the shader effect. This way 'bmp' remains the same at all times.
Change your code from:
51 al_set_target_bitmap(bmp); 52 al_use_shader(shader); 53// al_set_shader_float_vector("tint", 3, &tints[0], 1); 54 al_draw_bitmap(bmp, 0, 0, 0); 55 al_use_shader(NULL); 56 al_set_target_backbuffer(display); 57 al_clear_to_color(al_map_rgb(215, 255, 255)); 58 al_draw_bitmap(bmp, 0, 0, 0); ...
to:
51 52 al_set_target_backbuffer(display); 53 al_clear_to_color(al_map_rgb(215, 255, 255)); 54 al_use_shader(shader); 55// al_set_shader_float_vector("tint", 3, &tints[0], 1); 56 57 58 al_draw_bitmap(bmp, 0, 0, 0); ...
if that helps?
Yes, that's what it should do. Introducing a timer helps, a bit. Its behaviour is very consistent, the flickering part moves bottom-to-top over the screen, only when using a shader.
Interesting to know that drawing a bitmap onto itself works; using a shader too. I would have used a temporary bitmap for that. 'Live and learn' as they say.
As for synchronizing your program to the refresh rate of your screen please have a look at https://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Timers for an example of using timers to redraw the display.