|
Shaders not working properly |
brisingr123
Member #15,673
July 2014
|
Hello everyone! I was just messing around in my game, and I across a very strange behavior with shaders. Here is the code I was using, just for reference. AddShader("TEMP", "Assets\\shaders\\default.vert", "Assets\\shaders\\temp.frag"); if (KBKeyDown(ALLEGRO_KEY_N)) UseShader("TEMP"); al_set_target_bitmap(al_get_backbuffer(GAME_DISPLAY)); al_clear_to_color(blackColor); if (KBKeyDown(ALLEGRO_KEY_B)) al_draw_scaled_bitmap(screenBitmap, SCREEN_WIDTH * (1 - scaleInverse) / 2, SCREEN_HEIGHT * (1 - scaleInverse) / 2, SCREEN_WIDTH * scaleInverse, SCREEN_HEIGHT * scaleInverse, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); UseShader("NONE"); 1, 2 and 3 are the images showing the outputs with B (not darwing the bitmap), with B but not N (drawing it without the shader), and B and N (drawing it with shader). The shader is a simple shader that sets every pixel to (1, 0, 0). So why this strange behaviour? What's more, if I try drawing another bitmap without changing the shader, it is still drawn in it's normal form - no shaders used. I seriously have no idea what the hell is going on now EDIT : images are uploaded as attachments, sorry for that. |
Thomas Fjellstrom
Member #476
June 2000
|
Have you checked to see if your shader calls succeed? Shaders can be a bit finicky. -- |
brisingr123
Member #15,673
July 2014
|
Since I'm assuming you didn't look at the attachment, yes, I'm pretty sure the call succeeded, since part of the bitmap is red. |
Thomas Fjellstrom
Member #476
June 2000
|
What does your shader code look like? especially UseShader. -- |
brisingr123
Member #15,673
July 2014
|
void UseShader(std::string name) { if (name == "NONE") al_use_shader(nullptr); else al_use_shader(shaderList[name]); } temp.frag uniform sampler2D al_tex; uniform bool al_use_tex; varying vec4 tintColor; varying vec2 texCoord; varying vec2 fragPos; void main() { gl_FragColor = vec4(1, 0, 0, 1); }
|
SiegeLord
Member #7,827
October 2006
|
Are you changing your target bitmap while changing shaders? The current shader (set by al_use_shader) is local to the target bitmap. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
brisingr123
Member #15,673
July 2014
|
Nope, I am not. For heaven's sake, one part of the bitmap (i'm sure it's all one bitmap, since not drawing it draws a blank screen) is being drawn red, and the other half is being drawn with the proper colors! That has to proof enough that I'm not messing up with the calls! P.S. sorry if I sound exasperated, I've been staring at this code for so long trying to figure out why the shader is not working properly. |
Elias
Member #358
May 2000
|
Can you show more code? Like, where are you calling al_flip_display? -- |
Thomas Fjellstrom
Member #476
June 2000
|
brisingr123 said: Nope, I am not. For heaven's sake, one part of the bitmap (i'm sure it's all one bitmap, since not drawing it draws a blank screen) is being drawn red, and the other half is being drawn with the proper colors! That has to proof enough that I'm not messing up with the calls! I don't know about that. You are calling al_set_target_bitmap if you changed it at all before the code you showed us, that could easily be causing some issues. Can we see your main drawing code? -- |
brisingr123
Member #15,673
July 2014
|
The code before this just draws things to screenBitmap, and this is the final thing that draws the screenBitmap to my display. After this, I draw FPS, and flip the display (no more functions calls whatsoever to allegro, except one al_draw_text to draw the FPS). "The current shader (set by al_use_shader) is local to the target bitmap." |
Thomas Fjellstrom
Member #476
June 2000
|
Try setting the shader after you set the target. -- |
brisingr123
Member #15,673
July 2014
|
Yeah, that did it, and now I'm feeling like a dumb ass for not realizing that earlier Btw, if I'm not wrong, the last time I used vanilla openGl, the shader was constant till the time you changed it - and not dependent on the target (been a long time since I used it, so please correct me if I'm wrong). So why does Allegro bind it's shaders to target bitmaps, as opposed to having them bound till they are replaced, irrespective of the target bitmaps? |
SiegeLord
Member #7,827
October 2006
|
brisingr123 said: So why does Allegro bind it's shaders to target bitmaps, as opposed to having them bound till they are replaced, irrespective of the target bitmaps? No particular reason. It seems convenient to have a particular shader associated with each intermediate bitmap... but perhaps not that convenient? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
|