<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Shaders not working properly</title>
		<link>http://www.allegro.cc/forums/view/615075</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 14 Feb 2015 13:23:02 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello everyone!</p><p>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.</p><div class="source-code snippet"><div class="inner"><pre>    AddShader<span class="k2">(</span><span class="s">"TEMP"</span>, <span class="s">"Assets\\shaders\\default.vert"</span>, <span class="s">"Assets\\shaders\\temp.frag"</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span>KBKeyDown<span class="k2">(</span>ALLEGRO_KEY_N<span class="k2">)</span><span class="k2">)</span>
        UseShader<span class="k2">(</span><span class="s">"TEMP"</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>GAME_DISPLAY<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span>blackColor<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span>KBKeyDown<span class="k2">(</span>ALLEGRO_KEY_B<span class="k2">)</span><span class="k2">)</span>
        <a href="http://www.allegro.cc/manual/al_draw_scaled_bitmap"><span class="a">al_draw_scaled_bitmap</span></a><span class="k2">(</span>screenBitmap, SCREEN_WIDTH <span class="k3">*</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">-</span> scaleInverse<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span>, SCREEN_HEIGHT <span class="k3">*</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">-</span> scaleInverse<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span>, SCREEN_WIDTH <span class="k3">*</span> scaleInverse, SCREEN_HEIGHT <span class="k3">*</span> scaleInverse, <span class="n">0</span>, <span class="n">0</span>, SCREEN_WIDTH, SCREEN_HEIGHT, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
    UseShader<span class="k2">(</span><span class="s">"NONE"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

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&#39;s more, if I try drawing another bitmap without changing the shader, it is still drawn in it&#39;s normal form - no shaders used. I seriously have no idea what the hell is going on now <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>EDIT : images are uploaded as attachments, sorry for that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Fri, 13 Feb 2015 09:13:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Have you checked to see if your shader calls succeed? Shaders can be a bit finicky.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 13 Feb 2015 09:27:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Since I&#39;m assuming you didn&#39;t look at the attachment, yes, I&#39;m pretty sure the call succeeded, since part of the bitmap is red.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Fri, 13 Feb 2015 09:40:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What does your shader code look like? especially UseShader.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 13 Feb 2015 10:07:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> UseShader<span class="k2">(</span>std::string name<span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">if</span> <span class="k2">(</span>name <span class="k3">=</span><span class="k3">=</span> <span class="s">"NONE"</span><span class="k2">)</span>
        al_use_shader<span class="k2">(</span>nullptr<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">else</span>
        al_use_shader<span class="k2">(</span>shaderList<span class="k2">[</span>name<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

temp.frag
</p><div class="source-code snippet"><div class="inner"><pre>uniform sampler2D al_tex<span class="k2">;</span>
uniform <span class="k1">bool</span> al_use_tex<span class="k2">;</span>

varying vec4 tintColor<span class="k2">;</span>
varying vec2 texCoord<span class="k2">;</span>
varying vec2 fragPos<span class="k2">;</span>

<span class="k1">void</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
    gl_FragColor <span class="k3">=</span> vec4<span class="k2">(</span><span class="n">1</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Fri, 13 Feb 2015 10:11:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you changing your target bitmap while changing shaders? The current shader (set by <span class="source-code">al_use_shader</span>) is local to the target bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 13 Feb 2015 12:42:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nope, I am not. For heaven&#39;s sake, one part of the bitmap (i&#39;m sure it&#39;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&#39;m not messing up with the calls!</p><p>P.S. sorry if I sound exasperated, I&#39;ve been staring at this code for so long trying to figure out why the shader is not working properly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Fri, 13 Feb 2015 21:47:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you show more code? Like, where are you calling al_flip_display?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 13 Feb 2015 21:50:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615075/1010261#target">brisingr123</a> said:</div><div class="quote"><p>Nope, I am not. For heaven&#39;s sake, one part of the bitmap (i&#39;m sure it&#39;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&#39;m not messing up with the calls!</p></div></div><p>I don&#39;t know about that. You are calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a></span> if you changed it at all before the code you showed us, that could easily be causing some issues.</p><p>Can we see your main drawing code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 13 Feb 2015 22:34:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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).</p><p>&quot;The current shader (set by al_use_shader) is local to the target bitmap.&quot;<br />Just curious, does that mean that if I use bitmap A, use shader A_Shader, change my bitmap to B, use a different shader B_Shader and finally switch back to A again, that will still have A_Shader active? I guess I somehow overlooked this technicality. If so, then that might be the cause of my problem. I&#39;ll just go ahead and try playing with my code again, with this assumption.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Fri, 13 Feb 2015 23:44:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try setting the shader after you set the target.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 13 Feb 2015 23:53:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, that did it, and now I&#39;m feeling like a dumb <span class="cuss"><span>ass</span></span> for not realizing that earlier <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><p>Btw, if I&#39;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&#39;m wrong). So why does Allegro bind it&#39;s shaders to target bitmaps, as opposed to having them bound till they are replaced, irrespective of the target bitmaps?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (brisingr123)</author>
		<pubDate>Sat, 14 Feb 2015 00:24:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615075/1010273#target">brisingr123</a> said:</div><div class="quote"><p> So why does Allegro bind it&#39;s shaders to target bitmaps, as opposed to having them bound till they are replaced, irrespective of the target bitmaps? </p></div></div><p>No particular reason. It seems convenient to have a particular shader associated with each intermediate bitmap... but perhaps not that convenient?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 14 Feb 2015 13:23:02 +0000</pubDate>
	</item>
</rss>
