예제 #1
0
        public void Draw()
        {
            if ( Text == null )
            {
                return;
            }
            if ( Text.Length == 0 )
            {
                return;
            }
            if ( TextFont == null )
            {
                return;
            }

            int CharCode = 0;
            float CharWidth = 0;
            sXY_sng TexRatio = new sXY_sng();
            float LetterPosA = 0;
            float LetterPosB = 0;
            float PosY1 = 0;
            float PosY2 = 0;
            float CharSpacing = 0;
            int A = 0;

            GL.Color4(Colour.Red, Colour.Green, Colour.Blue, Colour.Alpha);
            PosY1 = Pos.Y;
            PosY2 = Pos.Y + SizeY;
            CharSpacing = SizeY / 10.0F;
            LetterPosA = Pos.X;
            for ( A = 0; A <= Text.Length - 1; A++ )
            {
                CharCode = Strings.AscW(Text[A]);
                if ( CharCode >= 0 & CharCode <= 255 )
                {
                    CharWidth = (float)(SizeY * TextFont.Character[CharCode].Width / TextFont.Height);
                    TexRatio.X = (float)(TextFont.Character[CharCode].Width / TextFont.Character[CharCode].TexSize);
                    TexRatio.Y = (float)(TextFont.Height / TextFont.Character[CharCode].TexSize);
                    LetterPosB = LetterPosA + CharWidth;
                    GL.BindTexture(TextureTarget.Texture2D, TextFont.Character[CharCode].GLTexture);
                    GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
                    GL.Begin(BeginMode.Quads);
                    GL.TexCoord2(0.0F, 0.0F);
                    GL.Vertex2(LetterPosA, PosY1);
                    GL.TexCoord2(0.0F, TexRatio.Y);
                    GL.Vertex2(LetterPosA, PosY2);
                    GL.TexCoord2(TexRatio.X, TexRatio.Y);
                    GL.Vertex2(LetterPosB, PosY2);
                    GL.TexCoord2(TexRatio.X, 0.0F);
                    GL.Vertex2(LetterPosB, PosY1);
                    GL.End();
                    LetterPosA = LetterPosB + CharSpacing;
                }
            }
        }
예제 #2
0
        public static void GetTileRotatedTexCoords(TileOrientation tileOrientation, sXY_sng coordA, sXY_sng coordB, sXY_sng coordC,
            sXY_sng coordD)
        {
            TileOrientation ReverseOrientation = new TileOrientation();

            ReverseOrientation = tileOrientation;
            ReverseOrientation.Reverse();

            if ( ReverseOrientation.SwitchedAxes )
            {
                if ( ReverseOrientation.ResultXFlip )
                {
                    coordA.X = 1.0F;
                    coordB.X = 1.0F;
                    coordC.X = 0.0F;
                    coordD.X = 0.0F;
                }
                else
                {
                    coordA.X = 0.0F;
                    coordB.X = 0.0F;
                    coordC.X = 1.0F;
                    coordD.X = 1.0F;
                }
                if ( ReverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1.0F;
                    coordB.Y = 0.0F;
                    coordC.Y = 1.0F;
                    coordD.Y = 0.0F;
                }
                else
                {
                    coordA.Y = 0.0F;
                    coordB.Y = 1.0F;
                    coordC.Y = 0.0F;
                    coordD.Y = 1.0F;
                }
            }
            else
            {
                if ( ReverseOrientation.ResultXFlip )
                {
                    coordA.X = 1.0F;
                    coordB.X = 0.0F;
                    coordC.X = 1.0F;
                    coordD.X = 0.0F;
                }
                else
                {
                    coordA.X = 0.0F;
                    coordB.X = 1.0F;
                    coordC.X = 0.0F;
                    coordD.X = 1.0F;
                }
                if ( ReverseOrientation.ResultYFlip )
                {
                    coordA.Y = 1.0F;
                    coordB.Y = 1.0F;
                    coordC.Y = 0.0F;
                    coordD.Y = 0.0F;
                }
                else
                {
                    coordA.Y = 0.0F;
                    coordB.Y = 0.0F;
                    coordC.Y = 1.0F;
                    coordD.Y = 1.0F;
                }
            }
        }
예제 #3
0
        public static sXY_sng GetTileRotatedPos_sng(TileOrientation tileOrientation, sXY_sng pos)
        {
            sXY_sng ReturnResult = new sXY_sng();

            if ( tileOrientation.SwitchedAxes )
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.X = pos.Y;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.Y = pos.X;
                }
            }
            else
            {
                if ( tileOrientation.ResultXFlip )
                {
                    ReturnResult.X = 1.0F - pos.X;
                }
                else
                {
                    ReturnResult.X = pos.X;
                }
                if ( tileOrientation.ResultYFlip )
                {
                    ReturnResult.Y = 1.0F - pos.Y;
                }
                else
                {
                    ReturnResult.Y = pos.Y;
                }
            }

            return ReturnResult;
        }
예제 #4
0
            public override void Perform()
            {
                clsTerrain Terrain = Map.Terrain;
                clsTileset Tileset = Map.Tileset;
                double[] TileTerrainHeight = new double[4];
                sXYZ_sng Vertex0 = new sXYZ_sng();
                sXYZ_sng Vertex1 = new sXYZ_sng();
                sXYZ_sng Vertex2 = new sXYZ_sng();
                sXYZ_sng Vertex3 = new sXYZ_sng();
                sXYZ_sng Normal0 = new sXYZ_sng();
                sXYZ_sng Normal1 = new sXYZ_sng();
                sXYZ_sng Normal2 = new sXYZ_sng();
                sXYZ_sng Normal3 = new sXYZ_sng();
                sXY_sng TexCoord0 = new sXY_sng();
                sXY_sng TexCoord1 = new sXY_sng();
                sXY_sng TexCoord2 = new sXY_sng();
                sXY_sng TexCoord3 = new sXY_sng();
                int A = 0;

                if ( Terrain.Tiles[TileX, TileY].Texture.TextureNum < 0 )
                {
                    GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_NoTile);
                }
                else if ( Tileset == null )
                {
                    GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile);
                }
                else if ( Terrain.Tiles[TileX, TileY].Texture.TextureNum < Tileset.TileCount )
                {
                    A = Tileset.Tiles[Terrain.Tiles[TileX, TileY].Texture.TextureNum].MapView_GL_Texture_Num;
                    if ( A == 0 )
                    {
                        GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile);
                    }
                    else
                    {
                        GL.BindTexture(TextureTarget.Texture2D, A);
                    }
                }
                else
                {
                    GL.BindTexture(TextureTarget.Texture2D, App.GLTexture_OverflowTile);
                }
                GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);

                TileTerrainHeight[0] = Terrain.Vertices[TileX, TileY].Height;
                TileTerrainHeight[1] = Terrain.Vertices[TileX + 1, TileY].Height;
                TileTerrainHeight[2] = Terrain.Vertices[TileX, TileY + 1].Height;
                TileTerrainHeight[3] = Terrain.Vertices[TileX + 1, TileY + 1].Height;

                TileUtil.GetTileRotatedTexCoords(Terrain.Tiles[TileX, TileY].Texture.Orientation, TexCoord0, TexCoord1, TexCoord2, TexCoord3);

                Vertex0.X = TileX * App.TerrainGridSpacing;
                Vertex0.Y = (float)(TileTerrainHeight[0] * Map.HeightMultiplier);
                Vertex0.Z = - TileY * App.TerrainGridSpacing;
                Vertex1.X = (TileX + 1) * App.TerrainGridSpacing;
                Vertex1.Y = (float)(TileTerrainHeight[1] * Map.HeightMultiplier);
                Vertex1.Z = - TileY * App.TerrainGridSpacing;
                Vertex2.X = TileX * App.TerrainGridSpacing;
                Vertex2.Y = (float)(TileTerrainHeight[2] * Map.HeightMultiplier);
                Vertex2.Z = - (TileY + 1) * App.TerrainGridSpacing;
                Vertex3.X = (TileX + 1) * App.TerrainGridSpacing;
                Vertex3.Y = (float)(TileTerrainHeight[3] * Map.HeightMultiplier);
                Vertex3.Z = - (TileY + 1) * App.TerrainGridSpacing;

                Normal0 = Map.TerrainVertexNormalCalc(TileX, TileY);
                Normal1 = Map.TerrainVertexNormalCalc(TileX + 1, TileY);
                Normal2 = Map.TerrainVertexNormalCalc(TileX, TileY + 1);
                Normal3 = Map.TerrainVertexNormalCalc(TileX + 1, TileY + 1);

                GL.Begin(BeginMode.Triangles);
                if ( Terrain.Tiles[TileX, TileY].Tri )
                {
                    GL.Normal3(Normal0.X, Normal0.Y, Convert.ToDouble(- Normal0.Z));
                    GL.TexCoord2(TexCoord0.X, TexCoord0.Y);
                    GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Normal3(Normal2.X, Normal2.Y, Convert.ToDouble(- Normal2.Z));
                    GL.TexCoord2(TexCoord2.X, TexCoord2.Y);
                    GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                    GL.Normal3(Normal1.X, Normal1.Y, Convert.ToDouble(- Normal1.Z));
                    GL.TexCoord2(TexCoord1.X, TexCoord1.Y);
                    GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));

                    GL.Normal3(Normal1.X, Normal1.Y, Convert.ToDouble(- Normal1.Z));
                    GL.TexCoord2(TexCoord1.X, TexCoord1.Y);
                    GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                    GL.Normal3(Normal2.X, Normal2.Y, Convert.ToDouble(- Normal2.Z));
                    GL.TexCoord2(TexCoord2.X, TexCoord2.Y);
                    GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                    GL.Normal3(Normal3.X, Normal3.Y, Convert.ToDouble(- Normal3.Z));
                    GL.TexCoord2(TexCoord3.X, TexCoord3.Y);
                    GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                }
                else
                {
                    GL.Normal3(Normal0.X, Normal0.Y, Convert.ToDouble(- Normal0.Z));
                    GL.TexCoord2(TexCoord0.X, TexCoord0.Y);
                    GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Normal3(Normal2.X, Normal2.Y, Convert.ToDouble(- Normal2.Z));
                    GL.TexCoord2(TexCoord2.X, TexCoord2.Y);
                    GL.Vertex3(Vertex2.X, Vertex2.Y, Convert.ToDouble(- Vertex2.Z));
                    GL.Normal3(Normal3.X, Normal3.Y, Convert.ToDouble(- Normal3.Z));
                    GL.TexCoord2(TexCoord3.X, TexCoord3.Y);
                    GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));

                    GL.Normal3(Normal0.X, Normal0.Y, Convert.ToDouble(- Normal0.Z));
                    GL.TexCoord2(TexCoord0.X, TexCoord0.Y);
                    GL.Vertex3(Vertex0.X, Vertex0.Y, Convert.ToDouble(- Vertex0.Z));
                    GL.Normal3(Normal3.X, Normal3.Y, Convert.ToDouble(- Normal3.Z));
                    GL.TexCoord2(TexCoord3.X, TexCoord3.Y);
                    GL.Vertex3(Vertex3.X, Vertex3.Y, Convert.ToDouble(- Vertex3.Z));
                    GL.Normal3(Normal1.X, Normal1.Y, Convert.ToDouble(- Normal1.Z));
                    GL.TexCoord2(TexCoord1.X, TexCoord1.Y);
                    GL.Vertex3(Vertex1.X, Vertex1.Y, Convert.ToDouble(- Vertex1.Z));
                }
                GL.End();
            }
예제 #5
0
        private void DrawView()
        {
            if ( !(DrawView_Enabled && IsGLInitialized) )
            {
                return;
            }

            if ( GraphicsContext.CurrentContext != OpenGLControl.Context )
            {
                OpenGLControl.MakeCurrent();
            }

            GL.Clear(ClearBufferMask.ColorBufferBit);

            clsMap Map = MainMap;

            if ( Map == null )
            {
                GL.Flush();
                OpenGLControl.SwapBuffers();
                Refresh();
                return;
            }

            int X = 0;
            int Y = 0;
            int Num = 0;
            sXY_int XY_int = new sXY_int();
            int A = 0;
            sXY_sng Vertex0 = new sXY_sng();
            sXY_sng Vertex1 = new sXY_sng();
            sXY_sng Vertex2 = new sXY_sng();
            sXY_sng UnrotatedPos = new sXY_sng();
            sXY_sng TexCoord0 = new sXY_sng();
            sXY_sng TexCoord1 = new sXY_sng();
            sXY_sng TexCoord2 = new sXY_sng();
            sXY_sng TexCoord3 = new sXY_sng();

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 temp_mat = Matrix4.CreateOrthographicOffCenter(0.0F, GLSize.X, GLSize.Y, 0.0F, -1.0F, 1.0F);
            GL.LoadMatrix(ref temp_mat);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            if ( Map.Tileset != null )
            {
                TileUtil.GetTileRotatedTexCoords(App.TextureOrientation, TexCoord0, TexCoord1, TexCoord2, TexCoord3);

                GL.Enable(EnableCap.Texture2D);
                GL.Color4(0.0F, 0.0F, 0.0F, 1.0F);

                for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                {
                    for ( X = 0; X <= TextureCount.X - 1; X++ )
                    {
                        Num = (TextureYOffset + Y) * TextureCount.X + X;
                        if ( Num >= Map.Tileset.TileCount )
                        {
                            goto EndOfTextures1;
                        }
                        A = Map.Tileset.Tiles[Num].TextureView_GL_Texture_Num;
                        if ( A == 0 )
                        {
                            GL.BindTexture(TextureTarget.Texture2D, 0);
                        }
                        else
                        {
                            GL.BindTexture(TextureTarget.Texture2D, A);
                        }
                        GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal);
                        GL.Begin(BeginMode.Quads);
                        GL.TexCoord2(TexCoord0.X, TexCoord0.Y);
                        GL.Vertex2(X * 64, Y * 64);
                        GL.TexCoord2(TexCoord2.X, TexCoord2.Y);
                        GL.Vertex2(X * 64, Y * 64 + 64);
                        GL.TexCoord2(TexCoord3.X, TexCoord3.Y);
                        GL.Vertex2(X * 64 + 64, Y * 64 + 64);
                        GL.TexCoord2(TexCoord1.X, TexCoord1.Y);
                        GL.Vertex2(X * 64 + 64, Y * 64);
                        GL.End();
                    }
                }

                EndOfTextures1:

                GL.Disable(EnableCap.Texture2D);

                if ( DisplayTileTypes )
                {
                    GL.Begin(BeginMode.Quads);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures2;
                            }
                            A = Map.Tile_TypeNum[Num];
                            GL.Color3(App.TileTypes[A].DisplayColour.Red, App.TileTypes[A].DisplayColour.Green, App.TileTypes[A].DisplayColour.Blue);
                            GL.Vertex2(X * 64 + 24, Y * 64 + 24);
                            GL.Vertex2(X * 64 + 24, Y * 64 + 40);
                            GL.Vertex2(X * 64 + 40, Y * 64 + 40);
                            GL.Vertex2(X * 64 + 40, Y * 64 + 24);
                        }
                    }
                    EndOfTextures2:
                    GL.End();
                }

                if ( App.DisplayTileOrientation )
                {
                    GL.Disable(EnableCap.CullFace);

                    UnrotatedPos.X = 0.25F;
                    UnrotatedPos.Y = 0.25F;
                    Vertex0 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.25F;
                    Vertex1 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);
                    UnrotatedPos.X = 0.5F;
                    UnrotatedPos.Y = 0.5F;
                    Vertex2 = TileUtil.GetTileRotatedPos_sng(App.TextureOrientation, UnrotatedPos);

                    GL.Begin(BeginMode.Triangles);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures3;
                            }
                            GL.Vertex2(X * 64 + Vertex0.X * 64, Y * 64 + Vertex0.Y * 64);
                            GL.Vertex2(X * 64 + Vertex2.X * 64, Y * 64 + Vertex2.Y * 64);
                            GL.Vertex2(X * 64 + Vertex1.X * 64, Y * 64 + Vertex1.Y * 64);
                        }
                    }
                    EndOfTextures3:
                    GL.End();

                    GL.Enable(EnableCap.CullFace);
                }

                if ( DisplayTileNumbers && App.UnitLabelFont != null ) //TextureViewFont IsNot Nothing Then
                {
                    clsTextLabel TextLabel = default(clsTextLabel);
                    GL.Enable(EnableCap.Texture2D);
                    for ( Y = 0; Y <= TextureCount.Y - 1; Y++ )
                    {
                        for ( X = 0; X <= TextureCount.X - 1; X++ )
                        {
                            Num = (TextureYOffset + Y) * TextureCount.X + X;
                            if ( Num >= Map.Tileset.TileCount )
                            {
                                goto EndOfTextures4;
                            }
                            TextLabel = new clsTextLabel();
                            TextLabel.Text = IOUtil.InvariantToString(Num);
                            TextLabel.SizeY = 24.0F;
                            TextLabel.Colour.Red = 1.0F;
                            TextLabel.Colour.Green = 1.0F;
                            TextLabel.Colour.Blue = 0.0F;
                            TextLabel.Colour.Alpha = 1.0F;
                            TextLabel.Pos.X = X * 64;
                            TextLabel.Pos.Y = Y * 64;
                            TextLabel.TextFont = App.UnitLabelFont; //TextureViewFont
                            TextLabel.Draw();
                        }
                    }
                    EndOfTextures4:
                    GL.Disable(EnableCap.Texture2D);
                }

                if ( App.SelectedTextureNum >= 0 & TextureCount.X > 0 )
                {
                    A = App.SelectedTextureNum - TextureYOffset * TextureCount.X;
                    XY_int.X = A - ((int)(Conversion.Int(A / TextureCount.X))) * TextureCount.X;
                    XY_int.Y = (int)(Conversion.Int(A / TextureCount.X));
                    GL.Begin(BeginMode.LineLoop);
                    GL.Color3(1.0F, 1.0F, 0.0F);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64);
                    GL.Vertex2(XY_int.X * 64, XY_int.Y * 64.0D + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64 + 64);
                    GL.Vertex2(XY_int.X * 64 + 64, XY_int.Y * 64);
                    GL.End();
                }
            }

            GL.Flush();
            OpenGLControl.SwapBuffers();

            Refresh();
        }