Beispiel #1
0
        private void UploadTex(mat1.MaterialEntry.TexMap TexMap, CLIM Texture, int Id)
        {
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
            Gl.glColor3f(1, 1, 1);
            Bitmap b = Texture.ToBitmap();
            //b.RotateFlip(RotateFlipType.RotateNoneFlipY);
            BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
            b.UnlockBits(d);

            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, (TexMap.MagFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, (TexMap.MinFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);

            switch (TexMap.WrapS)
            {
            case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT);
                break;

            default:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
                break;
            }

            switch (TexMap.WrapT)
            {
            case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT);
                break;

            default:
                Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
                break;
            }
        }
        private void UploadTex(mat1.MaterialEntry.TexMap TexMap, CLIM Texture, int Id)
        {
            GL.BindTexture(TextureTarget.Texture2D, Id);
            GL.Color3(1, 1, 1);
            Bitmap b = Texture.ToBitmap();
            //b.RotateFlip(RotateFlipType.RotateNoneFlipY);
            BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, b.Width, b.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, d.Scan0);
            b.UnlockBits(d);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (TexMap.MagFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? (int)TextureMagFilter.Linear : (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (TexMap.MinFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? (int)TextureMinFilter.Linear : (int)TextureMinFilter.Nearest);

            switch (TexMap.WrapS)
            {
            case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.MirroredRepeat);
                break;

            default:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                break;
            }

            switch (TexMap.WrapT)
            {
            case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                break;

            case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.MirroredRepeat);
                break;

            default:
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
                break;
            }
        }
Beispiel #3
0
 private void CLIMViewer_Load(object sender, EventArgs e)
 {
     pictureBox1.Image = Image.ToBitmap();
 }
        private void UploadTex(mat1.MaterialEntry.TexMap TexMap, CLIM Texture, int Id)
        {
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
            Gl.glColor3f(1, 1, 1);
            Bitmap b = Texture.ToBitmap();
            //b.RotateFlip(RotateFlipType.RotateNoneFlipY);
            BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
            b.UnlockBits(d);

            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, (TexMap.MagFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, (TexMap.MinFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);

            switch (TexMap.WrapS)
            {
                case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
                    break;
                case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
                    break;
                case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT);
                    break;
                default:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
                    break;
            }

            switch (TexMap.WrapT)
            {
                case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
                    break;
                case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
                    break;
                case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT);
                    break;
                default:
                    Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
                    break;
            }
        }