Exemple #1
0
		//------------------------------------------------------------------------------------------------------------------------
		//														GetInstance()
		//------------------------------------------------------------------------------------------------------------------------
		public static Texture2D GetInstance (string filename) {
			Texture2D tex2d = LoadCache[filename] as Texture2D;
			if (tex2d == null) {
				tex2d = new Texture2D(filename);
				LoadCache[filename] = tex2d;
			}
			tex2d.count ++;
			return tex2d;
		}
Exemple #2
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        initializeFromTexture()
 //------------------------------------------------------------------------------------------------------------------------
 protected void initializeFromTexture(Texture2D texture)
 {
     _texture = texture;
     _bounds = new Rectangle(0, 0, _texture.width, _texture.height);
     setUVs();
 }
Exemple #3
0
        //------------------------------------------------------------------------------------------------------------------------
        //                                                        CreateGLTexture()
        //------------------------------------------------------------------------------------------------------------------------
        private void CreateGLTexture()
        {
            if (_glTexture != null)
                if (_glTexture.Length > 0)
                    if (_glTexture[0] != UNDEFINED_GLTEXTURE)
                        destroyGLTexture();

            _glTexture = new int[1];
            if (_bitmap == null)
                _bitmap = new Bitmap(64, 64);

            GL.GenTextures(1, _glTexture);

            GL.BindTexture(GL.TEXTURE_2D, _glTexture[0]);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR);//GL.NEAREST);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.LINEAR);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE_EXT);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE_EXT);

            UpdateGLTexture();
            GL.BindTexture(GL.TEXTURE_2D, 0);
            lastBound = null;
        }
Exemple #4
0
        //------------------------------------------------------------------------------------------------------------------------
        //                                                        UpdateGLTexture()
        //------------------------------------------------------------------------------------------------------------------------
        public void UpdateGLTexture()
        {
            BitmapData data = _bitmap.LockBits(new System.Drawing.Rectangle(0, 0, _bitmap.Width, _bitmap.Height),
                                                 ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.BindTexture(GL.TEXTURE_2D, _glTexture[0]);
            GL.TexImage2D(GL.TEXTURE_2D, 0, GL.RGBA, _bitmap.Width, _bitmap.Height, 0,
                          GL.BGRA, GL.UNSIGNED_BYTE, data.Scan0);

            _bitmap.UnlockBits(data);
            lastBound = null;
        }
Exemple #5
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        Clone()
 //------------------------------------------------------------------------------------------------------------------------
 public Texture2D Clone(bool deepCopy = false)
 {
     Bitmap bitmap;
     if (deepCopy)
     {
         bitmap = _bitmap.Clone() as Bitmap;
     }
     else
     {
         bitmap = _bitmap;
     }
     Texture2D newTexture = new Texture2D(0, 0);
     newTexture.SetBitmap(bitmap);
     return newTexture;
 }
Exemple #6
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        Bind()
 //------------------------------------------------------------------------------------------------------------------------
 public void Bind()
 {
     if (lastBound == this) return;
     lastBound = this;
     GL.BindTexture(GL.TEXTURE_2D, _glTexture[0]);
 }