ctartamella's picture

Invalid internal pixel format

I have generated a texture using the following:

            m_letterTexture = GL.GenTexture ();
            GL.BindTexture (TextureTarget.Texture2D, m_letterTexture);
 
            Bitmap bmp = new Bitmap (10 * m_descriptors.Count, 14, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage (bmp);
 
            g.Clear (Color.Transparent);
            //g.InterpolationMode = InterpolationMode.High;
            //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            foreach (CellDescriptor desc in m_descriptors)
                {
                string letter = Convert.ToString(desc.Abbreviation);
                Font font = new Font("Segoe UI", 9);
                Brush brush = new SolidBrush(desc.Color);
                PointF point = new PointF (10.0f * desc.Index, 0.0f);
 
                g.DrawString (letter, font, brush, point);
                }
            g.Dispose ();
 
            BitmapData 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.Width, bmp.Height, 
                0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.Byte, data.Scan0);
            ErrorCode err = GL.GetError ();
            MessageBox.Show (err.ToString ());
            bmp.UnlockBits (data);
 
            GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

Essentially this takes a series of characters and spaces them out on a long, single line height texture. The texture is correct. (I dumped it to disk to confirm.) However, when I debug via gDebugger I am told that the internal pixel format that I used is invalid. GL.GetError() returns no error. The texture as I view it on the texture unit is a solid lime green but has the correct dimensions. Any idea what I might be doing wrong? Any advice would be appreciated.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mOfl's picture

I have two suggestions:
- Use PixelType.UnsignedByte instead of PixelType.Byte.
- Use PixelInternalFormat.Rgba8 instead of PixelInternalFormat.Rgba, it should be the same, but if you specify it clearly, you are on the safe side. This should not have anything to do with your error though.