コード例 #1
0
 public void Begin()
 {
     GL.Disable(EnableCap.DepthTest);
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
     GL.EnableClientState(ArrayCap.VertexArray);
     GL.EnableClientState(ArrayCap.ColorArray);
     GL.EnableClientState(ArrayCap.TextureCoordArray);
     GL.BindBuffer(BufferTarget.ArrayBuffer, fontVertexBuffer);
     GL.VertexPointer(3, VertexPointerType.Float, 24, IntPtr.Zero);
     GL.ColorPointer(4, ColorPointerType.UnsignedByte, 24, (IntPtr)12);
     GL.TexCoordPointer(2, TexCoordPointerType.Float, 24, (IntPtr)16);
     Render.SetWorld(ref world);
     Render.SetView(ref view);
     Render.SetProjection(ref projection);
     Render.EnableTexture = true;
     Render.Texture       = textureHandle;
 }
コード例 #2
0
ファイル: DemoFont3D.cs プロジェクト: 0000duck/KAOS-Engine
        public void Draw(float x, float y, float z, float scaleX, float scaleY, string text, Color color)
        {
            int     fontValue, textLength, textBufferLength, fontColor;
            float   u, v, translation, fontSizeX, fontSizeY, fontWidth, fontHeight, fontMargin;
            Matrix4 fontTranslation, fontWorld;

            Render.GetWorld(ref world);

            Matrix4.CreateTranslation(x, y, 0.0f, out fontTranslation);
            Matrix4.Mult(ref world, ref fontTranslation, out fontWorld);

            Render.SetWorld(ref fontWorld);

            translation = 0.0f;
            fontSizeX   = 16 * scaleX;
            fontSizeY   = 16 * scaleY;
            fontWidth   = 1.0f / 16.0f;
            fontHeight  = 1.0f / 16.0f;
            fontMargin  = 1.0f / 256.0f;
            fontColor   = color.ToArgb();

            for (int i = 0, j = 0; i < text.Length; i++, j += 4)
            {
                fontValue = (int)text[i];
                u         = (float)(fontValue % 16) * fontWidth + fontMargin;
                v         = (float)(fontValue >> 4) * fontHeight + fontMargin;

                fontVertices[j].Position.X          = translation;
                fontVertices[j].Position.Y          = 0.0f;
                fontVertices[j].Position.Z          = z;
                fontVertices[j].TextureCoordinate.X = u;
                fontVertices[j].TextureCoordinate.Y = v + fontHeight;
                fontVertices[j].Color = fontColor;

                fontVertices[j + 1].Position.X          = fontSizeX + translation;
                fontVertices[j + 1].Position.Y          = 0.0f;
                fontVertices[j + 1].Position.Z          = z;
                fontVertices[j + 1].TextureCoordinate.X = u + fontWidth;
                fontVertices[j + 1].TextureCoordinate.Y = v + fontHeight;
                fontVertices[j + 1].Color = fontColor;

                fontVertices[j + 2].Position.X          = translation;
                fontVertices[j + 2].Position.Y          = fontSizeY;
                fontVertices[j + 2].Position.Z          = z;
                fontVertices[j + 2].TextureCoordinate.X = u;
                fontVertices[j + 2].TextureCoordinate.Y = v;
                fontVertices[j + 2].Color = fontColor;

                fontVertices[j + 3].Position.X          = fontSizeX + translation;
                fontVertices[j + 3].Position.Y          = fontSizeY;
                fontVertices[j + 3].Position.Z          = z;
                fontVertices[j + 3].TextureCoordinate.X = u + fontWidth;
                fontVertices[j + 3].TextureCoordinate.Y = v;
                fontVertices[j + 3].Color = fontColor;

                translation += fontTranslations[fontValue] * scaleX;
            }

            textLength       = text.Length << 2;
            textBufferLength = 24 * textLength;

            Render.Apply();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)textBufferLength, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)textBufferLength, fontVertices, BufferUsageHint.DynamicDraw);

            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, textLength);

            Render.SetWorld(ref world);
        }
コード例 #3
0
ファイル: MenuDraw1.cs プロジェクト: 0000duck/KAOS-Engine
        void Draw(DrawMethodArgs args)
        {
            PhysicsScene  scene      = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex);
            PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex);

            PhysicsObject physicsObjectWithCamera = scene.GetPhysicsObjectWithCamera(0);

            if (physicsObjectWithCamera == null)
            {
                return;
            }

            PhysicsCamera activeCamera = physicsObjectWithCamera.Camera;

            if (activeCamera == null)
            {
                return;
            }

            float time = args.Time;

            if ((infoScreen == null) || (infoDescription == null))
            {
                return;
            }
            if (!infoDescription.EnableDrawing)
            {
                return;
            }

            string sceneScreenName = infoScreen.Material.UserDataStr;

            if (sceneScreenName == null)
            {
                return;
            }
            if (!demo.Descriptions.ContainsKey(sceneScreenName))
            {
                return;
            }

            List <string> Descriptions = demo.Descriptions[sceneScreenName];

            string info = null;

            infoDescription.MainWorldTransform.GetPosition(ref position);
            activeCamera.View.GetViewMatrix(ref view);
            activeCamera.Projection.GetProjectionMatrix(ref projection);

            RenderPCT render = demo.DemoFont3D.Render;

            render.SetWorld(ref world);
            render.SetView(ref view);
            render.SetProjection(ref projection);

            GL.CullFace(CullFaceMode.Back);

            demo.DemoFont3D.Begin();

            for (int i = 0; i < Descriptions.Count; i++)
            {
                info = Descriptions[i];

                if (info != null)
                {
                    demo.DemoFont3D.Draw(position.X - 25.0f, position.Y + 12.0f - 1.4f * i, position.Z - 0.5f, 0.08125f, 0.12125f, info, whiteColor);
                }
            }

            demo.DemoFont3D.End();
        }