<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[OpenGL] Lighting causes all colours to go grey</title>
		<link>http://www.allegro.cc/forums/view/589874</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 04 Feb 2007 22:23:27 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve got two games using this same &#39;framework&#39; which is just a shared object file that I&#39;m putting common OpenGL functionality in.</p><p>Anyway, I&#39;m trying to set up a good lighting system here:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//Gl is a namespace BTW</span>
            Gl.glEnable<span class="k2">(</span>Gl.GL_LIGHT0<span class="k2">)</span><span class="k2">;</span>
            Gl.glLightfv<span class="k2">(</span>Gl.GL_LIGHT0, Gl.GL_AMBIENT, <span class="k1">new</span> <span class="k1">float</span><span class="k2">[</span><span class="k2">]</span> <span class="k2">{</span> <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span> <span class="k2">}</span><span class="k2">)</span><span class="k2">;</span>
            Gl.glLightfv<span class="k2">(</span>Gl.GL_LIGHT0, Gl.GL_DIFFUSE, <span class="k1">new</span> <span class="k1">float</span><span class="k2">[</span><span class="k2">]</span> <span class="k2">{</span> <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span>, <span class="n">1</span>.<span class="n">0f</span> <span class="k2">}</span><span class="k2">)</span><span class="k2">;</span>
            Gl.glMaterialfv<span class="k2">(</span>Gl.GL_FRONT, Gl.GL_AMBIENT, <span class="k1">new</span> <span class="k1">float</span><span class="k2">[</span><span class="k2">]</span> <span class="k2">{</span> <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">0f</span> <span class="k2">}</span><span class="k2">)</span><span class="k2">;</span>
            Gl.glLightModelfv<span class="k2">(</span>Gl.GL_LIGHT_MODEL_AMBIENT, <span class="k1">new</span> <span class="k1">float</span><span class="k2">[</span><span class="k2">]</span> <span class="k2">{</span> <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">5f</span>, <span class="n">0</span>.<span class="n">0f</span> <span class="k2">}</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Both games have virtually identical classes|objects at the start of the game (introduction and main menu, etc) but in one game, the texture and all of the glColor3f seems to be overridden because all of the colours are greyish - but the other game is fine.</p><p>Firstly, is there any basic attributes that I&#39;m misconfiguring or not configuring in the code above?</p><p>Secondly, what could override all of the glColor functions to produce all-grey results?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Sat, 03 Feb 2007 19:53:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, if I remember correctly, what overrides the &#39;glColor&#39; calls is the fact that you&#39;re using lighting. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><br />You need to set up the colors using &#39;glMaterial&#39;, which you are setting to gray in your code...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Big)</author>
		<pubDate>Sat, 03 Feb 2007 21:59:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well, if I remember correctly, what overrides the &#39;glColor&#39; calls is the fact that you&#39;re using lighting. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div></div><p>
Nah, light simply affects the colours but it doesn&#39;t make everything the colour of the nearest light or anything. If you project a green light on a green object, that object would look fine but if you project the same light on a purely red object, it should turn black - this is assuming that you&#39;re using diffuse lighting though. But that&#39;s the general idea.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You need to set up the colors using &#39;glMaterial&#39;, which you are setting to gray in your code...
</p></div></div><p>
Are you certain? If I set glMaterial to 0,0,0 , wont I get black? And if I set it to 1,1,1 wont I get white in that case? Which parameter(s) should I be configuring?</p><p>What does get me the most is that it does fine with the other game, which has almost the same code up until past the main menu...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Sat, 03 Feb 2007 22:26:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
He said it right. If lighting is enabled, glColor does nothing. Instead, use glMaterial to modify the diffuse parameter. It does the same thing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 03 Feb 2007 23:15:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah yes, now I understand.</p><p><b>slaps forehead quite hard</b></p><p>I just realised that the texture <i>is</i> actually grey in colour and that the colours came from the glColor parameter - I was hoping of animating the title a little, and the menu selection is just a change in the glColor parameters.</p><p>But it&#39;s good to know that glMaterial would fix this up.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Sat, 03 Feb 2007 23:33:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can also enable GL_COLOR_MATERIAL, which takes the material color out of glColor.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Sun, 04 Feb 2007 13:27:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But that way he won&#39;t learn anything... ;_;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sun, 04 Feb 2007 14:16:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>He just did learn something. Two somethings in fact. glColor is ignored by default for lighting, and GL_COLOR_MATERIAL will enable using the regular colors again for lighting....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 04 Feb 2007 17:49:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, but the right way to deal with lighting is to learn to use the material properties, not to hack around it with GL_COLOR_MATERIAL.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sun, 04 Feb 2007 17:50:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If all you want is a colored light, just use colors <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 04 Feb 2007 18:04:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
He just did learn something.
</p></div></div><p>
Yes! I are smart!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Sun, 04 Feb 2007 18:15:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I had been wondering this myself, actually. It was very annoying behavior. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Gotta try it later ....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sun, 04 Feb 2007 18:54:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Yes, but the right way to deal with lighting is to learn to use the material properties, not to hack around it with GL_COLOR_MATERIAL.
</p></div></div><p>
Not necessarily.<br />If you want your rendering code to render the model correctly both with and without lighting, GL_COLOR_MATERIAL is actually a choice that makes sense. The object rendering code doesn&#39;t need to know whether lighting is enabled, it just sets the color through glColor() and all other properties through glMaterial().<br />Though in practice, your objects would typically all be lit at all times.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sun, 04 Feb 2007 22:23:27 +0000</pubDate>
	</item>
</rss>
