예제 #1
0
        public override void Draw(GlTexture T)
        {
            if (T == null || this.CountOfPoints == 0 || !ActivateDrawStart())
            {
                return;
            }

            T.BindTexture();

            ActivateDrawing();

            Gl.glBegin(Gl.GL_POLYGON);
            for (int i = 0; i < this.CountOfPoints; i++)
            {
                if (this[i] != null)
                {
                    Gl.glVertex2f(this[i].X, this[i].Y);
                    Gl.glTexCoord2d((double)this[i].X, (double)this[i].Y);
                }
            }
            Gl.glEnd();

            T.UnbindTexture();

            ActivateDrawed();
        }
예제 #2
0
        public void Ctor_ShouldInstantiateGlTexture_When_CalledWithNoArguments()
        {
            var glTexture = new GlTexture();

            Assert.AreEqual(glTexture.width, 0);
            Assert.AreEqual(glTexture.height, 0);
        }
 public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
 {
     using (var glTexture = new GlTexture())
     {
         Assert.False(glTexture.isDisposed);
     }
 }
 public void Target_ShouldReturnTarget()
 {
     using (var glTexture = new GlTexture())
     {
         Assert.AreEqual(Gl.GL_TEXTURE_2D, glTexture.target);
     }
 }
예제 #5
0
        public override void Draw(GlTexture T)
        {
            if (this.vertexes == null || !ActivateDrawStart())
            {
                return;
            }

            T.BindTexture();

            ActivateDrawing();

            Gl.glBegin(Gl.GL_POLYGON);
            for (int i = 0; i < this.vertexes.Length; i++)
            {
                if (this.vertexes[i] != null)
                {
                    Gl.glVertex2f(this.vertexes[i].X, this.vertexes[i].Y);
                    Gl.glTexCoord2f(this.vertexes[i].X, this.vertexes[i].Y);
                }
            }
            Gl.glEnd();

            T.UnbindTexture();

            ActivateDrawed();
        }
 public void Ctor_ShouldInstantiateGlTexture_When_CalledWithNoArguments()
 {
     using (var glTexture = new GlTexture())
     {
         Assert.AreEqual(0, glTexture.width);
         Assert.AreEqual(0, glTexture.height);
     }
 }
예제 #7
0
        ITexture LoadTextureAsAlpha(string sm3directory, TdfParser.Section terrainsection, string texturesectionname)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.GetInstance().WriteLine(texturename);
            return(GlTexture.FromAlphamapFile(texturename));
        }
        public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
        {
            var glTexture = new GlTexture();

            glTexture.Dispose();

            Assert.True(glTexture.isDisposed);
        }
예제 #9
0
        public void Ctor_ShouldInstantiateGlTexture_When_CalledWithNameAndSize()
        {
            var glTexture = new GlTexture(1, 100, 100);

            Assert.AreEqual(glTexture.name, 1);
            Assert.AreEqual(glTexture.width, 100);
            Assert.AreEqual(glTexture.height, 100);
        }
예제 #10
0
        ITexture LoadTexture(string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.GetInstance().WriteLine(texturename);
            tilesize = texturesection.GetIntValue("tilesize");
            return(GlTexture.FromFile(texturename));
        }
 public static void DisposeIfNotCommon(GlTexture texture)
 {
     if (texture != NULL_WHITE_TEXTURE &&
         texture != NULL_GRAY_TEXTURE &&
         texture != NULL_BLACK_TEXTURE)
     {
         texture.Dispose();
     }
 }
예제 #12
0
 public RenderableS3o( string s3opath )
 {
     g = new GraphicsHelperGl();
     unit = new S3oLoader().LoadS3o(s3opath);
     if (unit.texturename1 == "Spring unit")
     {
        unit.texturename1 = "Default.tga";
        unit.texturename2 = "Default.tga";
     }
     string texturedirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(s3opath)), "unittextures");
     LogFile.GetInstance().WriteLine( texturedirectory + "\\" + unit.texturename1 + "]");
     texture1 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename1);
 }
예제 #13
0
        public RenderableS3o(string s3opath)
        {
            g    = new GraphicsHelperGl();
            unit = new S3oLoader().LoadS3o(s3opath);
            if (unit.texturename1 == "Spring unit")
            {
                unit.texturename1 = "Default.tga";
                unit.texturename2 = "Default.tga";
            }
            string texturedirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(s3opath)), "unittextures");

            LogFile.GetInstance().WriteLine(texturedirectory + "\\" + unit.texturename1 + "]");
            texture1 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename1);
        }
예제 #14
0
        /// <summary>
        /// テクスチャに描画。
        /// 更新されていない場合処理しないので、専用のテクスチャを用意しておいて、
        /// 毎回それを指定すること。
        /// </summary>
        public void Draw(GlTexture tx)
        {
            lock (lockObject)
            {
                Debug.Assert(IsReadyToDraw);
                // ↑これは呼び出し元でチェックしといて、
                // falseなうちは描画しない方がいい。(´ω`)

                if (window != null)
                {
                    Debug.Fail("Movie.SetWindow()されたのにMovie.Draw()が呼ばれた");
                    return;
                }

                // lock
                int p = SDL.SDL_mutexP(mutex); Debug.Assert(p == 0);

                // フラグ操作
                //*
                if (!updateRect.HasValue)
                {
                    // unlock
                    int vv = SDL.SDL_mutexV(mutex); Debug.Assert(vv == 0);
                    return;
                }
                //Rectangle clientRect = updateRect.Value; // 高速化に使えそうな予感もするものの…。
                updateRect = null;

                /*/
                 * if (!updated) {
                 *      // unlock
                 *      int vv = SDL.SDL_mutexV(mutex); Debug.Assert(vv == 0);
                 *      return;
                 * }
                 * updated = false;
                 * //*/

                // テクスチャに描画
                tx.Bind();
                Gl.glTexSubImage2D((uint)tx.TextureType, 0,
                                   0, 0, surface.Width, surface.Height,
                                   surface.Alpha ? Gl.GL_RGBA : Gl.GL_RGB,
                                   Gl.GL_UNSIGNED_BYTE, surface.Pixels);
                tx.Unbind();

                // unlock
                int v = SDL.SDL_mutexV(mutex); Debug.Assert(v == 0);
            }
        }
예제 #15
0
        public override void Draw(GlTexture T)
        {
            if (T == null || !ActivateDrawStart())
            {
                return;
            }

            ActivateDrawing();

            foreach (GlFigure F in this.figuresAmount)
            {
                F.Draw(T);
            }

            ActivateDrawed();
        }
예제 #16
0
        private GlTexture LoadTextureByPath(string path)
        {
            GlTexture texture = new GlTexture();

            texture.LocalOption.Smooth = false;
            YanesdkResult result = texture.Load(path);

            if (result == YanesdkResult.NoError)
            {
                return(texture);
            }
            else
            {
                throw new Exception("画像「" + path + "」を読み込めません><");
            }
        }
예제 #17
0
        public override void Draw(GlTexture T)
        {
            if (this.isNullPoint() || !ActivateDrawStart())
            {
                return;
            }

            T.BindTexture();

            ActivateDrawing();

            Gl.glBegin(Gl.GL_POINTS);
            Gl.glTexCoord2d(this.X, this.Y);
            Gl.glVertex2f(this.X, this.Y);
            Gl.glEnd();

            T.UnbindTexture();

            ActivateDrawed();
        }
예제 #18
0
        public override void Draw(GlTexture T)
        {
            if (!ActivateDrawStart())
            {
                return;
            }

            T.BindTexture();

            ActivateDrawing();

            Gl.glBegin(Gl.GL_LINES);
            Gl.glVertex2f(this.pointOfLine.X - this.DirectVector.deltaX, this.pointOfLine.Y - this.DirectVector.deltaY);
            Gl.glTexCoord2d(this.pointOfLine.X - this.DirectVector.deltaX, this.pointOfLine.Y - this.DirectVector.deltaY);

            Gl.glVertex2f(this.pointOfLine.X + this.DirectVector.deltaX, this.pointOfLine.Y + this.DirectVector.deltaY);
            Gl.glTexCoord2d(this.pointOfLine.X + this.DirectVector.deltaX, this.pointOfLine.Y + this.DirectVector.deltaY);
            Gl.glEnd();

            T.UnbindTexture();

            ActivateDrawed();
        }
예제 #19
0
 public abstract void Draw(GlTexture T);
예제 #20
0
    //  static int count = 0;
    public Unit LoadS3o(string filename)
    {
        //  if (count > 10)
        // {
        //    throw new Exception("");
        //}
        // count++;

        FileStream inStream = new FileStream(filename, FileMode.Open, FileAccess.Read);

        byte[] sdobytes = new byte[inStream.Length];
        inStream.Read(sdobytes, 0, (int)inStream.Length);
        inStream.Seek(0, SeekOrigin.Begin);
        int        offset    = 0;
        _S3OHeader s3oheader = new _S3OHeader();

        s3oheader = (_S3OHeader)ReadBinary(s3oheader, sdobytes, offset);
        DumpBytes(sdobytes, 0, 30);
        LogFile.GetInstance().WriteLine("[" + s3oheader.magic + "] [" + magiccode + "]");
        if (s3oheader.magic.Trim() != magiccode.Trim())
        {
            throw new Exception("Not an s3o file");
        }
        LogFile.GetInstance().WriteLine("Version: " + s3oheader.version);
        Unit unit = new Unit();

        unit.Height = s3oheader.height;
        unit.Mid    = new Vector3(s3oheader.midx, s3oheader.midy, s3oheader.midz);
        unit.Radius = s3oheader.radius;
        LogFile.GetInstance().WriteLine(ReadString(sdobytes, (int)s3oheader.texture1));
        LogFile.GetInstance().WriteLine(ReadString(sdobytes, (int)s3oheader.texture2));
        unit.texturename1 = ReadString(sdobytes, (int)s3oheader.texture1);
        unit.texturename2 = ReadString(sdobytes, (int)s3oheader.texture2);

        if (unit.texturename1 == "Spring unit")
        {
            unit.texturename1 = "Default.JPG";
            unit.texturename2 = "Default.JPG";
        }
        string texturedirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(filename)), "unittextures");
        string texture1filepath = texturedirectory + "\\" + unit.texturename1;
        string texture2filepath = texturedirectory + "\\" + unit.texturename2;

        LogFile.GetInstance().WriteLine(texturedirectory + "\\" + unit.texturename1 + "]");
        //System.Drawing.Bitmap blankbitmap = new System.Drawing.Bitmap(1, 1);
        //blankbitmap.SetPixel(0, 0, System.Drawing.Color.FromArgb(255, 255, 255));
        if (File.Exists(texture1filepath))
        {
            unit.texture1 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename1);
        }
        else
        {
            MapDesigner.MainUI.GetInstance().uiwindow.WarningMessage("Couldnt find texture " + texture1filepath + " , whilst loading " + filename + " . The object may not appear correctly");
            unit.texture1 = new GlTexture(false);
        }
        if (File.Exists(texture2filepath))
        {
            unit.texture2 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename2);
        }
        else
        {
            MapDesigner.MainUI.GetInstance().uiwindow.WarningMessage("Couldnt find texture " + texture2filepath + " , whilst loading " + filename + " . The object may not appear correctly");
            unit.texture2 = new GlTexture(false);
        }

        unit.unitpart = LoadUnitPart(sdobytes, Convert.ToInt32(s3oheader.rootPiece));

        unit.Name = Path.GetFileNameWithoutExtension(filename).ToLower();
        return(unit);
    }
예제 #21
0
 public override void Draw(GlTexture T)
 {
     throw new System.NotImplementedException();
 }
예제 #22
0
        public void isDisposed_ShouldReturnFalse_When_NotDisposedYet()
        {
            var glTexture = new GlTexture();

            Assert.False(glTexture.isDisposed);
        }
예제 #23
0
 /// <summary>
 /// Disposable implementation to free the GL Texture representing the Character once it is no longer needed.
 /// </summary>
 public void Dispose()
 {
     GlTexture?.Dispose();
 }
예제 #24
0
        public void target_ShouldReturnTarget()
        {
            var glTexture = new GlTexture();

            Assert.AreEqual(glTexture.target, Gl.GL_TEXTURE_2D);
        }