Esempio n. 1
0
        public Texture(Bitmap Bmp)
        {
            Width  = Bmp.Width;
            Height = Bmp.Height;

            Id       = TexUtil.CreateTextureFromBitmap(Bmp);
            Animated = false;
        }
Esempio n. 2
0
        public Texture(Bitmap Bmp, int Frames)
        {
            Width  = Bmp.Width / Frames;
            Height = Bmp.Height;

            Id          = TexUtil.CreateTextureFromBitmap(Bmp);
            this.Frames = Frames;
            Animated    = true;
        }
Esempio n. 3
0
        public Texture(string Path)
        {
            var Bmp = new Bitmap(Path);

            Width  = Bmp.Width;
            Height = Bmp.Height;

            Id       = TexUtil.CreateTextureFromBitmap(Bmp);
            Animated = false;
        }
Esempio n. 4
0
        public Texture(string Path, int Frames)
        {
            var Bmp = new Bitmap(Path);

            Width  = Bmp.Width / Frames;
            Height = Bmp.Height;

            Id          = TexUtil.CreateTextureFromBitmap(Bmp);
            this.Frames = Frames;
            Animated    = true;
        }
Esempio n. 5
0
        private void LoadTextures()
        {
            string LoadPath = string.Empty;

            for (int i = 0; i < _Mats.Count; i++)
            {
                if (_Mats[i].map_Ka != null)
                {
                    try
                    {
                        if (GL.IsTexture(_Mats[i].GLID) == true)
                        {
                            GL.DeleteTexture(_Mats[i].GLID);
                        }

                        if (_Mats[i].TexImage != null)
                        {
                            _Mats[i].TexImage.Dispose();
                        }

                        LoadPath = Path.IsPathRooted(_Mats[i].map_Ka) == true ? _Mats[i].map_Ka : _BasePath + _Mats[i].map_Ka;
                        if (ValidImageTypes.IndexOf(Path.GetExtension(LoadPath).ToLowerInvariant()) == -1)
                        {
                            throw new Exception();
                        }

                        _Mats[i].TexImage = new Bitmap(Bitmap.FromFile(LoadPath));
                        _Mats[i].GLID     = TexUtil.CreateTextureFromBitmap(_Mats[i].TexImage);
                        _Mats[i].Width    = _Mats[i].TexImage.Width;
                        _Mats[i].Height   = _Mats[i].TexImage.Height;
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show("Texture image " + LoadPath + " not found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Texture image " + LoadPath + " is in " + Path.GetExtension(LoadPath).ToUpperInvariant().Substring(1) + " format and cannot be loaded!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        continue;
                    }
                }
            }
        }
Esempio n. 6
0
    public static void ProduceEventIcons(Version version, string[][] StringList, bool overwriteOldImage = false)
    {
        if (!overwriteOldImage && EventAtlas[version] != 0)
        {
            return;
        }

        RectangleF rectE = new RectangleF(-16, 0, 64, 32);

        using (SolidBrush white = new SolidBrush(Color.White))
            using (Font arial = new Font(new FontFamily("Arial"), 8))
                using (Bitmap text_bmp = new Bitmap(512, 512))
                    using (Graphics totalgfx = Graphics.FromImage(text_bmp))
                        using (StringFormat formatEvent = new StringFormat())
                        {
                            formatEvent.Alignment = formatEvent.LineAlignment = StringAlignment.Center;
                            totalgfx.Clear(Color.FromArgb(128, 0, 0, 0));
                            for (int i = 1; i < 256; i++)
                            {
                                using (Bitmap single_bmp = new Bitmap(32, 32))
                                    using (Graphics gfx = Graphics.FromImage(single_bmp))
                                    {
                                        if (StringList[i].Length > 4 && StringList[i][4].TrimEnd() != "")
                                        {
                                            gfx.DrawString(StringList[i][3] + "\n" + StringList[i][4], arial, white, rectE, formatEvent);
                                        }
                                        else
                                        {
                                            gfx.DrawString(StringList[i][3], arial, white, rectE, formatEvent);
                                        }
                                        totalgfx.DrawImage(single_bmp, i % 16 * 32, i / 16 * 32);
                                    }
                            }
                            if (EventAtlas[version] != 0)
                            {
                                GL.DeleteTexture(EventAtlas[version]);
                            }
                            EventAtlas[version] = TexUtil.CreateTextureFromBitmap(text_bmp);
                        }
    }
Esempio n. 7
0
    public static void ProduceTypeIcons(Version version, IniFile typeIni, bool overwriteOldImage = false)
    {
        if (!overwriteOldImage && TileTypeAtlas[version] != 0)
        {
            return;
        }

        RectangleF rectT = new RectangleF(-2, 0, 256, 32);

        using (SolidBrush white = new SolidBrush(Color.White))
            using (Font arial = new Font(new FontFamily("Arial"), 8))
                using (Bitmap type_bmp = new Bitmap(128, 128))
                    using (Graphics totalgfx = Graphics.FromImage(type_bmp))
                        using (StringFormat formatType = new StringFormat())
                        {
                            formatType.LineAlignment = StringAlignment.Center;
                            formatType.Alignment     = StringAlignment.Near;
                            totalgfx.Clear(Color.FromArgb(128, 0, 0, 0));
                            TileTypeNames[version] = new string[16];

                            for (int i = 1; i < 16; i++)
                            {
                                if ((TileTypeNames[version][i] = typeIni.IniReadValue("Tiles", i.ToString()) ?? "") != "")
                                {
                                    using (Bitmap single_bmp = new Bitmap(32, 32))
                                        using (Graphics gfx = Graphics.FromImage(single_bmp))
                                        {
                                            gfx.DrawString(typeIni.IniReadValue("Tiles", i.ToString()), arial, white, rectT, formatType);
                                            totalgfx.DrawImage(single_bmp, i % 4 * 32, i / 4 * 32);
                                        }
                                }
                            }
                            if (TileTypeAtlas[version] != 0)
                            {
                                GL.DeleteTexture(TileTypeAtlas[version]);
                            }
                            TileTypeAtlas[version] = TexUtil.CreateTextureFromBitmap(type_bmp);
                        }
    }
Esempio n. 8
0
        /**
         * Dessine le joueur en OpenGl.
         * La position du mur est nécessaire afin de positionner correctement le joueur, qui suit le mur.
         */
        public void draw(double wallPosition)
        {
            wallPosition -= 5;

            if (bitmapSource != null)
            {
                playerTextureId = TexUtil.CreateTextureFromBitmap(Util.GetBitmap(bitmapSource));

                //La silhouette du joueur
                GL.BindTexture(TextureTarget.Texture2D, playerTextureId);
                GL.Begin(BeginMode.Quads);
                GL.TexCoord2(0, 0); GL.Vertex3(-Wall.wallWidth, wallPosition, Wall.wallHeight);
                GL.TexCoord2(1, 0); GL.Vertex3(Wall.wallWidth, wallPosition, Wall.wallHeight);
                GL.TexCoord2(1, 1); GL.Vertex3(Wall.wallWidth, wallPosition, 0);
                GL.TexCoord2(0, 1); GL.Vertex3(-Wall.wallWidth, wallPosition, 0);

                GL.Color3(System.Drawing.Color.White);
                GL.End();

                //Nettoyer la texture du joueur (pour éviter une fuite mémoire)
                GL.DeleteTexture(playerTextureId);
            }
        }
Esempio n. 9
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);  // use the visible framebuffer
            GL.ClearColor(0.5f, 0.5f, 0.55f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
            Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -1 * Vector3.UnitZ, Vector3.UnitY);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref modelview);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(-1, 1, -1, 1, -1, 1.1);


            if (videoFrame != null)
            {
                lock (videoFrame) {
                    if (videoTexture != -1)
                    {
                        GL.DeleteTextures(1, ref videoTexture);
                    }
                    videoTexture = TexUtil.CreateTextureFromBitmap(videoFrame);
                    GL.BindTexture(TextureTarget.Texture2D, videoTexture);
                    videoFrame.Dispose();
                    videoFrame = null;
                }
            }
            GC.Collect();
            fullscreenQuad.Draw();

            SwapBuffers();
        }