PDA

View Full Version : Adding color to a polygon



Jakeop132
01-21-2011, 08:48 AM
This is a very basic question, but I haven't been able to find an answer to it. I'm trying to display a red triangle. Following lesson 3 of NeHe's tutorial, I tried the following code:


GL.PushMatrix();

GL.Begin(DrawMode.TriangleStrip);

GL.Color4f(1f, 0f, 0f, 1f);
GL.Vertex3f(-2000, 100, -2000);

GL.Color4f(1f, 0f, 0f, 1f);
GL.Vertex3f(-2000, 100, 2000);

GL.Color4f(1f, 0f, 0f, 1f);
GL.Vertex3f(2000, 100, -2000);

GL.End();
GL.PopMatrix();


But the result is a completely black triangle. I'm able to use texCoord to texture map the triangle, but I'm not able to simply color it without texture mapping it. (BTW: I'm using c#).

Jakeop132
01-21-2011, 09:18 AM
Interestingly, if I disable textures, then the triangle is always blue (no matter what color I make the current color). I don't get it.

ugluk
01-21-2011, 10:50 AM
Like always, try rendering points, see if they have different colors, then lines, then .... Play with the GL to debug. If you aren't texturing, then textures should in fact be disabled.

Jakeop132
01-21-2011, 07:13 PM
ugluk, thanks. I'm making progress. Points are too small, so I started with a line. I'm having trouble turning off textures... I can actually get things to work as I'd expect with this code:

GL.PushMatrix();
GL.Begin(DrawMode.Lines);
GL.Color(1f, 1.0f, 1f, 1f);
GL.Vertex(-2, 2, 13);
GL.Vertex(2, 2, 13);
GL.PopMatrix();

It draws a white line, just as it should. However, if I prefix the above code with these lines:
GL.ActivateTexture(TexID.Tex1);
GL.BindTexture(TexMode.Tex2D, TexID.Tex1);
GL.Enable(GLFeature.Tex2D);
GL.Disable(GLFeature.Tex2D);

Then, it draws a gray line. I realize it's silly to enable a texture only to disable it the next line. But in the future, I'd like to draw some things with textures and others without. So, right now I'm trying to figure out how to disable textures. Obviously, glDisable(GL_TEXTURE_2D); doesn't do the trick. What lines of code are required, then, to disable textures?

_arts_
01-22-2011, 02:13 AM
try this:

GL.Enable(GLFeature.Tex2D);
GL.BindTexture(TexMode.Tex2D, TexID.Tex1);
[...]
GL.Disable(GLFeature.Tex2D);

Jakeop132
01-23-2011, 07:06 AM
Thanks. The culprit is glActiveTexture. Once it's active, there seems to be no way of going back...

ugluk
01-23-2011, 07:52 AM
This must be a problem with your library. Why not just use C++? Or maybe you could fit the library yourself.

_arts_
01-25-2011, 04:27 AM
glActiveTexture needs a texture unit identifier, not a texture name id.

ugluk
01-25-2011, 05:59 AM
I agree arts, but then again, one can store practically anything in a variable.