Evinyl's picture

Textures too dark

Hello everyone,

I'm currently working on a music visualizer c# app with OpenGL visualizations. I added texturing support to my program, but the loaded texture is a different color than the PNG file.
My texture loading code is

public static bool LoadOpenglTexture(out int Texture)
            var _Name = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Visualizer", "texture.png");
            if (System.IO.File.Exists(_Name))
                Bitmap TextureBitmap = new Bitmap(_Name);
                System.Drawing.Imaging.BitmapData TextureData =
                TextureBitmap.LockBits(new System.Drawing.Rectangle(0, 0, TextureBitmap.Width, TextureBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                OpenTK.Graphics.OpenGL.GL.GenTextures(1, out Texture);
                OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, Texture);
                OpenTK.Graphics.OpenGL.GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, TextureData.Width, TextureData.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, TextureData.Scan0);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                return true;
                Texture = -1;
                return false;

The drawing code I use is

                GL.BindTexture(TextureTarget.Texture2D, Texture);
                GL.TexCoord2(1.0, 0.0);
                GL.Vertex2(0.0, lVolBottom);
                GL.TexCoord2(0.0, 0.0);
                GL.Vertex2(0.0, Height);
                GL.TexCoord2(0.0, 1.0);
                GL.Vertex2(lVolWidth, Height);
                GL.TexCoord2(1.0, 1.0);
                GL.Vertex2(lVolWidth, lVolBottom);
                GL.Color3(fFromColor[2], fFromColor[1], fFromColor[0]);
                GL.Vertex2(0.0, 0.0);
                GL.Color3(fFromColor[2], fFromColor[1], fFromColor[0]);
                GL.Vertex2(0.0, rVolTop);
                GL.Color3(fToColor[2], fToColor[1], fToColor[0]);
                GL.Vertex2(rVolWidth, rVolTop);
                GL.Color3(fToColor[2], fToColor[1], fToColor[0]);
                GL.Vertex2(rVolWidth, 0.0);
                GL.Vertex2(lVolPeak, Height);
                GL.Vertex2(lVolPeak, lVolBottom);
                GL.Vertex2(rVolPeak, rVolTop);
                GL.Vertex2(rVolPeak, 0.0);

A screenshot of the VU meter visualization:

The lower bar is the GL.Color(1.0,0.0,0.0) bar, and the upper bar is the solid red textured bar. The textured bar's RGB shows up as 119,14,18 in photoshop. Any idea why the texture color isn't solid red?


Comment viewing options

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

Some blending enabled?

Evinyl's picture

I fixed it by calling gl.Color(1f,1f,1f,1f) before drawing the quad. Not sure what the proper way of fixing it is though.

tomriddle's picture

Ahh this is cool. Mind sharing the code that generates that waveform? ;D
I'm a Web Developer who does Web Deisgn so I'd like to use this for one of my projects.