Пример #1
0
        static void DrawQuad(uint texture)
        {
            int width, height;

            Glfw.GetFramebufferSize(Glfw.GetCurrentContext(), out width, out height);

            Gl.Viewport(0, 0, width, height);

            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(0f, 1f, 0f, 1f, 0f, 1f);

            Gl.Enable(EnableCap.Texture2d);
            Gl.BindTexture(TextureTarget.Texture2d, texture);
            Gl.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, Gl.MODULATE);

            Gl.Begin(PrimitiveType.Quads);

            Gl.TexCoord2(0f, 0f);
            Gl.Vertex2(0f, 0f);

            Gl.TexCoord2(1f, 0f);
            Gl.Vertex2(1f, 0f);

            Gl.TexCoord2(1f, 1f);
            Gl.Vertex2(1f, 1f);

            Gl.TexCoord2(0f, 1f);
            Gl.Vertex2(0f, 1f);

            Gl.End();
        }
Пример #2
0
        private void DrawSquare()
        {
            if (square.Point1X == 0f && square.Point1Y == 0f && square.Point2X == 0f && square.Point2Y == 0f)
            {
                return;
            }

            Gl.PushMatrix();
            Gl.LoadIdentity();

            Gl.Translate(Wight / 2 + moveX, -Height / 2 - moveY, -1f);

            Gl.Begin(OpenGL.GL_LINE_STRIP);

            Gl.Color(0f, 0f, 0f);

            Gl.Vertex(square.Point1X, square.Point1Y);
            Gl.Vertex(square.Point2X, square.Point1Y);
            Gl.Vertex(square.Point2X, square.Point2Y);
            Gl.Vertex(square.Point1X, square.Point2Y);
            Gl.Vertex(square.Point1X, square.Point1Y);

            Gl.End();

            Gl.PopMatrix();
        }
Пример #3
0
        /// <summary>
        /// Old school OpenGL 1.0 drawing.
        /// </summary>
        private void RenderControl_RenderGL100()
        {
            // Setup model-view matrix

            // Model-view matrix selector
            Gl.MatrixMode(MatrixMode.Modelview);
            // Load (reset) to identity
            Gl.LoadIdentity();
            // Multiply with rotation matrix (around Z axis)
            Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f);

            // Draw triangle using immediate mode (8 draw call)

            // Start drawing triangles
            Gl.Begin(PrimitiveType.Triangles);

            // Feed triangle data: color and position
            // Note: vertex attributes (color, texture coordinates, ...) are specified before position information
            // Note: vertex data is passed using method calls (performance killer!)
            Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
            Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
            Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);

            // Triangles ends
            Gl.End();
        }
Пример #4
0
        protected void Run()
        {
            while (!_mainWindow.Closing)
            {
                if (!_mainWindow.HandleEvents())
                {
                    return;
                }

                Gl.Clear(Gl.ColorBufferBit);
                Gl.ClearColor(0.6901961f, 0.1921569f, 0.2470588f, 1);

                Gl.MatrixMode(Gl.Projection);
                Gl.LoadIdentity();
                Gl.Ortho(0, 1, 0, 1, 0, 1);

                Gl.Begin(Gl.Triangles);
                Gl.Color3(1, 0, 0);
                Gl.Vertex2(0, 0);
                Gl.Color3(0, 1, 0);
                Gl.Vertex2(0.5f, 1);
                Gl.Color3(0, 0, 1);
                Gl.Vertex2(1, 0);
                Gl.End();

                //Gl.Clear(Gl.ColorBufferBit);

                _mainWindow.Swap();
            }
        }
Пример #5
0
        public void DrawAxis(float px, float py, float pz, float dist, float thick)
        {
            Gl.Viewport(30, this.glControl.ClientSize.Height - 200, 150, 150);
            Gl.PushMatrix();
            Gl.LoadIdentity();

            Gl.LineWidth(thick);

            Gl.Translate(0, 0, 0);
            Gl.Rotate(this.camera.Pitch, 1, 0, 0);
            Gl.Rotate(this.camera.Yaw, 0, 1, 0);
            Gl.Rotate(this.camera.Roll, 0, 0, 1);
            Gl.Scale(1, 1, 1);
            this.Text = $"CogiEngine (Deubg : camera dir x = {camera.Pitch}, y ={camera.Yaw}, z = {camera.Roll}";
            //X - Red
            Gl.Begin(PrimitiveType.Lines);
            Gl.Color3(1f, 0f, 0f);
            Gl.Vertex3(px, py, pz);
            Gl.Vertex3(px + dist, py, pz);

            //Y - Blue
            Gl.Color3(0, 0, 1f);
            Gl.Vertex3(px, py, pz);
            Gl.Vertex3(px, py + dist, pz);

            //Z - Green
            Gl.Color3(0f, 1f, 0f);
            Gl.Vertex3(px, py, pz);
            Gl.Vertex3(px, py, pz + dist);
            Gl.End();

            Gl.PopMatrix();
        }
Пример #6
0
        public void Test_Draw()
        {
            //moveX = 20000;
            //moveY = -20000;
            //Gl.Translate(moveX * c * kX, -moveY * c * kY, -1f);
            Gl.Translate(moveX, -moveY, -1f);
            double _scale = Scale;

            Gl.Scale(_scale, _scale, 1.0);


            Gl.Color(0f, 1f, 0f);
            Gl.Begin(OpenGL.GL_LINE_STRIP);

            Gl.Vertex(2d, -1000000);
            Gl.Vertex(2d, 1000000);

            Gl.End();

            Gl.Color(0f, 0f, 1f);
            Gl.Begin(OpenGL.GL_LINE_STRIP);

            Gl.Vertex(500d, 0);
            Gl.Vertex(15000d, 1000000);

            Gl.End();

            Gl.Color(1f, 0f, 0f);
            Gl.Begin(OpenGL.GL_LINE_STRIP);

            Gl.Vertex(-1000000, 2); //659
            Gl.Vertex(1000000, 2);

            Gl.End();
        }
Пример #7
0
        private void glControl_Render(object sender, GlControlEventArgs e)
        {
            try {
                Gl.VertexPointer(2, VertexPointerType.Float, 0, ArrayPosition);
                Gl.EnableClientState(EnableCap.VertexArray);
                Gl.TexCoordPointer(2, TexCoordPointerType.Float, 0, ArrayTexCoord);
                Gl.EnableClientState(EnableCap.TextureCoordArray);

                var control = sender as Control;
                Gl.Viewport(0, 0, control.ClientSize.Width, control.ClientSize.Height);
                Gl.Clear(ClearBufferMask.ColorBufferBit);
                Gl.BindTexture(TextureTarget.Texture2d, texture);

                if (Gl.CurrentVersion >= Gl.Version_110)
                {
                    Gl.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
                }
                else
                {
                    Gl.Begin(PrimitiveType.TriangleStrip);
                    for (var i = 0; i < ArrayPosition.Length; i += 2)
                    {
                        Gl.TexCoord2(ArrayTexCoord[i], ArrayTexCoord[i + 1]);
                        Gl.Vertex2(ArrayPosition[i], ArrayPosition[i + 1]);
                    }
                    Gl.End();
                }
            }
            catch {
            }
        }
Пример #8
0
 public void DrawDecalQuad(DecalInstance decal)
 {
     Gl.BindTexture(TextureTarget.Texture2d, (uint)decal.decal.id);
     Gl.Begin(PrimitiveType.Quads);
     Gl.Color4(decal.tint.r, decal.tint.g, decal.tint.b, decal.tint.a);
     Gl.TexCoord4(decal.uv[0].x, decal.uv[0].y, 0.0f, decal.w[0]); Gl.Vertex2(decal.pos[0].x, decal.pos[0].y);
     Gl.TexCoord4(decal.uv[1].x, decal.uv[1].y, 0.0f, decal.w[1]); Gl.Vertex2(decal.pos[1].x, decal.pos[1].y);
     Gl.TexCoord4(decal.uv[2].x, decal.uv[2].y, 0.0f, decal.w[2]); Gl.Vertex2(decal.pos[2].x, decal.pos[2].y);
     Gl.TexCoord4(decal.uv[3].x, decal.uv[3].y, 0.0f, decal.w[3]); Gl.Vertex2(decal.pos[3].x, decal.pos[3].y);
     Gl.End();
 }
Пример #9
0
        public override void Paint(Rectangle visibleTiles, MapLocation mouseLocationOnMap)
        {
            if (_toolStep > ToolStep.SetOrigin)
            {
                Gl.Begin(PrimitiveType.Triangles);

                RenderQuad(Owner.TextureMap[MapTileVisual.Origin], Owner.GetMapLocationOnClient(_origin), new Color4()
                {
                    A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F
                });

                if (_toolStep > ToolStep.SetDestination)
                {
                    RenderQuad(Owner.TextureMap[MapTileVisual.Destination], Owner.GetMapLocationOnClient(_destination), new Color4()
                    {
                        A = 1.0f, R = 1.0f, G = 1.0F, B = 1.0F
                    });
                }

                Gl.End();

                if (_toolStep == ToolStep.Pathfind && _computedPath?.Path?.Length > 0)
                {
                    Gl.Disable(EnableCap.Texture2d);

                    Gl.Begin(PrimitiveType.Lines);
                    Gl.Color3(0.0f, 0.0f, 1.0f);
                    var start = Owner.GetMapLocationOnClient(_computedPath.Path[0]);

                    for (int i = 1; i < _computedPath.Path.Length; i++)
                    {
                        var end = Owner.GetMapLocationOnClient(_computedPath.Path[i]);
                        Gl.Vertex2(start.X + start.Width / 2, start.Y + start.Height / 2);
                        Gl.Vertex2(end.X + end.Width / 2, end.Y + end.Height / 2);
                        start = end;
                    }
                    Gl.End();

                    Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                    Gl.Enable(EnableCap.Blend);
                    Gl.Begin(PrimitiveType.Triangles);

                    foreach (var coloredTile in _computedPath.ColoredTiles)
                    {
                        RenderQuad(Owner.TextureMap[MapTileVisual.White], Owner.GetMapLocationOnClient(coloredTile), new Color4()
                        {
                            A = 0.2f, R = 0.0f, G = 0.0F, B = 1.0F
                        });
                    }

                    Gl.End();
                }
            }
        }
Пример #10
0
 public void DrawRectangle(Pen pen, RectangleF r)
 {
     Gl.PolygonMode(Gl.GL_FRONT, Gl.GL_LINE);
     Gl.LineWidth(pen.Width);
     Gl.Color(pen.Color);
     Gl.Begin(Gl.GL_QUADS);
     Gl.Vertex(r.Left, r.Top);
     Gl.Vertex(r.Left, r.Bottom);
     Gl.Vertex(r.Right, r.Bottom);
     Gl.Vertex(r.Right, r.Top);
     Gl.End();
 }
Пример #11
0
        // method for drawing a line segment from the DataBuffer
        public static void LineSegment(float x1, float y1, float x2, float y2)
        {
            Gl.Begin(PrimitiveType.LineStrip);
            Gl.Vertex2(x1, y1);
            Gl.Vertex2(x2, y2);
            Gl.End();

            //Gl.Color3(.3f, .7f, .7f);
            //Gl.Begin(PrimitiveType.Points);
            //Gl.Vertex2(x1, y1);
            //Gl.End();
        }
Пример #12
0
        private void glControl_Render(object sender, GlControlEventArgs e)
        {
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Gl.Begin(PrimitiveType.Polygon);
            Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.5f, 0.1f);
            Gl.Color3(1.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.333333f);
            Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.333333f, 0.666666f);
            Gl.Color3(0.0f, 1.0f, 1.0f); Gl.Vertex2(0.5f, 0.9f);
            Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.666666f);
            Gl.Color3(1.0f, 0.0f, 1.0f); Gl.Vertex2(0.666666f, 0.333333f);
            Gl.End();
        }
 public void DrawDistortedSprite(SegaSaturnDistortedSprite sprite)
 {
     if (sprite.TextureId.HasValue)
     {
         Gl.Enable(EnableCap.Texture2d);
         Gl.BindTexture(TextureTarget.Texture2d, sprite.TextureId.Value);
     }
     Gl.Color4(1.0f, 1.0f, 1.0f, sprite.UseHalfTransparency ? 0.5f : 1.0f);
     Gl.Begin(PrimitiveType.Quads);
     if (sprite.TextureId.HasValue)
     {
         Gl.TexCoord2(0.0, 0.0);
     }
     else
     {
         Gl.Color3(1.0f, 0.0f, 0.0f);
     }
     Gl.Vertex3(sprite.A.FloatX, sprite.A.FloatY, sprite.A.FloatZ);
     if (sprite.TextureId.HasValue)
     {
         Gl.TexCoord2(1.0, 0.0);
     }
     else
     {
         Gl.Color3(0.0f, 1.0f, 0.0f);
     }
     Gl.Vertex3(sprite.B.FloatX, sprite.B.FloatY, sprite.B.FloatZ);
     if (sprite.TextureId.HasValue)
     {
         Gl.TexCoord2(1.0, 1.0);
     }
     else
     {
         Gl.Color3(0.0f, 0.0f, 1.0f);
     }
     Gl.Vertex3(sprite.C.FloatX, sprite.C.FloatY, sprite.C.FloatZ);
     if (sprite.TextureId.HasValue)
     {
         Gl.TexCoord2(0.0, 1.0);
     }
     else
     {
         Gl.Color3(1.0f, 0.0f, 1.0f);
     }
     Gl.Vertex3(sprite.D.FloatX, sprite.D.FloatY, sprite.D.FloatZ);
     Gl.End();
     if (sprite.TextureId.HasValue)
     {
         Gl.Disable(EnableCap.Texture2d);
     }
 }
Пример #14
0
 public void DrawLayerQuad(VectorF2d offset, VectorF2d scale, Pixel tint)
 {
     Gl.Begin(PrimitiveType.Quads);
     Gl.Color4(tint.r, tint.g, tint.b, tint.a);
     Gl.TexCoord2(0.0f * scale.x + offset.x, 1.0f * scale.y + offset.y);
     Gl.Vertex3(-1.0f /*+ vSubPixelOffset.x*/, -1.0f /*+ vSubPixelOffset.y*/, 0.0f);
     Gl.TexCoord2(0.0f * scale.x + offset.x, 0.0f * scale.y + offset.y);
     Gl.Vertex3(-1.0f /*+ vSubPixelOffset.x*/, 1.0f /*+ vSubPixelOffset.y*/, 0.0f);
     Gl.TexCoord2(1.0f * scale.x + offset.x, 0.0f * scale.y + offset.y);
     Gl.Vertex3(1.0f /*+ vSubPixelOffset.x*/, 1.0f /*+ vSubPixelOffset.y*/, 0.0f);
     Gl.TexCoord2(1.0f * scale.x + offset.x, 1.0f * scale.y + offset.y);
     Gl.Vertex3(1.0f /*+ vSubPixelOffset.x*/, -1.0f /*+ vSubPixelOffset.y*/, 0.0f);
     Gl.End();
 }
Пример #15
0
        public void draw()
        {
            if (available)
            {
                image_handler.draw();

                // If the Positional tracking is good, we can draw the mesh over the current image
                Gl.Disable(EnableCap.Texture2d);
                if (tracking_state == POSITIONAL_TRACKING_STATE.OK)
                {
                    // Send the projection and the Pose to the GLSL shader to make the projection of the 2D image.
                    Matrix4x4.Invert(pose, out Matrix4x4 pose_inv);
                    Matrix4x4 vpMatrix = projection_ * pose_inv;
                    Gl.UseProgram(meshObject.shader.it.getProgramId());
                    Gl.UniformMatrix4f((int)meshObject.shader.MVP_Mat, 1, true, vpMatrix);

                    float3 clrPlane = getPlaneColor(meshObject.type);
                    Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    Gl.Uniform3f(meshObject.shader.shColorLoc, 1, clrPlane);
                    meshObject.draw();

                    Gl.LineWidth(0.5f);
                    Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                    Gl.Uniform3f(meshObject.shader.shColorLoc, 1, clrPlane);
                    meshObject.draw();
                    Gl.UseProgram(0);
                    Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                }


                float cx = userAction.hitCoord.X * 2.0f - 1.0f;
                float cy = (userAction.hitCoord.Y * 2.0f - 1.0f) * -1.0f;

                float lx = 0.02f;
                float ly = lx * (wnd_w / (1.0f * wnd_h));

                Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                Gl.LineWidth(2.0f);
                Gl.Color3(0.2f, 0.45f, 0.9f);
                Gl.Begin(PrimitiveType.Lines);
                Gl.Vertex3(cx - lx, cy, 0.0f);
                Gl.Vertex3(cx + lx, cy, 0.0f);
                Gl.Vertex3(cx, cy - ly, 0.0f);
                Gl.Vertex3(cx, cy + ly, 0.0f);
                Gl.End();
                Gl.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            }
        }
Пример #16
0
        protected override void OnGlPaint(ref PaintStruct ps)
        {
            Gl.Clear(ClearBufferMask.ColorBufferBit);
            var size = this.GetClientSize();

            Gl.Viewport(0, 0, size.Width, size.Height);
            Gl.Begin(PrimitiveType.Triangles);
            Gl.Color3(1.0f, 0.0f, 0.0f);
            Gl.Vertex2(0.0f, 0.0f);
            Gl.Color3(0.0f, 1.0f, 0.0f);
            Gl.Vertex2(0.5f, 1.0f);
            Gl.Color3(0.0f, 0.0f, 1.0f);
            Gl.Vertex2(1.0f, 0.0f);
            Gl.End();
            this.DeviceContext.SwapBuffers();
        }
Пример #17
0
		private static void RenderOsd(int w, int h)
		{
			Gl.Viewport(0, 0, w, h);
			Gl.Clear(ClearBufferMask.ColorBufferBit);

			Gl.MatrixMode(MatrixMode.Projection);
			Gl.LoadIdentity();
			Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0);
			Gl.MatrixMode(MatrixMode.Modelview);
			Gl.LoadIdentity();

			Gl.Begin(PrimitiveType.Triangles);
			Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
			Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
			Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
			Gl.End();
		}
Пример #18
0
        private void Draw_grid()
        {
            double intervalY = Height / 6;
            double intervalX = Wight / 7;

            Gl.PushMatrix();
            Gl.LoadIdentity();

            Gl.Translate(Wight / 2, -Height / 2, -1f);
            // Указываем цвет вершин
            Gl.Color(0.8f, 0.8f, 0.8f);
            for (int j = 1; j <= 7; j++)
            {
                Gl.Begin(OpenGL.GL_LINE_STRIP);
                Gl.Vertex((intervalX * j - Wight * 0.5), -Height / 2);
                Gl.Vertex((intervalX * j - Wight * 0.5), Height / 2);
                Gl.End();
            }

            for (int j = 1; j <= 6; j++)
            {
                Gl.Begin(OpenGL.GL_LINE_STRIP);
                Gl.Vertex(-Wight / 2, (-intervalY * j + Height * 0.5));
                Gl.Vertex(Wight / 2, (-intervalY * j + Height * 0.5));
                Gl.End();
            }


            Gl.Color(0f, 0f, 0f);
            Gl.DrawText(0, (int)intervalY * 5, 0, 0, 0, "", 11, ((-intervalY * 1 + moveY + Height * 0.5) / ScaleY).ToString("N3"));
            Gl.DrawText(0, (int)intervalY * 4, 0, 0, 0, "", 11, ((-intervalY * 2 + moveY + Height * 0.5) / ScaleY).ToString("N3"));
            Gl.DrawText(0, (int)intervalY * 3, 0, 0, 0, "", 11, ((-intervalY * 3 + moveY + Height * 0.5) / ScaleY).ToString("N3"));
            Gl.DrawText(0, (int)intervalY * 2, 0, 0, 0, "", 11, ((-intervalY * 4 + moveY + Height * 0.5) / ScaleY).ToString("N3"));
            Gl.DrawText(0, (int)intervalY * 1, 0, 0, 0, "", 11, ((-intervalY * 5 + moveY + Height * 0.5) / ScaleY).ToString("N3"));


            Gl.DrawText((int)intervalX * 1, 0, 0, 0, 0, "", 11, ((intervalX * 1 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));
            Gl.DrawText((int)intervalX * 2, 0, 0, 0, 0, "", 11, ((intervalX * 2 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));
            Gl.DrawText((int)intervalX * 3, 0, 0, 0, 0, "", 11, ((intervalX * 3 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));
            Gl.DrawText((int)intervalX * 4, 0, 0, 0, 0, "", 11, ((intervalX * 4 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));
            Gl.DrawText((int)intervalX * 5, 0, 0, 0, 0, "", 11, ((intervalX * 5 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));
            Gl.DrawText((int)intervalX * 6, 0, 0, 0, 0, "", 11, ((intervalX * 6 - moveX - Wight * 0.5) / (ScaleX * 1000)).ToString("N3"));

            Gl.PopMatrix();
        }
Пример #19
0
        private void GlControl_Render(object sender, GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f);

            // This method is shared between the two GlControl
            // Uses the texture created with the GlControl1 on both controls
            Gl.BindTexture(TextureTarget.Texture2d, _SharedTexture);

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexTexCoordLock = new MemoryLock(_ArrayTexCoord))
                    {
                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.TexCoordPointer(2, TexCoordPointerType.Float, 0, vertexTexCoordLock.Address);
                        Gl.EnableClientState(EnableCap.TextureCoordArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                    }
            }
            else
            {
                // Old school OpenGL
                Gl.Begin(PrimitiveType.Triangles);
                for (int i = 0; i < _ArrayPosition.Length; i += 2)
                {
                    Gl.TexCoord2(_ArrayTexCoord[i], _ArrayTexCoord[i + 1]);
                    Gl.Vertex2(_ArrayPosition[i], _ArrayPosition[i + 1]);
                }
                Gl.End();
            }

            _Angle += 1.0f;
        }
Пример #20
0
        private bool SwapBuffersHook(IntPtr hdc)
        {
            //var context = Wgl.CreateContext(hdc);
            Prepare2D();
            //// Do drawing

            Gl.Color3(255, 0, 0);
            Gl.Begin(PrimitiveType.Quads);

            Gl.Vertex2(150, 150);
            Gl.Vertex2(500, 150);
            Gl.Vertex2(500, 500);
            Gl.Vertex2(150, 500);

            Gl.End();

            RestoreOpenGl();
            return(SwapBuffers(hdc));
        }
Пример #21
0
        private void GlControl_Render(object sender, OpenGL.GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            // FIXME I wonder why the viewport is affected when the GlControl is hosted in WPF windows.
            int vpx = -senderControl.ClientSize.Width;
            int vpy = -senderControl.ClientSize.Height;
            int vpw = senderControl.ClientSize.Width * 2;
            int vph = senderControl.ClientSize.Height * 2;

            Gl.Viewport(vpx, vpy, vpw, vph);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                    {
                        // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                        // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                    }
            }
            else
            {
                // Old school OpenGL
                Gl.Begin(PrimitiveType.Triangles);
                Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
                Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
                Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
                Gl.End();
            }
        }
Пример #22
0
        private void RenderControl_Render_GL(object sender, GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            // Animate triangle
            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();
            Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f);

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                    {
                        // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                        // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                    }
            }
            else
            {
                // Old school OpenGL
                Gl.Begin(PrimitiveType.Triangles);
                Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
                Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
                Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
                Gl.End();
            }
        }
Пример #23
0
        private void RenderControl_Render(object sender, GlControlEventArgs e)
        {
            lock (_drawLock)
            {
                Gl.Enable(EnableCap.Texture2d);
                Gl.ClearColor(Color.Gray.R / 255.0f, Color.Gray.G / 255.0f, Color.Gray.B / 255.0f, 0);
                Gl.Clear(ClearBufferMask.ColorBufferBit);

                if (_ui.gameStarted)
                {
                    Gl.MatrixMode(MatrixMode.Projection);
                    Gl.LoadIdentity();
                    Gl.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
                    Gl.Ortho(0d, 1d, 0d, 1d, -1d, 1d);
                    Gl.MatrixMode(MatrixMode.Modelview);
                    Gl.LoadIdentity();

                    Gl.BindTexture(TextureTarget.Texture2d, _textureId);

                    using (MemoryLock locked = new MemoryLock(_ui.rawBitmap))
                    {
                        Gl.TexImage2D(TextureTarget.Texture2d, 0, InternalFormat.Rgba, UI.GameWidth, UI.GameHeight, 0,
                                      PixelFormat.Bgra, PixelType.UnsignedByte, locked.Address);
                    }

                    Gl.TextureParameterEXT(_textureId, TextureTarget.Texture2d, TextureParameterName.TextureMagFilter,
                                           _ui._filterMode == UI.FilterMode.Linear ? Gl.LINEAR : Gl.NEAREST);

                    Gl.Begin(PrimitiveType.Quads);
                    Gl.TexCoord2(0, 1);
                    Gl.Vertex2(0, 0);
                    Gl.TexCoord2(0, 0);
                    Gl.Vertex2(0, 1);
                    Gl.TexCoord2(1, 0);
                    Gl.Vertex2(1, 1);
                    Gl.TexCoord2(1, 1);
                    Gl.Vertex2(1, 0);
                    Gl.End();
                }
            }
        }
Пример #24
0
        private void Draw_Markers()
        {
            int s = 0;

            Gl.Color(1f, 0f, 0f);

            foreach (double mark in markers.LMarkers)
            {
                s++;
                Gl.Begin(OpenGL.GL_LINE_STRIP);
                //Gl.Color(0f, 0f, 0f);

                Gl.Vertex(mark * 1000, (-Height / 2 + moveY) / ScaleY);
                Gl.Vertex(mark * 1000, (Height / 2 + moveY) / ScaleY);

                //Gl.Vertex(0.001, -Height / 2 + moveY);
                //Gl.Vertex(0.001, Height / 2 + moveY);

                Gl.End();
            }
        }
Пример #25
0
        public override void Paint(Rectangle visibleTiles, MapLocation mouseLocationOnMap)
        {
            int size    = Math.Max(0, Size);
            var minimum = mouseLocationOnMap.Move(MapDirection.South | MapDirection.West, size);
            var maximum = mouseLocationOnMap.Move(MapDirection.North | MapDirection.East, size);
            var area    = Rectangle.Union(Owner.GetMapLocationOnClient(minimum), Owner.GetMapLocationOnClient(maximum));

            Gl.Begin(PrimitiveType.Lines);

            Gl.Color3(0.0f, 0.0f, 0.0f);
            Gl.Vertex2(area.X, area.Y);
            Gl.Vertex2(area.Right, area.Y);
            Gl.Vertex2(area.Right, area.Y);
            Gl.Vertex2(area.Right, area.Bottom);
            Gl.Vertex2(area.Right, area.Bottom);
            Gl.Vertex2(area.X, area.Bottom);
            Gl.Vertex2(area.X, area.Bottom);
            Gl.Vertex2(area.X, area.Y);

            Gl.End();
        }
        public void DrawAxis(bool x, bool y, bool z)
        {
            const float arrowLength    = 1.0f;
            const float arrowTopLength = 0.1f;

            Gl.Begin(PrimitiveType.Lines);
            if (x)
            {
                Gl.Color3(1.0f, 0.0f, 0.0f);
                Gl.Vertex3(-arrowLength, 0.0f, 0.0f);
                Gl.Vertex3(arrowLength, 0.0f, 0.0f);
                Gl.Vertex3(arrowLength - arrowTopLength, arrowTopLength, 0.0f);
                Gl.Vertex3(arrowLength, 0.0f, 0.0f);
                Gl.Vertex3(arrowLength - arrowTopLength, -arrowTopLength, 0.0f);
                Gl.Vertex3(arrowLength, 0.0f, 0.0f);
            }
            if (y)
            {
                Gl.Color3(0.0f, 1.0f, 0.0f);
                Gl.Vertex3(0.0f, -arrowLength, 0.0f);
                Gl.Vertex3(0.0f, arrowLength, 0.0f);
                Gl.Vertex3(arrowTopLength, arrowLength - arrowTopLength, 0.0f);
                Gl.Vertex3(0.0f, arrowLength, 0.0f);
                Gl.Vertex3(-arrowTopLength, arrowLength - arrowTopLength, 0.0f);
                Gl.Vertex3(0.0f, arrowLength, 0.0f);
            }
            if (z)
            {
                Gl.Color3(1.0f, 0.0f, 1.0f);
                Gl.Vertex3(0.0f, 0.0f, -arrowLength);
                Gl.Vertex3(0.0f, 0.0f, arrowLength);
                Gl.Vertex3(0.0f, arrowTopLength, arrowLength - arrowTopLength);
                Gl.Vertex3(0.0f, 0.0f, arrowLength);
                Gl.Vertex3(0.0f, -arrowTopLength, arrowLength - arrowTopLength);
                Gl.Vertex3(0.0f, 0.0f, arrowLength);
            }
            Gl.End();
        }
Пример #27
0
        /// <summary>
        /// Delegate used for executing animation drawing.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> used for drawing.
        /// </param>
        /// <param name="animationTime">
        /// A <see cref="TimeSpan"/> that specifies the animation time.
        /// </param>
        /// <param name="data">
        /// A <see cref="Object"/> used to pass information to animation drawing delegate.
        /// </param>
        protected void AnimationDraw(GraphicsContext ctx, TimeSpan animationTime, object data)
        {
            const float DEG_PER_SEC = 45.0f;

            // Clear surface
            Surface.Clear(_Context);

            // Set modelview matrix
            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            // Animation: rotate triangle
            Gl.Rotate(Angle.Normalize360(animationTime.TotalSeconds * DEG_PER_SEC), 0.0f, 0.0f, 1.0f);

            // Red triangle
            Gl.Color3(1.0f, 0.0f, 0.0f);

            Gl.Begin(PrimitiveType.Triangles);
            Gl.Vertex2(-1.0f, -1.0f);
            Gl.Vertex2(0.0f, 1.0f);
            Gl.Vertex2(+1.0f, -1.0f);
            Gl.End();
        }
Пример #28
0
        private void renderGl()
        {
            ParticleEditModel md = MainModel.ins.particleEditModel;

            if (md == null || md.width == 0 || md.height == 0)
            {
                return;
            }

            float x = slbX + (boxWidth - md.width) / 2 + 0.5f;
            float y = slbY + (boxHeight - md.height) / 2 + 0.5f;

            var w = boxWidth;
            var h = boxHeight;

            //int vpx = 0;
            //int vpy = 0;
            //int vpw = w;
            //int vph = h;

            //Gl.Viewport(vpx, vpy, vpw, vph);
            //Gl.Clear(ClearBufferMask.ColorBufferBit);

            //Gl.MatrixMode(MatrixMode.Projection);
            //Gl.LoadIdentity();
            //Gl.Ortho(0.0, w, 0.0, h, 0.0, 1.0);

            //Gl.MatrixMode(MatrixMode.Modelview);
            //Gl.LoadIdentity();

            Gl.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            renderInitMatrix(w, h);

            //line 1
            float xl1 = x;
            float yl1 = y;

            Gl.LineWidth(1f);
            Gl.Begin(PrimitiveType.LineLoop);
            Gl.Color3(1.0f, 1.0f, 1.0f);
            Gl.Vertex2(xl1, yl1);
            Gl.Vertex2(xl1 + md.width, yl1);
            Gl.Vertex2(xl1 + md.width, yl1 + md.height);
            Gl.Vertex2(xl1, yl1 + md.height);
            Gl.End();

            //line 2
            float xl2 = x - 1;
            float yl2 = y - 1;

            Gl.Begin(PrimitiveType.LineLoop);
            Gl.Color3(0.0f, 0.0f, 0.0f);
            Gl.Vertex2(xl2, yl2);
            Gl.Vertex2(xl2 + md.width + 2, yl2);
            Gl.Vertex2(xl2 + md.width + 2, yl2 + md.height + 2);
            Gl.Vertex2(xl2, yl2 + md.height + 2);
            Gl.End();

            //mask
            if (md.isMaskBox)
            {
                Gl.Enable(EnableCap.ScissorTest);
                Gl.Scissor((int)x, (int)y, md.width, md.height);
            }

            //emitter
            for (int i = 0; i < lstEmitter.Count; ++i)
            {
                lstEmitter[i].setStartPos((int)x, (int)y);
                lstEmitter[i].render(mMVP, renderTime);
            }

            //mask
            if (md.isMaskBox)
            {
                Gl.Disable(EnableCap.ScissorTest);
            }
        }
Пример #29
0
        protected void DrawPbo()
        {
            if (!(OutputBuffer is OGLBuffer buffer))
            {
                return;
            }

            if (mPBOTexID == 0)
            {
                GL.GenTextures(1, out mPBOTexID);
                Gl.BindTexture(TextureTarget.Texture2D, mPBOTexID);
                // Change these to GL_LINEAR for super- or sub-sampling

                //public const int GL_LINEAR = 9729;
                Gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, 9728);
                Gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, 9728);

                // GL_CLAMP_TO_EDGE for linear filtering, not relevant for nearest.

                Gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, 33071);
                Gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, 33071);

                Gl.BindTexture(TextureTarget.Texture2D, 0);
            }

            Gl.BindTexture(TextureTarget.Texture2D, mPBOTexID);

            // send pbo to texture
            Gl.BindBuffer(BufferTarget.PixelUnpackBuffer, buffer.ResourceId);

            var elementSize = (uint)buffer.ElemSize;

            if ((elementSize % 8) == 0)
            {
                Gl.PixelStore(PixelStoreParameter.UnpackAlignment, 8);
            }
            else if ((elementSize % 4) == 0)
            {
                Gl.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
            }
            else if ((elementSize % 2) == 0)
            {
                Gl.PixelStore(PixelStoreParameter.UnpackAlignment, 2);
            }
            else
            {
                Gl.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
            }

            switch (buffer.Format)
            {
            case Format.UByte4:
                Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Width, Height, 0, PixelFormat.Bgra, PixelType.Byte, IntPtr.Zero);
                break;

            case Format.Float4:
                Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba32f, Width, Height, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero);
                break;

            case Format.Float3:
                Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb32f, Width, Height, 0, PixelFormat.Rgb, PixelType.Float, IntPtr.Zero);
                break;

            case Format.Float:
                Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Luminance, Width, Height, 0, PixelFormat.Luminance, PixelType.Float, IntPtr.Zero);
                break;

            default:
                throw new Exception("Unsupported format for PBO");
            }


            Gl.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);

            Gl.Enable(EnableCap.Texture2D);

            // Initialize offsets to pixel center sampling.

            float u = 0.5f / Width;
            float v = 0.5f / Height;

            Gl.Begin(PrimitiveType.Quads);
            Gl.TexCoord2(u, v);
            Gl.Vertex2(0.0f, 0.0f);
            Gl.TexCoord2(1.0f, v);
            Gl.Vertex2(1.0f, 0.0f);
            Gl.TexCoord2(1.0f - u, 1.0f - v);
            Gl.Vertex2(1.0f, 1.0f);
            Gl.TexCoord2(u, 1.0f - v);
            Gl.Vertex2(0.0f, 1.0f);
            Gl.End();

            Gl.Disable(EnableCap.Texture2D);
        }
Пример #30
0
        public void DrawImage(GlImage image, float x, float y, float w, float h, float ix, float iy, float iw, float ih)
        {
            if (ix < 0)
            {
                x += -w * ix / iw;
                ix = 0;
            }

            if (ix + iw > image.Width)
            {
                w -= (ix + iw - image.Width) * w / iw;
                iw = image.Width - ix;
            }

            if (iy < 0)
            {
                y += -h * iy / ih;
                iy = 0;
            }

            if (iy + ih > image.Height)
            {
                h -= (iy + ih - image.Height) * h / ih;
                ih = image.Height - iy;
            }

            Gl.UseProgram(image.ShaderProgram);

            Gl.ActiveTexture(Gl.GL_TEXTURE0);
            Gl.BindTexture(Gl.GL_TEXTURE_2D, image.Id);
            Gl.Uniform1(Gl.GetUniformLocation(image.ShaderProgram, "tex"), 0);

            var vert  = (uint)Gl.GetAttribLocation(image.ShaderProgram, "vert");
            var tvert = (uint)Gl.GetAttribLocation(image.ShaderProgram, "vertTexCoord");

            var projectionMatrix = new float[16];

            Gl.GetFloat(Gl.GL_PROJECTION_MATRIX, projectionMatrix);
            Gl.UniformMatrix4(Gl.GetUniformLocation(image.ShaderProgram, "projectionMatrix"), 1, false,
                              projectionMatrix);

            Gl.PolygonMode(Gl.GL_FRONT, Gl.GL_FILL);
            Gl.Color(Color.Transparent);
            Gl.Enable(Gl.GL_TEXTURE_2D);

            Gl.Begin(Gl.GL_QUADS);

            Gl.VertexAttrib2(vert, x, y);
            Gl.VertexAttrib2(tvert, ix / image.Width, iy / image.Height);

            Gl.VertexAttrib2(vert, x, y + h);
            Gl.VertexAttrib2(tvert, ix / image.Width, (iy + ih) / image.Height);

            Gl.VertexAttrib2(vert, x + w, y + h);
            Gl.VertexAttrib2(tvert, (ix + iw) / image.Width, (iy + ih) / image.Height);

            Gl.VertexAttrib2(vert, x + w, y);
            Gl.VertexAttrib2(tvert, (ix + iw) / image.Width, iy / image.Height);

            Gl.End();

            Gl.Disable(Gl.GL_TEXTURE_2D);
            Gl.BindTexture(Gl.GL_TEXTURE_2D, 0);

            Gl.UseProgram(0);

            Gl.Flush();
        }