<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Multiply blending in OpenGL</title>
		<link>http://www.allegro.cc/forums/view/359405</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 13 May 2004 09:53:59 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I asked in #allegro the other day, and despite getting an answer from Bob, it&#39;s still not working right. I need to figure out how to do multiply blending in OpenGL so I can properly overlay a lightmap on a polygon. Yeah I know I should use multitexturing, but besides wanting to support cards that may not have it (I don&#39;t think mine does), the engine is already setup to do a double-pass for lighting. When I asked on IRC, I was told:<br /><span class="source-code">glBlendFunc<span class="k2">(</span>GL_DST_COLOR, GL_ZERO<span class="k2">)</span><span class="k2">;</span></span>however that didn&#39;t work. Doing this, however:<br /><span class="source-code">glBlendFunc<span class="k2">(</span>GL_ZERO, GL_DST_COLOR<span class="k2">)</span><span class="k2">;</span></span>somewhat works, but not fully. That just applies the lightmap&#39;s color to the polygon, but doesn&#39;t actually do the lighting (eg. it doesn&#39;t darken anything, just colorizes).</p><p>Grepping around the gl headers for multiply, google searches for opengl multiply blending, and forum searches for the same have turned up nothing. Can someone tell me what I&#39;m doing wrong?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 12 May 2004 10:58:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Actually, the second one should be &quot;GL_SRC_COLOR&quot;. I&#39;m not sure that OpenGL even allows the dest color to be multiplied by itself like that.</p><p>But yes, the first one ought to work.</p><p>Did you glEnable(GL_BLEND);? A common mistake with many OpenGL states.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Korval)</author>
		<pubDate>Wed, 12 May 2004 11:21:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code">glEnable<span class="k2">(</span>GL_BLEND<span class="k2">)</span><span class="k2">;</span></span>is called, and these are the results:</p><p>No lightmaps:<br /><a href="http://kcat.strangesoft.net/nolight.png">http://kcat.strangesoft.net/nolight.png</a></p><p>with GL_ZERO, GL_DST_COLOR:<br /><a href="http://kcat.strangesoft.net/withlight.png">http://kcat.strangesoft.net/withlight.png</a></p><p>with GL_DST_COLOR, GL_SRC_COLOR:<br /><a href="http://kcat.strangesoft.net/newlight.png">http://kcat.strangesoft.net/newlight.png</a></p><p>If I could subtract the inverse blend color, that might work too, but a tutorial on using Q2 lightmaps says that the lightmap should be multiply-blended on top of the polygon face.</p><p>EDIT:<br />Actually.. you know I&#39;m not even sure if the lightmap is even really working. When I try to display just the lightmap, I get a level full of solid brown (no light or color variation at all). So maybe DST_COLOR, SRC_COLOR does work, but the lightmap just isn&#39;t being used right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 12 May 2004 12:19:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> So maybe DST_COLOR, SRC_COLOR does work, but the lightmap just isn&#39;t being used right.</p></div></div><p>
DST_COLOR, SRC_COLOR will compute:</p><p>final = texture * fb + fb * texture</p><p>You want:</p><p>final = texture * fb</p><p>Which is done either by:</p><p>DST_COLOR, ZERO  (final = texture * fb)<br />or<br />ZERO, SRC_COLOR  (final = fb * texture)</p><p>If you didn&#39;t enable blending, then obviusly it will not work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Thu, 13 May 2004 00:26:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What does the lightmap look like?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Korval)</author>
		<pubDate>Thu, 13 May 2004 05:36:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Originally it was just solid brown. However, playing around with the texture settings (enabling wrapping instead of clamping), I get this to appear. This image shows just the &quot;lightmap&quot;, and not the texture underneath.</p><p><a href="http://kcat.strangesoft.net/lightmap.jpg">http://kcat.strangesoft.net/lightmap.jpg</a></p><p>That does not at all look right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 13 May 2004 06:02:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, I should add that Quake plays with the gamma setting to lighten up the game. Most likely, the textures are inverse-gamma-corrected to compensate.</p><p>So if you don&#39;t also change the gamma ramps, you won&#39;t get the same effect.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Thu, 13 May 2004 07:58:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>That does not at all look right.</p></div></div><p>

Is that the image you loaded? That doesn&#39;t look like a resonable light map.</p><p>Are you loading it or generating it by hand?</p><p>Also, since it&#39;s a light map, you may want to consider using an Intensity or Luminance format, rather than an RGB one. They take up much less room (on hardware that can support them).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Korval)</author>
		<pubDate>Thu, 13 May 2004 08:12:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>That doesn&#39;t look like a resonable light map.</p></div></div><p>
It might be a colored lightmap. Arguably, colored lightmaps have limited uses, but still... <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Thu, 13 May 2004 08:15:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s the lightmap the engine takes from the Quake 2 demo pak. As an update, I finally got it working. The original source used min/max where the proper header wasn&#39;t included in Linux. I created static inline versions using Bob&#39;s branchless method, but failed to realize min/max could be, and were, used on floats. It was getting the wrong image all along. So I made simple defines that dealt with any number type, and it all looks pretty now. Though it seems the gamma needs to be played with a bit (the game palette&#39;s intensity is doubled, so that&#39;s what I&#39;m going to try to do to the lightmap). I&#39;ll post a screeny when I do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 13 May 2004 08:40:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Glad you got it working!</p><p>[Insert secret purpose for post]So Kitty Cat can post pretty screenies![/Insert secret purpose for post]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Thu, 13 May 2004 09:42:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok. I&#39;m not sure what to do about the lightmap. When I run it it looks properly lit to me, but I dunno. Here&#39;s a screenie:<br /><a href="http://kcat.strangesoft.net/works.jpg">http://kcat.strangesoft.net/works.jpg</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 13 May 2004 09:50:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Whoa.</p><p>Sweet screenie ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 13 May 2004 09:53:59 +0000</pubDate>
	</item>
</rss>
