Esempio n. 1
0
        public void updateData()
        {
            GL.Enable(EnableCap.Texture2D);
            bind();

            OGL.PixelInternalFormat pif = OGL.PixelInternalFormat.Rgba;
            OGL.PixelFormat         pf  = OGL.PixelFormat.Rgba;
            OGL.PixelType           pt  = OGL.PixelType.UnsignedByte;

            GL.TexImage2D <Byte>(target, 0, pif, myWidth, myHeight, 0, pf, pt, myData);

            unbind();
        }
Esempio n. 2
0
        public Texture(int texWidth, int texHeight, OGL.PixelInternalFormat pif = PixelInternalFormat.Rgba8, PixelData pixels = null, bool generateMipmaps = false)
        {
            target        = TextureTarget.Texture2D;
            myWidth       = texWidth;
            myHeight      = texHeight;
            myPixelFormat = pif;

            GL.GenTextures(1, out myId);
            bind();

            if (pixels != null)
            {
                myData     = pixels.data;
                myDataType = pixels.dataType;
                GL.TexImage2D(target, 0, myPixelFormat, myWidth, myHeight, 0, pixels.pixelFormat, myDataType, myData);
            }
            else
            {
                myData = null;
                OGL.PixelFormat pf;
                findPixelType(myPixelFormat, out pf, out myDataType);
                GL.TexImage2D(target, 0, myPixelFormat, myWidth, myHeight, 0, pf, myDataType, myData);
            }

            GL.TexParameter(target, TextureParameterName.TextureBaseLevel, 0);
            if (generateMipmaps == false)
            {
                GL.TexParameter(target, TextureParameterName.TextureMaxLevel, 0); //needed since no mip maps are created
                setMinMagFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            }

            setWrapping(TextureWrapMode.Repeat, TextureWrapMode.Repeat);

            if (myData == null)
            {
                Info.print("Created empty texture with id: " + myId);
            }
            else
            {
                Info.print("Created user defined texture with id: " + myId);
            }

            if (generateMipmaps)
            {
                createMipMaps();
                setMinMagFilters(TextureMinFilter.LinearMipmapLinear, TextureMagFilter.Linear);
            }

            unbind();
        }
Esempio n. 3
0
        public bool paste(float[] source, Vector2 loc, Vector2 size, OGL.PixelFormat pf)
        {
            if (myId == 0)
            {
                return(false);
            }

            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);

            bind();

            OGL.PixelType pt = OGL.PixelType.Float;
            GL.TexSubImage2D <float>(target, 0, (int)loc.X, (int)loc.Y, (int)size.X, (int)size.Y, pf, pt, source);

            unbind();
            return(true);
        }
Esempio n. 4
0
        public Bitmap loadBitmap(string filename, out OGL.PixelInternalFormat pif, out OGL.PixelFormat pf, out OGL.PixelType pt)
        {
            filename = Path.GetFullPath(filename);
            if (File.Exists(filename) == false)
            {
                throw new Exception("File " + filename + " does not exist");
            }

            Bitmap CurrentBitmap = null;

            try // Exceptions will be thrown if any Problem occurs while working on the file.
            {
                if (Path.GetExtension(filename) == ".pcx")
                {
                    CurrentBitmap = PCX.load(filename);
                }
                else
                {
                    CurrentBitmap = new Bitmap(filename);
                }

                evalBitmap(CurrentBitmap, out pif, out pf, out pt);

                //flip the image since it's backwards from what opengl expects
                if (myFlip == true)
                {
                    CurrentBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }

                return(CurrentBitmap);
            }

            catch (Exception e)
            {
                throw new Exception("Texture Loading Error: Failed to read file " + filename + ": " + e.Message);
            }
        }
Esempio n. 5
0
        public void evalBitmap(Bitmap bm, out OGL.PixelInternalFormat pif, out OGL.PixelFormat pf, out OGL.PixelType pt)
        {
            switch (bm.PixelFormat)
            {
            case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: // misses glColorTable setup
                pif = OGL.PixelInternalFormat.Rgb8;
                pf  = OGL.PixelFormat.ColorIndex;
                pt  = OGL.PixelType.Bitmap;
                break;

            case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555:
            case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: // does not work
                pif      = OGL.PixelInternalFormat.Rgb5A1;
                pf       = OGL.PixelFormat.Bgr;
                pt       = OGL.PixelType.UnsignedShort5551Ext;
                hasAlpha = true;
                break;

            /*  case System.Drawing.Imaging.PixelFormat.Format16bppRgb565:
             *    pif = OGL.PixelInternalFormat.R5G6B5IccSgix;
             *    pf = OGL.PixelFormat.R5G6B5IccSgix;
             *    pt = OGL.PixelType.UnsignedByte;
             *    break;
             */
            case System.Drawing.Imaging.PixelFormat.Format24bppRgb: // works
                pif = OGL.PixelInternalFormat.Rgb8;
                pf  = OGL.PixelFormat.Bgr;
                pt  = OGL.PixelType.UnsignedByte;
                break;

            case System.Drawing.Imaging.PixelFormat.Format32bppRgb:  // has alpha too? wtf?
            case System.Drawing.Imaging.PixelFormat.Canonical:
            case System.Drawing.Imaging.PixelFormat.Format32bppArgb: // works
                pif      = OGL.PixelInternalFormat.Rgba;
                pf       = OGL.PixelFormat.Bgra;
                pt       = OGL.PixelType.UnsignedByte;
                hasAlpha = true;
                break;

            default:
                throw new ArgumentException("ERROR: Unsupported Pixel Format " + bm.PixelFormat);
            }
        }
Esempio n. 6
0
        protected void findPixelType(OGL.PixelInternalFormat pif, out OGL.PixelFormat pf, out OGL.PixelType pt)
        {
            switch (myPixelFormat)
            {
            case PixelInternalFormat.DepthComponent32f:
                pt = PixelType.Float;
                pf = OGL.PixelFormat.DepthComponent;
                break;

            case PixelInternalFormat.DepthComponent:
                pt = PixelType.Float;
                pf = OGL.PixelFormat.DepthComponent;
                break;

            case PixelInternalFormat.R32f:
                pt = PixelType.Float;
                pf = OGL.PixelFormat.Red;
                break;

            case PixelInternalFormat.Rgb32f:
                pt = PixelType.Float;
                pf = OGL.PixelFormat.Rgb;
                break;

            case PixelInternalFormat.Rgba32f:
                pt = PixelType.Float;
                pf = OGL.PixelFormat.Rgba;
                break;

            case PixelInternalFormat.Rgb8:
                pt = PixelType.Byte;
                pf = OGL.PixelFormat.Rgb;
                break;

            case PixelInternalFormat.Rgba8:
                pt = PixelType.Byte;
                pf = OGL.PixelFormat.Rgba;
                break;

            default:
                pt = PixelType.Byte;
                pf = OGL.PixelFormat.Rgba;
                break;
            }
        }