
Colored Lines Problem
Posted Sunday, 26 September, 2010 - 05:56 by APXEOLOG inHI! 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?


Comments
Re: Colored Lines Problem
I think the problem is that you set the color for unselected like this:
Regards, ...
MiguelTK
Re: Colored Lines Problem
Hm, no, i have only one GL.Color3 in if() block. Also that's ok without Color line, selection has white color...
Re: Colored Lines Problem
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.
Re: Colored Lines Problem
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.