nlraley's picture

After drawing quad or polygon and resizing entire viewport is the color of the quad/poly

Title explains it.

I'm loading a bunch of texture into the background, then drawing a quad or polygon.

Everything draws just fine; however, whenever the form is resized, everything is tinted in the color of the quad/poly.

Here is my code:

//  Draw Rectangle
            GL.MatrixMode(MatrixMode.Modelview);
            GL.Color4(0.0, 0.0, 1.0, 0.5);
            GL.BlendFunc(BlendingFactorSrc.OneMinusConstantAlpha, BlendingFactorDest.SrcAlpha);
            //GL.Color3(Color.Blue);
 
            GL.Begin(BeginMode.Polygon);    
            foreach (Pixels point in tempPoints)
            {
                GL.Vertex3(point.X, point.Y, 0);
            }
            GL.End();
 
            //  Flush the buffer
            GL.Flush();
            //  Swap the buffers
            glControl1.SwapBuffers();

Am I forgetting to close/reset something that is causing everything to be blue once OpenGL has to redraw?


Comments

Comment viewing options

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

You're not actually clearing the previous contents of the buffer by the looks of it.

Something on the lines of:
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
(Also look at GL.ClearColor to set the color used to clear things)

Unless this is somewhere else in your drawing routine already?

nlraley's picture

Sorry, yes, I do that at the very beginning of the Paint routine for the control.

Full repaint from start to finish is:

if (!loaded)
                return;
 
            List<Pixels> tempPoints = new List<Pixels>();
            tempPoints.Add(new Pixels(300, 50));
            tempPoints.Add(new Pixels(200, 200));
            tempPoints.Add(new Pixels(250, 150));
            tempPoints.Add(new Pixels(100, 100));
 
            reference = tempPoints[0];
            tempPoints.Sort(new Comparison<Pixels>(MapUtils.SortPointsClockwise));
 
            //  Fetch the map bounds
            MapUtils.GetMapBounds(ref mapBounds, Program.main.glControl1.Width, Program.main.glControl1.Height);
 
            //  Clear the OpenGL control
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
            //  Enable 2D texturing and blending
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
 
            //  Set the hint
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
 
            //  Fetch displayed tiles
            MapUtils.FetchTiles();
 
            ////  Draw Rectangle
            GL.MatrixMode(MatrixMode.Modelview);
            GL.Color4(0.0, 0.0, 1.0, 0.5);
            GL.BlendFunc(BlendingFactorSrc.OneMinusConstantAlpha, BlendingFactorDest.SrcAlpha);
            ////GL.Color3(Color.Blue);
 
            GL.Begin(BeginMode.Polygon);
            //GL.Vertex3(200, 200, 0);
            //GL.Vertex3(100, 100, 0);
            //GL.Vertex3(300, 50, 0);
            //GL.Vertex3(250, 150, 0);       
            foreach (Pixels point in tempPoints)
            {
                GL.Vertex3(point.X, point.Y, 0);
            }
            GL.End();
 
            //  Flush the buffer
            GL.Flush();
            //  Swap the buffers
            glControl1.SwapBuffers();

Of course the first pass of this works just fine. However, when called again it loads the "Tiles" again and then redraws the rectangle, but everything is covered in a blue tint.

Any ideas? Do I have to Clear the buffer again after drawing the rectangles?

jrwatts's picture

You're setting the draw color to blue with GL.Color4(0.0, 0.0, 1.0, 0.5);, and I don't see anywhere where you reset it to white, so it shouldn't be surprising that everything is colored blue after the first pass. Try adding GL.Color4(1.0, 1.0, 1.0, 1.0) ; after drawing your rectangle.

nlraley's picture

Odd, I'd figure the Color would be limited to the scope of the GL.Begin/End call.

If I enable the blend function and draw the quad, it fails to draw the background tiles. How do you clear/reset the blend function?