Пример #1
1
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="r">The r.</param>
        /// <param name="g">The g.</param>
        /// <param name="b">The b.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
        {
            //  Get the font size in pixels.
            var fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = (from fbe in fontBitmapEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0
                         && fbe.Height == fontHeight
                         select fbe).ToList();

            //  Get the FBE or null.
            var fontBitmapEntry = result.FirstOrDefault();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
                fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);

            double width = gl.RenderContextProvider.Width;
            double height = gl.RenderContextProvider.Height;
            
            //  Create the appropriate projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            gl.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Color(r, g, b);
            gl.RasterPos(x, y);

            gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
                OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
            gl.Color(r, g, b);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.RasterPos(x, y);

            //  Set the list base.
            gl.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            var lists = text.Select(c => (byte) c).ToArray();

            //  Call the lists for the string.
            gl.CallLists(lists.Length, lists);
            gl.Flush();
            
            //  Reset the list bit.
            gl.PopAttrib();

            //  Pop the modelview.
            gl.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
Пример #2
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();

            gl.LookAt(0, 20, 30, 0, 0, 0, 0, 1, 0);

            //desenha o piso
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            grass.Bind(gl);
            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(0.0f, 1.0f, 0.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-100.0f, 0.0f, -100.0f);
            gl.TexCoord(100.0f, 0.0f); gl.Vertex(100.0f, 0.0f, -100.0f);
            gl.TexCoord(100.0f, 100.0f); gl.Vertex(100.0f, 0.0f, 100.0f);
            gl.TexCoord(0.0f, 100.0f); gl.Vertex(-100.0f, 0.0f, 100.0f);
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);

            foreach (Polygon polygon in polygons)
            {
                polygon.PushObjectSpace(gl);
                polygon.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
                polygon.PopObjectSpace(gl);
            }

            gl.Flush();
        }
Пример #3
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.LoadIdentity();

            gl.Translate(-1.5f, 0f, -6f);

            gl.Begin(OpenGL.GL_TRIANGLES);
            {
                gl.Vertex(0.0f, 1.0f, 0.0f);
                gl.Vertex(-1.0f, -1.0f, 0.0f);
                gl.Vertex(1.0f, -1.0f, 0.0f);
            }
            gl.End();

            gl.Translate(3f, 0f, 0f);

            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.Vertex(-1.0f, 1.0f, 0.0f);
                gl.Vertex(1.0f, 1.0f, 0.0f);
                gl.Vertex(1.0f, -1.0f, 0.0f);
                gl.Vertex(-1.0f, -1.0f, 0.0f);
            }
            gl.End();
            gl.Flush();
        }
Пример #4
0
        //在鼠标按下的时候触发的事件
        public void DrawStart()
        {
            fPoint currentPoint = new fPoint(fx, fy);

            switch (selectedTool)
            {
            case Tools.pointer:
                break;

            //橡皮擦为白色的50宽度的铅笔
            case Tools.pen:
            case Tools.eraser:
                pointQueue.Enqueue(currentPoint);
                gl.Begin(OpenGL.GL_POINTS);
                {
                    gl.Vertex(fx, fy, 0f);
                }
                gl.End();
                gl.Flush();
                break;

            case Tools.line:
                pointQueue.Enqueue(currentPoint);
                //gl.genbuffers(1, buffers);
                //gl.bindbuffer(buffers[0], opengl.gl_color_buffer_bit);
                break;

            case Tools.circle:
            case Tools.rec:
                pointQueue.Enqueue(currentPoint);
                break;

            case Tools.poly:
                if (pointQueue.Count != 0)
                {
                    gl.Begin(OpenGL.GL_LINES);
                    {
                        gl.Vertex(currentPoint.fx, currentPoint.fy, 0f);
                        gl.Vertex(pointQueue.Peek().fx, pointQueue.Peek().fy);
                    }
                    gl.End();
                    pointQueue.Clear();
                }
                break;
            }
            isDrawing = true;
        }
Пример #5
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();


            gl.PushMatrix();

            gl.Translate(0.0f, 0.0f, -6.0f);
            gl.Rotate(angle, 1.0f, 1.0f, 1.0f);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);

            gl.Begin(OpenGL.GL_QUADS);
            gl.Normal(0.0f, 0.0f, -1.0f);
            // Front Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Left Of The Texture and Quad

            // Back Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Left Of The Texture and Quad

            // Top Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);

            // Bottom Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);

            // Right face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, 1.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, -1.0f);

            // Left Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);
            gl.End();
            gl.PopMatrix();

            gl.Flush();

            angle += rotSpeed;
        }
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -6.0f);

            gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);

            //  Bind the texture.
            texture.Bind(gl);

            gl.Begin(OpenGL.GL_QUADS);

            // Front Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Left Of The Texture and Quad

            // Back Face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Left Of The Texture and Quad

            // Top Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad

            // Bottom Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad

            // Right face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad

            // Left Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.End();

            gl.Flush();

            rtri += 1.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle
        }
Пример #7
0
        //jumpFrame: 一次跳躍資料數
        public static void drawGL_FrameData_Triangle(SharpGL.OpenGL gl_object, FrameData_LJV7 frame, int jumpFrame)
        {
            gl_object.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);

            //可以不用每次都旋轉,可以滑鼠動作時變更即可
            //不影響效能
            gl_object.LoadIdentity();
            gl_object.Translate(_LX, _LY, _LZ);
            gl_object.Rotate(_RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(_RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(_RoZ, 0.0, 0.0, 1.0);

            double x = 0, y = 0;
            double centerx = frame.size_per_frame / 2;
            double centery = frame.LJVcount / 2;
            double diff = frame.Max_Buffer_Compute - frame.Min_Buffer_Compute;
            double r = 0, g = 0, b = 0;
            double Color_H = 0.0;

            for (int j = 0; j < frame.LJVcount - jumpFrame; j += jumpFrame)
            {
                gl_object.Begin(OpenGL.TRIANGLE_STRIP);
                for (int i = 0; i < frame.size_per_frame - jumpFrame; i += jumpFrame)
                {
                    int pos = Convert.ToInt32(i * frame.LJVcount + j);
                    if (frame.buffer_compute[pos] == -999 || frame.buffer_compute[pos + jumpFrame] == -999)
                    {
                        gl_object.End();
                        gl_object.Begin(OpenGL.TRIANGLE_STRIP);
                        continue;
                    }
                    Color_H = (frame.buffer_compute[pos] - frame.Min_Buffer_Compute) / diff;
                    Color_H = Color_H * (MaxColorH - MinColorH) + MinColorH;
                    HsvToRgb(Color_H, 1.0, 1.0, out r, out g, out b);
                    gl_object.Color(r, g, b);

                    x = (Convert.ToDouble(i) - centerx) / Convert.ToDouble(100);
                    y = -(Convert.ToDouble(j) - centery) / Convert.ToDouble(100);
                    gl_object.Vertex(x, y, frame.buffer_compute[pos]);


                    Color_H = (frame.buffer_compute[pos + jumpFrame] - frame.Min_Buffer_Compute) / diff;
                    Color_H = Color_H * (MaxColorH - MinColorH) + MinColorH;
                    HsvToRgb(Color_H, 1.0, 1.0, out r, out g, out b);
                    gl_object.Color(r, g, b);

                    x = (Convert.ToDouble(i) - centerx) / Convert.ToDouble(100);
                    y = -(Convert.ToDouble(j + jumpFrame) - centery) / Convert.ToDouble(100);
                    gl_object.Vertex(x, y, frame.buffer_compute[pos + jumpFrame]);
                }
                gl_object.End();
            }

            //drawAxis(gl_object);
            gl_object.Flush();
            return;
        }
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Translate(0.0f, 0.0f, -6.0f);

            //绘制正方体,Rotate The Quad On The X, Y, And Z Axes
            gl.Rotate(x, -1.0f, 0.0f, 0.0f);
            gl.Rotate(y, 0.0f, 0.0f, 1.0f);
            gl.Rotate(z, 0.0f, 1.0f, 0.0f);

            gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);

            gl.Begin(OpenGL.GL_QUADS);

            // Front Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Left Of The Texture and Quad

            // Back Face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Left Of The Texture and Quad

            // Top Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad

            // Bottom Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad

            // Right face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad

            // Left Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.End();

            gl.Flush();
        }
Пример #9
0
        public static void Draw3DInformation(SharpGL.OpenGL gl_object, float[] X, float[] Y, float[] Z, DetectedRectRegion DetectField)
        {
            double MaxDistance = 0;
            double r = 0, g = 0, b = 0;

            gl_object.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl_object.LoadIdentity();
            gl_object.Translate(_LX, _LY, _LZ);
            gl_object.Rotate(_RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(_RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(_RoZ, 0.0, 0.0, 1.0);

            //畫光達自己的位置
            gl_object.Begin(OpenGL.GL_TRIANGLES);
            gl_object.Color(1.0, 1.0, 1.0);
            gl_object.Vertex(-0.2, -0.15, 0);
            gl_object.Vertex(0, 0.2, 0);
            gl_object.Vertex(0.2, -0.15, 0);
            gl_object.End();

            drawAxis(gl_object);

            //畫D場景
            gl_object.Begin(OpenGL.GL_POINTS);
            for (int i = 0; i < 23040; i++)
            {
                if (DetectField.DetectRegionX1 < X[i] && X[i] < DetectField.DetectRegionX2 && DetectField.DetectRegionY1 < Y[i] && Y[i] < DetectField.DetectRegionY2 && DetectField.DetectRegionZ1 < Z[i] && Z[i] < DetectField.DetectRegionZ2)
                {
                    continue;
                }
                if (X[i] != 0 && Y[i] != 0 && Z[i] != 0)
                {
                    //用XY距離計算顯示顏色
                    double XYDistance = Math.Sqrt(X[i] * X[i] + Y[i] * Y[i]);
                    if (XYDistance > MaxDistance)
                    {
                        MaxDistance = XYDistance;
                    }
                    if (XYDistance > 10)
                    {
                        XYDistance = 10;
                    }
                    XYDistance = XYDistance / 10 * (360 - 30) + 30;
                    HsvToRgb(XYDistance, 1, 1, out r, out g, out b);
                    gl_object.Color(r, g, b);
                    //畫上點座標
                    gl_object.Vertex(X[i], Y[i], Z[i]);
                }
            }
            gl_object.End();
            gl_object.Flush();
        }
Пример #10
0
        public static void drawGL_FrameData_Triangle(SharpGL.OpenGL gl_object, ModelBuilder builder, int jumpFrame)
        {
            if (builder._ShowPoints == null || builder._ShowPoints.Length <= 0)
            {
                return;
            }

            gl_object.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT);

            //可以不用每次都旋轉,可以滑鼠動作時變更即可
            //不影響效能
            gl_object.LoadIdentity();
            gl_object.Translate(GLDrawObject._LX, GLDrawObject._LY, GLDrawObject._LZ);
            gl_object.Rotate(GLDrawObject._RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(GLDrawObject._RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(GLDrawObject._RoZ, 0.0, 0.0, 1.0);

            for (int j = 0; j < builder._LJV7Frame.LJVcount - jumpFrame; j += jumpFrame)
            {
                gl_object.Begin(OpenGL.TRIANGLE_STRIP);
                for (int i = 0; i < builder._LJV7Frame.size_per_frame - jumpFrame; i += jumpFrame)
                {
                    int pos = Convert.ToInt32(i * builder._LJV7Frame.LJVcount + j);
                    if (builder._ShowPoints[pos].Z == -999 || builder._ShowPoints[pos + jumpFrame].Z == -999)
                    {
                        gl_object.End();
                        gl_object.Begin(OpenGL.TRIANGLE_STRIP);
                        continue;
                    }

                    DPoint point = builder._ShowPoints[pos];
                    gl_object.Color(point.r, point.g, point.b);
                    gl_object.Vertex(point.X, point.Y, point.Z);

                    point = builder._ShowPoints[pos + jumpFrame];
                    gl_object.Color(point.r, point.g, point.b);
                    gl_object.Vertex(point.X, point.Y, point.Z);

                    //Console.WriteLine("X:" + point.r);
                    //Console.WriteLine("Y:" + point.g);
                    //Console.WriteLine("Z:" + point.b);
                }
                gl_object.End();
            }

            GLDrawObject.drawAxis(gl_object);
            gl_object.Flush();
            return;
        }
Пример #11
0
        public override void Draw(SharpGL.OpenGL gl)
        {
            //Process alignment in baseclass
            base.Draw(gl);

            //Draw the square on screen
            gl.Begin(OpenGL.GL_QUADS);
            gl.Color(Color.R, Color.G, Color.B);
            gl.Vertex(-15f, -15f);
            gl.Vertex(-15f, 15f);
            gl.Vertex(15f, 15f);
            gl.Vertex(15f, -15f);
            gl.End();
            gl.Flush();
        }
Пример #12
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
            gl.Enable(OpenGL.GL_TEXTURE_2D);


            if (playerLives != 0)
            {
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.LoadIdentity();
                gl.Translate(0.0f, 0.0f, -20.0f);
                main.Create(gl, "..\\..\\main.png");

                gl.PushMatrix();
                gl.Begin(OpenGL.GL_QUADS);
                gl.TexCoord(1, 1); gl.Vertex(-1, -1);
                gl.TexCoord(0, 1); gl.Vertex(1, -1);
                gl.TexCoord(0, 0); gl.Vertex(1, 1);
                gl.TexCoord(1, 0); gl.Vertex(-1, 1);

                gl.End();
                gl.PopMatrix();
                currentFrame = currentFrame + 1;
                if (currentFrame % 28 == 0)
                {
                    createEnemy();
                    currentFrame = 0;
                }
                moveEnemy();

                if (enemyList != null)
                {
                    for (int i = 0; i < enemyList.Count; i++)
                    {
                        enemyList[i].drawEnemy(gl);
                    }
                }
                gl.Flush();
            }
            else
            {
                label2.Text = "Game over";
            }
        }
Пример #13
0
        private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs e)
        {
            SharpGL.OpenGL gl = e.OpenGL;

            gl.MatrixMode(SharpGL.OpenGL.GL_PROJECTION);

            gl.LoadIdentity();

            const float left   = -5;
            const float right  = 5;
            const float bottom = -5;
            const float top    = 5;

            gl.Ortho2D(left, right, bottom, top);

            gl.Color(1, 1, 1);

            gl.Begin(SharpGL.OpenGL.GL_LINES);

            gl.Vertex(0, bottom);
            gl.Vertex(0, top);
            gl.Vertex(left, 0);
            gl.Vertex(right, 0);

            gl.End();

            gl.Color(0.0f, 0.0f, 1.0f);
            gl.Begin(SharpGL.OpenGL.GL_LINE_STRIP);

            for (var x = -4.0; x < 4; x += 0.1)
            {
                gl.Vertex(x, Math.Sin(x));
            }

            gl.Viewport(20, 20, 200, 200);

            gl.End();
            gl.Flush();
        }
Пример #14
0
 private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)//绘图循环
 {
     SharpGL.OpenGL gl = this.openGLControl.OpenGL;
     //清除深度缓存
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
     //坐标变换
     gl.LoadIdentity();
     gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
     if (recoverCenter)
     {
         gl.LoadIdentity();
     }
     gl.Scale(scale, scale, scale);
     //绘图
     DrawPoint(gl);
     if (isDraw)
     {
         DrawCurve(gl);
     }
     if (checkBoxGridShow.Checked == true)
     {
         DrawCtrlGrid(gl);
     }
     DrawXoZGrids(gl);
     DrawOneCoodinate(gl, 0, 0, 0, false);
     if (pointModify == true && switchToPointSelectBtn.Value == true)
     {
         DrawCoodinate(gl, selectedPt);
     }
     DrawSurface(gl);
     //更新显示的控制点与座标架
     if (viewChanged)
     {
         UpdateViewforSelct(gl);
         viewChanged = false;
     }
     gl.Flush();   //强制刷新
 }
Пример #15
0
        public static void DrawObstacleInformation(SharpGL.OpenGL gl_object, ObstacleData ObData, double ColorR, double ColorG, double ColorB)
        {
            //gl_object.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl_object.LoadIdentity();
            gl_object.Translate(_LX, _LY, _LZ);
            gl_object.Rotate(_RoX, 0.0, 1.0, 0.0);
            gl_object.Rotate(_RoY, 1.0, 0.0, 0.0);
            gl_object.Rotate(_RoZ, 0.0, 0.0, 1.0);

            //畫D場景
            gl_object.Begin(OpenGL.GL_POINTS);
            gl_object.Color(ColorR, ColorG, ColorB);
            for (int i = 0; i < ObData.ObstaclePosX.Count; i++)
            {
                if (ObData.ObstaclePosX[i] != 0 && ObData.ObstaclePosY[i] != 0 && ObData.ObstaclePosZ[i] != 0)
                {
                    //畫上點座標
                    gl_object.Vertex(ObData.ObstaclePosX[i], ObData.ObstaclePosY[i], ObData.ObstaclePosZ[i]);
                }
            }
            gl_object.End();
            gl_object.Flush();
        }
Пример #16
0
        private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            gl = this.openGLControl1.OpenGL;
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

            gl.LoadIdentity();                                                 // Reset The View
            //gl.Translate(-1.5f, 0.0f, -6.0f);				// Move Left And Into The Screen
            gl.Translate(_ZBx, _ZBy, _ZBz);                                    // 设置坐标,距离屏幕距离为6
                                                                               // gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);              // Rotate The Pyramid On It's Y Axis
            gl.Rotate(_x, 1.0f, 0.0f, 0.0f);                                   // 绕X轴旋转
            gl.Rotate(_y, 0.0f, 1.0f, 0.0f);                                   // 绕Y轴旋转
            gl.Rotate(_z, 0.0f, 0.0f, 1.0f);
            #region 原始代码
            //gl.Begin(OpenGL.TRIANGLES);					// Start Drawing The Pyramid

            //gl.Color(1.0f, 0.0f, 0.0f);			// Red
            //gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
            //gl.Color(0.0f, 1.0f, 0.0f);			// Green
            //gl.Vertex(-1.0f, -1.0f, 1.0f);			// Left Of Triangle (Front)
            //gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            //gl.Vertex(1.0f, -1.0f, 1.0f);			// Right Of Triangle (Front)

            //gl.Color(1.0f, 0.0f, 0.0f);			// Red
            //gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
            //gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            //gl.Vertex(1.0f, -1.0f, 1.0f);			// Left Of Triangle (Right)
            //gl.Color(0.0f, 1.0f, 0.0f);			// Green
            //gl.Vertex(1.0f, -1.0f, -1.0f);			// Right Of Triangle (Right)

            //gl.Color(1.0f, 0.0f, 0.0f);			// Red
            //gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
            //gl.Color(0.0f, 1.0f, 0.0f);			// Green
            //gl.Vertex(1.0f, -1.0f, -1.0f);			// Left Of Triangle (Back)
            //gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            //gl.Vertex(-1.0f, -1.0f, -1.0f);			// Right Of Triangle (Back)

            //gl.Color(1.0f, 0.0f, 0.0f);			// Red
            //gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
            //gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            //gl.Vertex(-1.0f, -1.0f, -1.0f);			// Left Of Triangle (Left)
            //gl.Color(0.0f, 1.0f, 0.0f);			// Green
            //gl.Vertex(-1.0f, -1.0f, 1.0f);			// Right Of Triangle (Left)
            //gl.End();						// Done Drawing The Pyramid

            //gl.LoadIdentity();
            //gl.Translate(1.5f, 0.0f, -7.0f);				// Move Right And Into The Screen

            //gl.Rotate(rquad, 1.0f, 1.0f, 1.0f);			// Rotate The Cube On X, Y & Z

            //gl.Begin(OpenGL.QUADS);					// Start Drawing The Cube

            //gl.Color(0.0f, 1.0f, 0.0f);			// Set The Color To Green
            //gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Top)
            //gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Top)
            //gl.Vertex(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
            //gl.Vertex(1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)


            //gl.Color(1.0f, 0.5f, 0.0f);			// Set The Color To Orange
            //gl.Vertex(1.0f, -1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
            //gl.Vertex(-1.0f, -1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
            //gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Bottom)
            //gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Bottom)

            //gl.Color(1.0f, 0.0f, 0.0f);			// Set The Color To Red
            //gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
            //gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
            //gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
            //gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Front)

            //gl.Color(1.0f, 1.0f, 0.0f);			// Set The Color To Yellow
            //gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Back)
            //gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Back)
            //gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Back)
            //gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Back)

            //gl.Color(0.0f, 0.0f, 1.0f);			// Set The Color To Blue
            //gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
            //gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Left)
            //gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Left)
            //gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Left)

            //gl.Color(1.0f, 0.0f, 1.0f);			// Set The Color To Violet
            //gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Right)
            //gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
            //gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
            //gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Right)
            //gl.End();                       // Done Drawing The Q



            //rtri += 1.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle
            //rquad -= 0.75f;//
            #endregion
            gl.Begin(OpenGL.GL_POINTS);
            // gl.Color(5.0f, 39.0f, 175.0f);
            if (!Drawxs)// 设置颜色
            {
                for (int i = 0; i < sum; i++)
                {
                    gl.Vertex((pointX[i] - _ZBxT) / _ZBv, (pointY[i] - _ZByT) / _ZBv, (pointZ[i] - _ZBzT) / _ZBv);
                    //gl.Vertex((pointZ[i] - _ZBzT) / _ZBv, (pointX[i] - _ZBxT) / _ZBv, (pointY[i] - _ZByT) / _ZBv);
                }
                if (Zcdk)
                {
                    for (int i = 0; i < xds; i++)
                    {
                        Z_color = Math.Abs(maxz[i] / 1000);
                        if (Z_color >= 0 && Z_color < 0.25)
                        {
                            gl.Color(1.0f, 0.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }

                        else if (Z_color >= 0.25 && Z_color < 0.5)
                        {
                            gl.Color(1.0f, 0.25f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 0.5 && Z_color < 0.75)
                        {
                            gl.Color(1.0f, 0.5f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 0.75 && Z_color < 1.0)
                        {
                            gl.Color(1.0f, 0.75f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 1.0 && Z_color < 1.25)
                        {
                            gl.Color(1.0F, 1.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 1.25 && Z_color < 1.5)
                        {
                            gl.Color(0.75f, 1.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 1.5 && Z_color < 1.75)
                        {
                            gl.Color(0.5f, 1.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 1.75 && Z_color < 2.0)
                        {
                            gl.Color(0.25f, 1.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 2.0 && Z_color < 2.25)
                        {
                            gl.Color(0.0f, 1.0f, 0.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 2.25 && Z_color < 2.5)
                        {
                            gl.Color(0.0f, 1.0f, 0.25f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 2.5 && Z_color < 2.75)
                        {
                            gl.Color(0.0f, 1.0f, 0.4f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 2.75 && Z_color < 3.0)//////////////////
                        {
                            gl.Color(0.0f, 1.0f, 0.55f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 3.0 && Z_color < 3.25)
                        {
                            gl.Color(0.0f, 1.0f, 0.7f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }
                        else if (Z_color >= 3.25 && Z_color < 3.5)
                        {
                            gl.Color(0.0f, 1.0f, 0.85f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }

                        else

                        {
                            gl.Color(0.0f, 1.0f, 1.0f);
                            gl.Vertex((maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
                        }


                        //gl.Vertex((maxz[i] - _ZBzT + 0.01) / _ZBv, (maxx[i] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv);
                    }
                }
            }
            //else
            //{
            //    for (int i = 0; i < cut; i++)
            //    {
            //        gl.Vertex((temx[bcsz[i]] - _ZBxT) / _ZBv, (miny[i] - _ZByT) / _ZBv, (minz[i] - _ZBzT) / _ZBv);
            //        gl.Vertex((temx[bcsz[i]] - _ZBxT) / _ZBv, (miny[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
            //        gl.Vertex((temx[bcsz[i]] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (minz[i] - _ZBzT) / _ZBv);
            //        gl.Vertex((temx[bcsz[i]] - _ZBxT) / _ZBv, (maxy[i] - _ZByT) / _ZBv, (maxz[i] - _ZBzT) / _ZBv);
            //    }
            //}
            gl.End();
            gl.Flush();
            GC.Collect();
        }
Пример #17
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            //清除深度缓存
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            //重置当前指定的矩阵为单位矩阵,将当前的用户坐标系的原点移到了屏幕中心
            gl.LoadIdentity();

            //显示视频画面
            Monitor.Enter(MainForm._MyLock);
            try
            {
                if (this.buffer != IntPtr.Zero)
                {
                    var xz  = (float)this.openGLControl1.Width / (float)this.videoWidth;
                    var yz  = (float)this.openGLControl1.Height / (float)this.videoHeight;
                    var xyz = 1f;
                    xyz = Math.Min(xz, yz);
                    if (xz < yz)
                    {
                        gl.RasterPos(-1f, (xyz / yz));
                    }
                    else
                    {
                        gl.RasterPos((xyz / xz), -1f);
                    }
                    gl.PixelZoom(xyz, -xyz);
                    gl.DrawPixels((int)this.videoWidth, (int)this.videoHeight, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, this.buffer);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Monitor.Exit(MainForm._MyLock);
            }

            lock (this.osdLock)
            {
                if (this.osdMessage != null)
                {
                    var textData = this.osdMessage.LockBits(new Rectangle(0, 0, this.osdMessage.Width, this.osdMessage.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);


                    //显示OSD
                    var x = (2f / this.openGLControl1.Width) * 50f - 1f;
                    var y = (2f / this.openGLControl1.Height) * (this.openGLControl1.Height - 50f) - 1f;
                    gl.RasterPos(x, y);
                    gl.PixelZoom(1, -1);
                    gl.DrawPixels(this.osdMessage.Width, this.osdMessage.Height, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, textData.Scan0);
                    this.osdMessage.UnlockBits(textData);


                    //gl.DrawText(50, this.openGLControl1.Height - 18, 1, 1, 0, "Microsoft YaHei UI", 24, this.osdMessage);
                }
            }

            gl.Flush();   //强制刷新
        }
Пример #18
0
        private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
        {
            SharpGL.OpenGL gl = this.openGLControl.OpenGL;
            setCamera(gl);

            //清除深度缓存
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //重置当前指定的矩阵为单位矩阵,将当前的用户坐标系的原点移到了屏幕中心
            gl.LoadIdentity();

            // 光照
            //  gl.Enable(OpenGL.GL_LIGHTING);


            //地形
            mydem.DrawLand(gl, texture[8]);



            //把当前坐标系右移3个单位,注意此时是相对上面(-1.5, 0, -6)点定位
            gl.Translate(0f, 0f, 0f);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[1].Bind(gl);

            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {    //地形
                 //gl.TexCoord(0, 0);
                 //gl.Vertex(-50.0f, 50.0f, 0.0f);
                 //gl.TexCoord(0, 1);
                 //gl.Vertex(-50.0f, -50.0f, 0.0f);
                 //gl.TexCoord(1, 1);
                 //gl.Vertex(50.0f, -50.0f, 0.0f);
                 //gl.TexCoord(1, 0);
                 //gl.Vertex(50.0f, 50.0f, 0.0f);
            }


            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);



            //水面

            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[3].Bind(gl);

            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(-50.0f, 50.0f, a);
                gl.TexCoord(0, 1);
                gl.Vertex(-50.0f, -50.0f, a);
                gl.TexCoord(1, 1);
                gl.Vertex(50.0f, -50.0f, a);
                gl.TexCoord(1, 0);
                gl.Vertex(50.0f, 50.0f, a);
            }

            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);



            //天空

            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[2].Bind(gl);

            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(-50.0f, 50.0f, 40.00f);
                gl.TexCoord(0, 1);
                gl.Vertex(-50.0f, -50.0f, 40f);
                gl.TexCoord(1, 1);
                gl.Vertex(50.0f, -50.0f, 40f);
                gl.TexCoord(1, 0);
                gl.Vertex(50.0f, 50.0f, 40f);
            }

            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            //01
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[4].Bind(gl);
            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(-50.0f, 50.0f, -1f);
                gl.TexCoord(0, 1);
                gl.Vertex(-50.0f, 50.0f, 40f);
                gl.TexCoord(1, 1);
                gl.Vertex(-50.0f, -50.0f, 40f);
                gl.TexCoord(1, 0);
                gl.Vertex(-50.0f, -50.0f, -1f);
            }
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);

            //02

            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[5].Bind(gl);
            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(50.0f, 50.0f, -1f);
                gl.TexCoord(0, 1);
                gl.Vertex(50.0f, 50.0f, 40f);
                gl.TexCoord(1, 1);
                gl.Vertex(50.0f, -50.0f, 40f);
                gl.TexCoord(1, 0);
                gl.Vertex(50.0f, -50.0f, -1f);
            }
            //03
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[6].Bind(gl);
            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(-50.0f, 50.0f, -1f);
                gl.TexCoord(0, 1);
                gl.Vertex(-50.0f, 50.0f, 40f);
                gl.TexCoord(1, 1);
                gl.Vertex(50.0f, 50.0f, 40f);
                gl.TexCoord(1, 0);
                gl.Vertex(50.0f, 50.0f, -1f);
            }
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);

            gl.Enable(OpenGL.GL_TEXTURE_2D);
            texture[7].Bind(gl);
            gl.Color(1f, 1f, 1f, 1f);
            gl.Begin(OpenGL.GL_QUADS);
            {
                gl.TexCoord(0, 0);
                gl.Vertex(-50.0f, -50.0f, -1f);
                gl.TexCoord(0, 1);
                gl.Vertex(-50.0f, -50.0f, 40f);
                gl.TexCoord(1, 1);
                gl.Vertex(50.0f, -50.0f, 40f);
                gl.TexCoord(1, 0);
                gl.Vertex(50.0f, -50.0f, -1f);
            }
            gl.End();
            gl.Disable(OpenGL.GL_TEXTURE_2D);



            //画树
            for (int i = 0; i < treePos.Count; i++)
            {
                Vector3d vPos = treePos[i];
                drawTree(gl, vPos.dx, vPos.dy, vPos.dz, i);
            }

            gl.Flush();   //强制刷新
        }
Пример #19
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, string faceName, float fontSize, 
            float deviation, float extrusion, string text)
        {
            //  Get the font size in pixels.
            int fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = from fbe in fontOutlineEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && string.Compare(fbe.FaceName, faceName, true) == 0
                         && fbe.Height == fontHeight
                         && fbe.Deviation == deviation
                         && fbe.Extrusion == extrusion
                         select fbe;

            //  Get the FBE or null.
            var fontOutlineEntry = result == null || result.Count() == 0 ? null : result.First();

            //  If we don't have the FBE, we must create it.
            if (fontOutlineEntry == null)
                fontOutlineEntry = CreateFontOutlineEntry(gl, faceName, fontHeight, deviation, extrusion, FontOutlineFormat.Polygons);

            //  Set the list base.
            gl.ListBase(fontOutlineEntry.ListBase);

            //  Create an array of lists for the glyphs.
            List<byte> lists = new List<byte>();
            foreach(char c in text)
                lists.Add((byte)c);            

            //  Call the lists for the string.
            gl.CallLists(lists.Count, lists.ToArray());
            gl.Flush();
        }
Пример #20
0
        private void SampleRendering(OpenGL gl, float rX, float rY, float rZ)
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
            gl.LoadIdentity();					// Reset The View
            gl.Translate(-1.5f, 0.0f, -6.0f);				// Move Left And Into The Screen

            gl.Rotate(rtri, rX, rY, rZ);				// Rotate The Pyramid On It's Y Axis

            gl.Begin(OpenGL.GL_TRIANGLES);					// Start Drawing The Pyramid

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);			// Red
            gl.Vertex(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);			// Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);			// Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Right Of Triangle (Left)
            gl.End();						// Done Drawing The Pyramid

            gl.LoadIdentity();
            gl.Translate(1.5f, 0.0f, -7.0f);				// Move Right And Into The Screen

            gl.Rotate(rquad, rX, rY, rZ);			// Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.GL_QUADS);					// Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);			// Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)


            gl.Color(1.0f, 0.5f, 0.0f);			// Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);			// Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);			// Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);			// Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);			// Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);			// Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);			// Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);			// Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);			// Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);			// Bottom Right Of The Quad (Right)
            gl.End();						// Done Drawing The Q

            gl.Flush();

            rtri += 1.0f;// 0.2f;						// Increase The Rotation Variable For The Triangle 
            rquad -= 1.0f;// 0.15f;						// Decrease The Rotation Variable For The Quad 
        }
Пример #21
0
        private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Rotate(yaw, 0.0f, 1.0f, 0.0f);
            gl.Rotate(pitch, 1.0f, 0.0f, 0.0f);
            gl.Rotate(roll, 0.0f, 0.0f, 1.0f);
            gl.GetFloat(OpenGL.GL_MODELVIEW_MATRIX, mat);
            gl.PopMatrix();
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.LoadIdentity();
            gl.Translate(0, 0, -10);
            gl.PointSize(6.0f);
            gl.LoadIdentity();
            //gl.LookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -6.0f, 0.0f, 0.0f, 1.0f);
            gl.Translate(0.0f, -1.0f, -5.0f);

            //gl.Rotate(rx, ry, rz);
            gl.Rotate(-yaw, 0.0f, 1.0f, 0.0f);
            gl.Rotate(-pitch, 1.0f, 0.0f, 0.0f);
            gl.Rotate(-roll, 0.0f, 0.0f, 1.0f);
            gl.Scale(1.0f, 0.5f, 2.0f);
            //  Bind the texture.
            texture.Bind(gl);

            gl.Begin(OpenGL.GL_QUADS);

            // Front Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Left Of The Texture and Quad

            // Back Face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Left Of The Texture and Quad

            // Top Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad

            // Bottom Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad

            // Right face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad

            // Left Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.End();

            gl.Flush();
        }
Пример #22
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="deviation">The deviation.</param>
        /// <param name="extrusion">The extrusion.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, string faceName, float fontSize, 
            float deviation, float extrusion, string text)
        {
            //  Get the font size in pixels.
            var fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = (from fbe in fontOutlineEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0
                         && fbe.Height == fontHeight
                         && fbe.Deviation == deviation
                         && fbe.Extrusion == extrusion
                         select fbe).ToList();

            //  Get the FBE or null.
            var fontOutlineEntry = result.FirstOrDefault();

            //  If we don't have the FBE, we must create it.
            if (fontOutlineEntry == null)
                fontOutlineEntry = CreateFontOutlineEntry(gl, faceName, fontHeight, deviation, extrusion, FontOutlineFormat.Polygons);

            //  Set the list base.
            gl.ListBase(fontOutlineEntry.ListBase);

            //  Create an array of lists for the glyphs.
            var lists = text.Select(c => (byte) c).ToArray();

            //  Call the lists for the string.
            gl.CallLists(lists.Length, lists);
            gl.Flush();
        }
Пример #23
0
        private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            //  Get the OpenGL object, just to clean up the code.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
            gl.LoadIdentity();                                           // Reset The View
            gl.Translate(-1.5f, 0.0f, -6.0f);                            // Move Left And Into The Screen

            gl.Rotate(rtri, 0.0f, 1.0f, 0.0f);                           // Rotate The Pyramid On It's Y Axis

            gl.Begin(OpenGL.TRIANGLES);                                  // Start Drawing The Pyramid

            gl.Color(1.0f, 0.0f, 0.0f);                                  // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                                 // Top Of Triangle (Front)
            gl.Color(0.0f, 1.0f, 0.0f);                                  // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);                               // Left Of Triangle (Front)
            gl.Color(0.0f, 0.0f, 1.0f);                                  // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);                                // Right Of Triangle (Front)

            gl.Color(1.0f, 0.0f, 0.0f);                                  // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                                 // Top Of Triangle (Right)
            gl.Color(0.0f, 0.0f, 1.0f);                                  // Blue
            gl.Vertex(1.0f, -1.0f, 1.0f);                                // Left Of Triangle (Right)
            gl.Color(0.0f, 1.0f, 0.0f);                                  // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);                               // Right Of Triangle (Right)

            gl.Color(1.0f, 0.0f, 0.0f);                                  // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                                 // Top Of Triangle (Back)
            gl.Color(0.0f, 1.0f, 0.0f);                                  // Green
            gl.Vertex(1.0f, -1.0f, -1.0f);                               // Left Of Triangle (Back)
            gl.Color(0.0f, 0.0f, 1.0f);                                  // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);                              // Right Of Triangle (Back)

            gl.Color(1.0f, 0.0f, 0.0f);                                  // Red
            gl.Vertex(0.0f, 1.0f, 0.0f);                                 // Top Of Triangle (Left)
            gl.Color(0.0f, 0.0f, 1.0f);                                  // Blue
            gl.Vertex(-1.0f, -1.0f, -1.0f);                              // Left Of Triangle (Left)
            gl.Color(0.0f, 1.0f, 0.0f);                                  // Green
            gl.Vertex(-1.0f, -1.0f, 1.0f);                               // Right Of Triangle (Left)
            gl.End();                                                    // Done Drawing The Pyramid

            gl.LoadIdentity();
            gl.Translate(1.5f, 0.0f, -7.0f);            // Move Right And Into The Screen

            gl.Rotate(rquad, 1.0f, 1.0f, 1.0f);         // Rotate The Cube On X, Y & Z

            gl.Begin(OpenGL.QUADS);                     // Start Drawing The Cube

            gl.Color(0.0f, 1.0f, 0.0f);                 // Set The Color To Green
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Top)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Bottom Left Of The Quad (Top)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Bottom Right Of The Quad (Top)


            gl.Color(1.0f, 0.5f, 0.0f);                 // Set The Color To Orange
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Top Right Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Top Left Of The Quad (Bottom)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Bottom)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Bottom)

            gl.Color(1.0f, 0.0f, 0.0f);                 // Set The Color To Red
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Right Of The Quad (Front)
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Left Of The Quad (Front)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Left Of The Quad (Front)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Right Of The Quad (Front)

            gl.Color(1.0f, 1.0f, 0.0f);                 // Set The Color To Yellow
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Left Of The Quad (Back)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Right Of The Quad (Back)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Right Of The Quad (Back)
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Left Of The Quad (Back)

            gl.Color(0.0f, 0.0f, 1.0f);                 // Set The Color To Blue
            gl.Vertex(-1.0f, 1.0f, 1.0f);               // Top Right Of The Quad (Left)
            gl.Vertex(-1.0f, 1.0f, -1.0f);              // Top Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, -1.0f);             // Bottom Left Of The Quad (Left)
            gl.Vertex(-1.0f, -1.0f, 1.0f);              // Bottom Right Of The Quad (Left)

            gl.Color(1.0f, 0.0f, 1.0f);                 // Set The Color To Violet
            gl.Vertex(1.0f, 1.0f, -1.0f);               // Top Right Of The Quad (Right)
            gl.Vertex(1.0f, 1.0f, 1.0f);                // Top Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, 1.0f);               // Bottom Left Of The Quad (Right)
            gl.Vertex(1.0f, -1.0f, -1.0f);              // Bottom Right Of The Quad (Right)
            gl.End();                                   // Done Drawing The Q

            gl.Flush();

            rtri  += 3.0f; // 0.2f;						// Increase The Rotation Variable For The Triangle
            rquad -= 3.0f; // 0.15f;						// Decrease The Rotation Variable For The Quad
        }
Пример #24
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="r">The r.</param>
        /// <param name="g">The g.</param>
        /// <param name="b">The b.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
        {
            //  Get the font size in pixels.
            var fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = (from fbe in fontBitmapEntries
                          where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle &&
                          fbe.HRC == gl.RenderContextProvider.RenderContextHandle &&
                          String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0 &&
                          fbe.Height == fontHeight
                          select fbe).ToList();

            //  Get the FBE or null.
            var fontBitmapEntry = result.FirstOrDefault();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
            {
                fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);
            }

            double width  = gl.RenderContextProvider.Width;
            double height = gl.RenderContextProvider.Height;

            //  Create the appropriate projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();

            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            gl.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.LoadIdentity();
            gl.Color(r, g, b);
            gl.RasterPos(x, y);

            gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
                          OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
            gl.Color(r, g, b);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.RasterPos(x, y);

            //  Set the list base.
            gl.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            var lists = text.Select(c => (byte)c).ToArray();

            //  Call the lists for the string.
            gl.CallLists(lists.Length, lists);
            gl.Flush();

            //  Reset the list bit.
            gl.PopAttrib();

            //  Pop the modelview.
            gl.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
Пример #25
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="gl">The gl.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="r">The r.</param>
        /// <param name="g">The g.</param>
        /// <param name="b">The b.</param>
        /// <param name="faceName">Name of the face.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="text">The text.</param>
        public void DrawText(OpenGL gl, int x, int y, float r, float g, float b, string faceName, float fontSize, string text)
        {
            //  Get the font size in pixels.
            int fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = from fbe in fontBitmapEntries
                         where fbe.HDC == gl.RenderContextProvider.DeviceContextHandle
                         && fbe.HRC == gl.RenderContextProvider.RenderContextHandle
                         && string.Compare(fbe.FaceName, faceName, true) == 0
                         && fbe.Height == fontHeight
                         select fbe;

            //  Get the FBE or null.
            FontBitmapEntry fontBitmapEntry = result == null || result.Count() == 0 ? null : result.First();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
                fontBitmapEntry = CreateFontBitmapEntry(gl, faceName, fontHeight);

            double width = gl.RenderContextProvider.Width;
            double height = gl.RenderContextProvider.Height;

            double aspect_ratio = width / height;
            
            //  Create the appropriate projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PushMatrix();
            gl.LoadIdentity();
            
            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);
            //gl.Ortho2D(viewport[0], viewport[2], viewport[1], viewport[3]);
            gl.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();
            gl.LoadIdentity();
            //gl.Translate(0, 0, -5);
            //gl.RasterPos(x, y);
            gl.Color(r, g, b);
            gl.RasterPos(x, y);

            gl.PushAttrib(OpenGL.GL_LIST_BIT | OpenGL.GL_CURRENT_BIT |
                OpenGL.GL_ENABLE_BIT | OpenGL.GL_TRANSFORM_BIT);
            gl.Color(r, g, b);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.Disable(OpenGL.GL_DEPTH_TEST);
            gl.RasterPos(x, y);
           /** gl.Enable(OpenGL.GL_BLEND);
            gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); */

            //  Set the list base.
            gl.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            List<byte> lists = new List<byte>();
            foreach(char c in text)
                lists.Add((byte)c);            

            //  Call the lists for the string.
            gl.CallLists(lists.Count, lists.ToArray());
            gl.Flush();
            
            //  Reset the list bit.
            gl.PopAttrib();

            //  Pop the modelview.
            gl.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.PopMatrix();
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }
Пример #26
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            OpenGL gl = new OpenGL();

            ballX -= balMovX;
            ballY -= balMovY;
            if (Convert.ToInt32(ballX) == -gameSizeX)
            {
                balMovX = -0.08f;
            }
            else if (Convert.ToInt32(ballX) == gameSizeX)
            {
                balMovX = 0.08f;
            }
            if (Convert.ToInt32(ballY) == -gameSizeY)
            {
                balMovY = -0.03f;
            }
            else if (Convert.ToInt32(ballY) == gameSizeY)
            {
                balMovY = 0.03f;
            }

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.LoadIdentity();
            gl.Translate(gameX, gameY, gameZ);
            gameRect(gl);

            Ball(gl);
            Bed(gl,bed1X, bed1Y, bed1Z, 0.2f, 1.8f);
            Bed(gl,bed2X, bed2Y, bed2Z, 0.2f, 1.8f);

            gl.Flush();
        }
Пример #27
0
        private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e)
        {
            float qw = q0;
            float qx = q1;
            float qy = q2;
            float qz = q3;

            //if (Math.Abs(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3 - 1.0f) > 0.1f) return;
            float[] rotMat = { 1.0f - 2.0f * qy * qy - 2.0f * qz * qz,        2.0f * qx * qy - 2.0f * qz * qw,        2.0f * qx * qz + 2.0f * qy * qw, 0.0f,
                               2.0f * qx * qy + 2.0f * qz * qw,        1.0f - 2.0f * qx * qx - 2.0f * qz * qz,        2.0f * qy * qz - 2.0f * qx * qw, 0.0f,
                               2.0f * qx * qz - 2.0f * qy * qw,               2.0f * qy * qz + 2.0f * qx * qw, 1.0f - 2.0f * qx * qx - 2.0f * qy * qy, 0.0f,
                               0.0f,                                                                     0.0f,                                   0.0f, 1.0f };
            //  Get the OpenGL object, for quick access.
            SharpGL.OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.LoadIdentity();
            //gl.LookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -6.0f, 0.0f, 0.0f, 1.0f);
            gl.Translate(0.0f, -1.0f, -5.0f);

            //gl.Rotate(rx, ry, rz);
            //gl.Rotate(-yaw, 0.0f, 1.0f, 0.0f);
            //gl.Rotate(-pitch, 1.0f, 0.0f, 0.0f);
            //gl.Rotate(-roll, 0.0f, 0.0f, 1.0f);
            gl.MultMatrix(rotMat);
            gl.Scale(1.0f, 0.5f, 2.0f);
            //  Bind the texture.
            texture.Bind(gl);

            gl.Begin(OpenGL.GL_QUADS);

            // Front Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Left Of The Texture and Quad

            // Back Face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Left Of The Texture and Quad

            // Top Face
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad

            // Bottom Face
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad

            // Right face
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(1.0f, -1.0f, -1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(1.0f, 1.0f, -1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(1.0f, 1.0f, 1.0f);       // Top Left Of The Texture and Quad
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(1.0f, -1.0f, 1.0f);      // Bottom Left Of The Texture and Quad

            // Left Face
            gl.TexCoord(0.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, -1.0f);    // Bottom Left Of The Texture and Quad
            gl.TexCoord(1.0f, 0.0f); gl.Vertex(-1.0f, -1.0f, 1.0f);     // Bottom Right Of The Texture and Quad
            gl.TexCoord(1.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, 1.0f);      // Top Right Of The Texture and Quad
            gl.TexCoord(0.0f, 1.0f); gl.Vertex(-1.0f, 1.0f, -1.0f);     // Top Left Of The Texture and Quad
            gl.End();

            gl.Flush();
        }