Beispiel #1
0
        public void cache(ref List<Texture> mList)
        {
            if (type != Type.fromFramebuffer)
            {
                Texture tmpTex = new Texture();

                tmpTex.name = name;
                tmpTex.cacheBitmap = cacheBitmap;
                tmpTex.multisampling = multisampling;

                mList.Add(tmpTex);
            }
        }
        public void fromFile(string file,bool sampling)
        {
            string name = file.Replace(gameWindow.materialFolder, "");

            if (!TextureNames.ContainsKey(name))
            {
                Texture curTexture = new Texture();

                curTexture.identifier = Textures.Count;
                curTexture.type = Texture.TYPE_FROMFILE;
                curTexture.loaded = false;
                curTexture.pointer = file;
                curTexture.name = name;
                curTexture.multisampling = sampling;

                registerTexture(curTexture);

            }
        }
Beispiel #3
0
 public void setTexture(TexType type, Texture texture)
 {
     textures[(int)type] = texture;
 }
        public void fromFramebuffer(string name,int texture)
        {
            Texture curTexture = new Texture();

            curTexture.identifier = Textures.Count;
            curTexture.type = Texture.TYPE_FRAMEBUFFER;
            curTexture.loaded = true;
            curTexture.texture = texture;
            curTexture.name = name;

            registerTexture(curTexture);
        }
        public void registerTexture(Texture curTex)
        {
            if(TextureNames.ContainsKey(curTex.name))
                    TextureNames.Remove(curTex.name);

            TextureNames.Add(curTex.name, curTex.identifier);
            Textures.Add(curTex);
        }
        public void loadTexture(Texture target)
        {
            if (target.type == Texture.TYPE_FROMFILE)
            {
                if (String.IsNullOrEmpty(target.pointer))
                    throw new ArgumentException(target.pointer);

                target.texture = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, target.texture);

                Bitmap bmp = new Bitmap(target.pointer);
                BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                    OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

                bmp.UnlockBits(bmp_data);

                int sampling = 0;
                if (target.multisampling)
                {
                    sampling = (int)TextureMinFilter.Linear;
                }
                else
                {
                    sampling = (int)TextureMinFilter.Nearest;
                }

                // We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
                // On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
                // mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.

                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            }

            target.loaded = true;

            Textures[target.identifier] = target;
        }
Beispiel #7
0
        internal Texture nameOnly()
        {
            Texture tmpTexture = new Texture();

            tmpTexture.name = name;

            return tmpTexture;
        }
Beispiel #8
0
        private void loadTextureFromDds(Texture target)
        {
            GL.Enable(EnableCap.Texture2D);

            uint ImageTextureHandle;
            TextureTarget ImageTextureTarget;

            DDSLoader.LoadFromDisk(target.pointer, out ImageTextureHandle, out ImageTextureTarget);

                // load succeeded, Texture can be used.
                GL.BindTexture(ImageTextureTarget, ImageTextureHandle);
            GL.TexParameter(ImageTextureTarget, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            int[] MipMapCount = new int[1];
            GL.GetTexParameter(ImageTextureTarget, GetTextureParameter.TextureMaxLevel, out MipMapCount[0]);
            if (MipMapCount[0] == 0) // if no MipMaps are present, use linear Filter
                GL.TexParameter(ImageTextureTarget, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            else // MipMaps are present, use trilinear Filter
                GL.TexParameter(ImageTextureTarget, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

            target.texture = (int)ImageTextureHandle;
            target.loaded = true;

            textures[target.identifier] = target;
        }
Beispiel #9
0
 public void loadTexture(Texture target)
 {
     switch (target.type)
     {
         case Texture.Type.fromPng:
             loadTextureFromPng(target);
             break;
         case Texture.Type.fromDds:
             loadTextureFromDds(target);
             break;
         default:
             break;
     }
 }
Beispiel #10
0
        public void fromDds(string file)
        {
            string name = file.Replace(gameWindow.materialFolder, "");

            if (!textureNames.ContainsKey(name))
            {
                Texture curTexture = new Texture();

                curTexture.identifier = textures.Count;
                curTexture.type = Texture.Type.fromDds;
                curTexture.loaded = false;
                curTexture.pointer = file;
                curTexture.name = name;

                registerTexture(curTexture);
            }
        }