Adding color to a polygon

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#).

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.

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.

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?

try this:

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

Thanks. The culprit is glActiveTexture. Once it’s active, there seems to be no way of going back…

This must be a problem with your library. Why not just use C++? Or maybe you could fit the library yourself.

glActiveTexture needs a texture unit identifier, not a texture name id.

I agree arts, but then again, one can store practically anything in a variable.