当前位置: 首页>>代码示例>>C#>>正文


C# OpenGL.PushMatrix方法代码示例

本文整理汇总了C#中SharpGL.OpenGL.PushMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.PushMatrix方法的具体用法?C# OpenGL.PushMatrix怎么用?C# OpenGL.PushMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpGL.OpenGL的用法示例。


在下文中一共展示了OpenGL.PushMatrix方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PushObjectSpace

 public void PushObjectSpace(OpenGL gl)
 {
     gl.PushMatrix();
     gl.Translate(pos.X, pos.Y, pos.Z);
     if (material != null)
         material.Push(gl);
 }
开发者ID:chances,项目名称:Animatum,代码行数:7,代码来源:Sphere.cs

示例2: DrawText

        /// <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);
        }
开发者ID:hhool,项目名称:sharpgl,代码行数:80,代码来源:FontOutlines.cs

示例3: ComputeBoundingBox

        private void ComputeBoundingBox(Node node, ref Vector3 min, ref Vector3 max, ref Matrix4 trafo, ref OpenGL gl)
        {
            gl.PushMatrix();
            gl.LoadIdentity();
            Matrix4 prev = trafo;
            trafo = Matrix4.Mult(prev, FromMatrix(node.Transform));

            if (node.HasMeshes)
            {
                foreach (int index in node.MeshIndices)
                {
                    Mesh mesh = m_model.Meshes[index];
                    for (int i = 0; i < mesh.VertexCount; i++)
                    {
                        Vector3 tmp = FromVector(mesh.Vertices[i]);
                        Vector3.Transform(tmp, trafo);

                        min.X = Math.Min(min.X, tmp.X);
                        min.Y = Math.Min(min.Y, tmp.Y);
                        min.Z = Math.Min(min.Z, tmp.Z);

                        max.X = Math.Max(max.X, tmp.X);
                        max.Y = Math.Max(max.Y, tmp.Y);
                        max.Z = Math.Max(max.Z, tmp.Z);
                    }
                }
            }

            for (int i = 0; i < node.ChildCount; i++)
            {
                ComputeBoundingBox(node.Children[i], ref min, ref max, ref trafo, ref gl);
            }
            trafo = prev;
        }
开发者ID:EternalEnvy,项目名称:SmackBrosClient,代码行数:34,代码来源:GameplayScreen.cs

示例4: RecursiveRender

        private void RecursiveRender(Assimp.Scene scene, Node node, ref OpenGL gl)
        {
            Matrix4 m = FromMatrix(node.Transform);
            m.Transpose();
            gl.PushMatrix();
            gl.MultMatrix(FloatFromMatrix(m));

            if (node.HasMeshes)
            {
                foreach (int index in node.MeshIndices)
                {
                    Mesh mesh = scene.Meshes[index];
                    ApplyMaterial(m_model.Materials[mesh.MaterialIndex], ref gl);

                    if (mesh.HasNormals)
                    {

                        gl.Enable(OpenGL.GL_LIGHTING);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_LIGHTING);
                    }

                    bool hasColors = mesh.HasVertexColors(0);
                    if (hasColors)
                    {
                        gl.Enable(OpenGL.GL_COLOR_MATERIAL);
                    }
                    else
                    {
                        gl.Disable(OpenGL.GL_COLOR_MATERIAL);
                    }

                    bool hasTexCoords = mesh.HasTextureCoords(0);

                    foreach (Assimp.Face face in mesh.Faces)
                    {
                        BeginMode faceMode;
                        switch (face.IndexCount)
                        {
                            case 1:
                                faceMode = BeginMode.Points;
                                break;
                            case 2:
                                faceMode = BeginMode.Lines;
                                break;
                            case 3:
                                faceMode = BeginMode.Triangles;
                                break;
                            default:
                                faceMode = BeginMode.Polygon;
                                break;
                        }

                        gl.Begin(faceMode);
                        for (int i = 0; i < face.IndexCount; i++)
                        {
                            int indice = face.Indices[i];
                            if (hasColors)
                            {
                                Color4 vertColor = FromColor(mesh.VertexColorChannels[0][indice]);
                                if (mesh.HasNormals)
                                {
                                    Vector3 normal = FromVector(mesh.Normals[indice]);
                                    gl.Normal(normal.X, normal.Y, normal.Z);
                                }
                                if (hasTexCoords)
                                {
                                    Vector3 uvw = FromVector(mesh.TextureCoordinateChannels[0][indice]);
                                    gl.TexCoord(uvw.X, 1 - uvw.Y);
                                }
                                Vector3 pos = FromVector(mesh.Vertices[indice]);
                                gl.Vertex(pos.X, pos.Y, pos.Z);
                            }
                            gl.End();
                        }
                    }
                }

                for (int i = 0; i < node.ChildCount; i++)
                {
                    RecursiveRender(m_model, node.Children[i], ref gl);
                }
            }
        }
开发者ID:EternalEnvy,项目名称:SmackBrosClient,代码行数:86,代码来源:GameplayScreen.cs

示例5: PushObjectSpace

 /// <summary>
 /// Push a new object space onto the stack and then apply a translation transformation.
 /// </summary>
 /// <param name="gl">The OpenGL render context</param>
 /// <param name="translation">The translation transformation to apply.</param>
 public void PushObjectSpace(OpenGL gl, Vertex translation)
 {
     gl.PushMatrix();
     gl.Translate(translation.X, translation.Y, translation.Z);
     Rotate(gl);
 }
开发者ID:chances,项目名称:Animatum,代码行数:11,代码来源:RotateTransform.cs

示例6: RenderForHitTest

        public override void RenderForHitTest(OpenGL gl, Dictionary<uint, Node> hitMap, ref uint currentName)
        {
            if (!Visible)
                return;

            gl.PushMatrix();
            gl.Translate(TransformedPosition.X, TransformedPosition.Y,
                TransformedPosition.Z);

            gl.LoadName(currentName);
            hitMap[currentName] = this;

            sphere.Render(gl);

            currentName++;

            sphere.PopObjectSpace(gl);

            // Render children
            foreach (Bone bone in children)
            {
                bone.RenderForHitTest(gl, hitMap, ref currentName);
            }
        }
开发者ID:chances,项目名称:Animatum,代码行数:24,代码来源:Bone.cs

示例7: Render

        public override void Render(OpenGL gl)
        {
            if (!Visible)
                return;

            gl.PushMatrix();
            if (sphere.Material != null)
                sphere.Material.Push(gl);
            gl.Translate(TransformedPosition.X, TransformedPosition.Y,
                TransformedPosition.Z);
            sphere.Render(gl);
            sphere.PopObjectSpace(gl);
            //Render children and the lines connecting them
            foreach (Bone bone in children)
            {
                DrawLine(gl, TransformedPosition, bone.TransformedPosition, Color, bone.Color);
                bone.Render(gl);
            }
        }
开发者ID:chances,项目名称:Animatum,代码行数:19,代码来源:Bone.cs

示例8: PushObjectSpace

 public void PushObjectSpace(OpenGL gl)
 {
     gl.PushMatrix();
 }
开发者ID:chances,项目名称:Animatum,代码行数:4,代码来源:Line.cs

示例9: DrawText

        /// <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);
        }
开发者ID:mind0n,项目名称:hive,代码行数:89,代码来源:FontOutlines.cs

示例10: drawModel

 /// <summary>
 /// Function to draw the model
 /// </summary>
 private void drawModel(OpenGL gl) 
 {
     if(l_vboId != null)
     {
         gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
         // itering over each list of points
         for(int k = 0; k < l_vboId.Count; k++)
         {
             gl.PushMatrix();
                 //transformations
                 gl.Scale(1.0f / f_scale, 1.0f / f_scale, 1.0f / f_scale);
                 gl.Translate(-v_center.X, -v_center.Y, -v_center.Z);
                 //vertexes
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][0]);
                 gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //color
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][1]);
                 gl.ColorPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //draw l_sizes[k] points
                 gl.DrawArrays(OpenGL.GL_POINTS, 0, l_sizes[k]);
             gl.PopMatrix();
         }
         gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
         gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
     }
 }
开发者ID:esmitt,项目名称:csharpOpenGL,代码行数:31,代码来源:SharpGLForm.cs


注:本文中的SharpGL.OpenGL.PushMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。