Results 1 to 9 of 9

Thread: Adding color to a polygon

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    20

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

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    20

    Re: Adding color to a polygon

    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.

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    592

    Re: Adding color to a polygon

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    20

    Re: Adding color to a polygon

    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?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Adding color to a polygon

    try this:

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

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    20

    Re: Adding color to a polygon

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

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    592

    Re: Adding color to a polygon

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

  8. #8
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Adding color to a polygon

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

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    592

    Re: Adding color to a polygon

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

Similar Threads

  1. OpenGL 3.1 - Color per polygon
    By FlayedOne in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 10-28-2009, 12:57 PM
  2. Adding color attachment to default frame buffer
    By jesusgumbau in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2008, 12:54 PM
  3. Why the initial color of model disappear after adding light
    By suponlyzx in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-24-2006, 10:20 AM
  4. color of polygon and his outline
    By pato in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-10-2002, 10:03 AM
  5. Different color on each side of a polygon
    By billy in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 01-07-2002, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean