using al_draw_bitmap to draw using pixel shader sampler
bitrex

I'm experimenting with using Allegro 5's API for GLSL shaders in my C++ application. I can successfully use the al_get_default_shader_source() call to retrieve the default vertex shader, write a little glsl shader with uniforms passed in to fool with the colors, link and use it and when drawing my bitmap to the backbuffer everything works out OK.

I'm struggling with getting texture samplers to work though, I've spent some time searching for what glsl shader source code I should use for the vertex and pixel shader so I can just do a basic test of using al_set_shader_sampler() to set an ALLEGRO_BITMAP as the sampler and write the data of the selected bitmap direct to the backbuffer verbatim, but I guess I haven't found the for-dummies-show-me-like-I'm-eight example that I'm looking for. I'm actually not entirely sure whether this is possible or whether to use a glsl sampler texture I have to draw a primitive and render with that...

I'm a little confused by the set of macros listed at <a href="http://liballeg.org/a5docs/trunk/shader.html</a> when I have "ALLEGRO_PROGRAMMABLE_PIPELINE" set. As I understand it these are macros that refer to internal variables used by say the default vertex shader so that I can use its vertex data in my pixel shader? What's the significance of "ALLEGRO_SHADER_VAR_USE_TEX" boolean, do I have to set that to "true" somewhere for samplers to work?

I'd also be interested to know if it's possible to render bitmaps to other video bitmaps with glsl shaders applied efficiently, or if rendering using shaders is only efficient when drawing to the backbuffer.

Thanks for any help ;)

SiegeLord
bitrex said:

but I guess I haven't found the for-dummies-show-me-like-I'm-eight example that I'm looking for.

See the ex_shader_multitex example.

Quote:

I'm a little confused by the set of macros listed at

Don't worry about the macros, they're only there to help you write your shader source in C. If you write them externally, you don't need them (and we don't define them for you in the shade source, although perhaps we could/should).

For the al_use_tex in particular, you can declare it in your shader source, and it'll be set by Allegro's code to signify whether you should render with a texture or not. This differentiates situations when you're using e.g. al_draw_filled_rectangle vs al_draw_bitmap with the same shader.

Quote:

I'd also be interested to know if it's possible to render bitmaps to other video bitmaps with glsl shaders applied efficiently, or if rendering using shaders is only efficient when drawing to the backbuffer.

Both are efficient.

bitrex

Got it up and running, thank you! :D

Thread #616980. Printed from Allegro.cc