So, despite many years of programming experience, I never had anything to do with shaders. I'm more of a game mechanics guy. But I found myself forced to try to write a shader recently, because I want to subtract one texture from another, and on my Tegra-3 based Android device, ALLEGRO_DIST_MINUS_SRC simply don't work at all.
But the problem is, whenever I attach a source for a vertex shader, any kind of output disappears!
Here's the code for drawing:
// Create a sub-bitmap, at coordinates where we want to remove a part of targetBitmap
ALLEGRO_BITMAP *tmp = al_create_sub_bitmap( targetBitmap, x, y, w, h );
al_set_target_bitmap( tmp );
al_use_shader( pShader );
TexPoint tp1( 0, 0, 0, 0 );
TexPoint tp2( w, 0, w, 0 );
TexPoint tp3( w, h, w, h );
TexPoint tp4( 0, h, 0, h );
render.DrawTexturedQuad( m_damageImage, tp1, tp2, tp3, tp4 );
al_set_target_backbuffer( al_get_current_display() );
al_destroy_bitmap( tmp );
if I create the shader in this way:
pShader = al_create_shader( ALLEGRO_SHADER_GLSL );
al_attach_shader_source( pShader, ALLEGRO_VERTEX_SHADER, default_vertex_shader );
al_attach_shader_source( pShader, ALLEGRO_PIXEL_SHADER, my_pixel_shader );
al_build_shader( pShader );
Nothing is visible. However, if I omit attaching vertex shader, then something is drawn at the necessary point.
If I set targetBitmap as a target, instead of sub-bitmap, things seem to work even with vertex shader, but this will lead to problems later, so I would prefer this code to work with sub-bitmap of targetBitmap.
What am I doing wrong here?