APXEOLOG's picture

Colored Lines Problem

HI! I added some selecting abilities in my program? and now i have some problems with drawing colored lines (when i draw selection square)

protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
 
            GL.ClearColor(Color.Black);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
 
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Fastest);
        }
 
 protected override void OnRenderFrame(FrameEventArgs e)
        {
 
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
            Matrix4 lookat = Matrix4.LookAt(x, 300, y + 50.0f, x, 0, y, 0, 1, 0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref lookat);
 
            for (.... j loop)
                for (.... i loop)
                {
                    GL.BindTexture(TextureTarget.Texture2D, tex[i, j]]);
                    GL.Begin(BeginMode.Quads);
                    GL.TexCoord2(...);
                    GL.Vertex3(...);
                    GL.TexCoord2(...);
                    GL.Vertex3(...);
                    GL.TexCoord2(...);
                    GL.Vertex3(...);
                    GL.TexCoord2(...);
                    GL.Vertex3(...);          
                    GL.End(); 
 
                    if (currentCell == selectedCell)
                    {
                        GL.Disable(EnableCap.Texture2D);
                        GL.Begin(BeginMode.LineLoop);
 
                        GL.Color3(Color.Red);
                        GL.Vertex3(...);
                        GL.Vertex3(...);
                        GL.Vertex3(...);
                        GL.Vertex3(...);
 
                        GL.End();
                        GL.Enable(EnableCap.Texture2D);   
 
                    }
               }
            SwapBuffers();
     }

My screen after selection is red (see screenshot)
Any ideas?
http://www.opentk.com/files/inline_images/before.JPG
http://www.opentk.com/files/inline_images/after.JPG

PS How the inline images work?

Inline Images

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
migueltk's picture

I think the problem is that you set the color for unselected like this:

for (.... i loop)
                {
                    GL.BindTexture(TextureTarget.Texture2D, tex[i, j]]);
                    GL.Begin(BeginMode.Quads);
                    GL.Color3(0.8f, 0.8f, 0.8f); // New line of code
                    GL.TexCoord2(...);
 
                 ..............

Regards, ...

MiguelTK

APXEOLOG's picture

Hm, no, i have only one GL.Color3 in if() block. Also that's ok without Color line, selection has white color...

c2woody's picture

Did you actually try what migueltk said? As that's most likely your problem, even if you may in the end solve it differently for performance reasons.

the Fiddler's picture

The thing to remember is that OpenGL is a state machine: you set the color and it "sticks" until you change it. It doesn't matter that the color is set to red inside an if-statement. Once that branch is taken, all subsequent vertices will be tinted red unless you reset them.

Migueltk has provided the correct solution.