コード例 #1
0
        public void Draw(OpenTKWrapper.CLGLInterop.GLAdvancedRender glw)
        {
            if (Visible)
            {
                GL.Disable(EnableCap.Lighting);
                GL.Color4(0.5f, 0.5f, 0.5f, 0.5f);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.Begin(BeginMode.Quads);
                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.End();

                GL.LineWidth(2.0f);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

                GL.Color3(0.82f, 0.0f, 0f);
                GL.Begin(BeginMode.Quads);

                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.minPoint.z);

                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);

                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.minPoint.z);

                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.minPoint.z);

                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.minPoint.z);

                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.minPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.minPoint.z);

                GL.End();

                GL.PushMatrix();
                GL.MultMatrix(ref GroundPlane);
                GL.Translate(0, 0, -bbox.maxPoint.z);
                GL.Color4(0.0f, 0.0f, 0.82f, 0.5f);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.Begin(BeginMode.Quads);
                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);

                GL.End();

                GL.LineWidth(2.0f);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

                GL.Color3(0.0f, 0.0f, 0.82f);
                GL.Begin(BeginMode.Quads);

                GL.Vertex3(bbox.minPoint.x, bbox.minPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.maxPoint.x, bbox.minPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.maxPoint.x, bbox.maxPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);
                GL.Vertex3(bbox.minPoint.x, bbox.maxPoint.y, bbox.maxPoint.z - GROUND_THICKNESS * 0.5f);

                GL.End();

                GL.PopMatrix();

                GL.Enable(EnableCap.Lighting);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.Color3(0.5f, 0.5f, 0.8f);
                sphere.Draw();

                GL.Color3(1.0f, 1.0f, 1.0f);

            }
        }
コード例 #2
0
        public void Initialize(BaseCameraApplication app, OpenTKWrapper.CLGLInterop.GLAdvancedRender glw)
        {
            try
            {
                CLCalc.Program.Compile(app.GetPrimaryDevice().GetPreprocessCode() + src);
            }
            catch (BuildProgramFailureComputeException ex)
            {
                System.Console.WriteLine(ex.Message);
                Environment.Exit(1);
            }
            kernelCopyImage = new CLCalc.Program.Kernel("CopyImageToMesh");
            BoundingBox bbox = app.GetPrimaryDevice().GetBoundingBox();
            int w = app.GetPrimaryDevice().GetDepthImage().Width;
            int h = app.GetPrimaryDevice().GetDepthImage().Height;
            int size = w * h;
            ColorData = new float[16 * size];
            PositionData = new float[16 * size];
            NormalData = new float[12 * size];
            for (int i = 0; i < size; i++)
            {
                PositionData[4 * i] = (i / w) - w / 2;
                PositionData[4 * i + 2] = i % w - h / 2;
                PositionData[4 * i + 1] = i % 7;
                PositionData[4 * i + 3] = 1.0f;

            }

            GL.GenBuffers(3, QuadMeshBufs);

            GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(ColorData.Length * sizeof(float)), ColorData, BufferUsageHint.StreamDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[1]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(PositionData.Length * sizeof(float)), PositionData, BufferUsageHint.StreamDraw);//Notice STREAM DRAW

            GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(NormalData.Length * sizeof(float)), NormalData, BufferUsageHint.StreamDraw);//Notice STREAM DRAW

            colorBuffer = new CLCalc.Program.Variable(QuadMeshBufs[0], typeof(float));
            positionBuffer = new CLCalc.Program.Variable(QuadMeshBufs[1], typeof(float));
            normalBuffer = new CLCalc.Program.Variable(QuadMeshBufs[2], typeof(float));

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.Enable(EnableCap.Blend);
        }
コード例 #3
0
 public void Initialize(BaseCameraApplication app, OpenTKWrapper.CLGLInterop.GLAdvancedRender glw)
 {
 }
コード例 #4
0
        public void Draw(OpenTKWrapper.CLGLInterop.GLAdvancedRender glw)
        {
            GL.Enable(EnableCap.Lighting);
            if (Visible)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.EnableClientState(ArrayCap.VertexArray);
                if (ShowColor)
                {

                    GL.Disable(EnableCap.Lighting);
                    GL.EnableClientState(ArrayCap.ColorArray);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[0]);
                    GL.ColorPointer(4, ColorPointerType.Float, 0, 0);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[1]);
                    GL.VertexPointer(4, VertexPointerType.Float, 0, 0);
                    GL.DrawArrays(BeginMode.Quads, 0, PositionData.Length / 4);
                    GL.DisableClientState(ArrayCap.ColorArray);
                }
                else
                {

                    GL.Enable(EnableCap.Lighting);
                    GL.EnableClientState(ArrayCap.NormalArray);
                    GL.Color3(0.8f, 0.4f, 0.2f);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[2]);
                    GL.NormalPointer(NormalPointerType.Float, 0, 0);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[1]);
                    GL.VertexPointer(4, VertexPointerType.Float, 0, 0);
                    GL.DrawArrays(BeginMode.Quads, 0, PositionData.Length / 4);
                    GL.Color3(1.0f, 1.0f, 1.0f);

                    GL.DisableClientState(ArrayCap.NormalArray);
                }
                GL.DisableClientState(ArrayCap.VertexArray);
            }
            if (WireFrame)
            {
                GL.LineWidth(2.0f);
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                GL.EnableClientState(ArrayCap.VertexArray);

                GL.EnableClientState(ArrayCap.NormalArray);
                if (ShowColor)
                {
                    GL.Color3(0.1f, 0.1f, 0.2f);
                }
                else
                {
                    GL.Color3(0.4f, 0.2f, 0.1f);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[2]);
                GL.NormalPointer(NormalPointerType.Float, 0, 0);
                GL.BindBuffer(BufferTarget.ArrayBuffer, QuadMeshBufs[1]);
                GL.VertexPointer(4, VertexPointerType.Float, 0, 0);
                GL.DrawArrays(BeginMode.Quads, 0, PositionData.Length / 4);
                GL.Color3(1.0f, 1.0f, 1.0f);

                GL.DisableClientState(ArrayCap.NormalArray);
            }
            GL.DisableClientState(ArrayCap.VertexArray);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }