Bicubic's picture

"Invalid value" when loading texture

Hi all, I'm getting started with OpenTK and keep getting an error when trying to load a texture.
The code is pretty much copy pasted from an example:

BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
    ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
 
 
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
    OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
 
bitmap.UnlockBits(data);

On my desktop, it works fine and I get a valid texture. On my netbook, it crashes at the second last line and gives me an "Invalid Value" which seems to point to "PixelType.UnsignedByte".
I think the issue may be that the netbook's graphics card doesn't support mip mapping on non power-of-2 textures as is the case with the one I'm loading. How do I tell it not to generate mipmaps if that's the issue, or what else can it be?

Kind Regards.


Comments

Comment viewing options

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

Mipmaps won't be generated unless you request for them explicitly via GL.GenerateMipmap, GL.Ext.GenerateMipmap or GL.TextureParameter(..., GenerateMipmaps).

In my experience, these are the most common "invalid value" issues when loading textures:

  1. Card does not support NPOT textures.
  2. Texture dimensions exceed the card's limits.
  3. PixelInternalFormat is not supported by the card.

NPOT is always support if GL.GetString(StringName.Version) returns 2.1 or higher (or was it 2.0?) You can query max texture size via GL.GetInteger. Finally PixelInternalFormat.Rgba is always supported on version 1.1 and higher.

Bicubic's picture

Hrm. I loaded a larger power of 2 texture and it worked fine with no changes to code. I think this rules out 2 and 3.
I do know that the card supports non power of 2 textures as long as there are no mip maps. I found out when I had my d3d app crash on the netbook and after googling my card's specs, ended up disabling the generation of mipmaps to resolve the issue.

What else could I be missing, or could this be a bug in OpenTK?

the Fiddler's picture

Intel netbook, I presume 945 or 950-based? I've had pretty bad experience with this combination (blue screens in OpenGL apps like World of Goo and generally bad OpenGL support). A quick google search found this: http://stackoverflow.com/questions/1840447/emulate-big-npot-textures-for...

Quote:

An example of a problematic videocard is the Mobile Intel® 945GM Express Chipset which doesn't seem to support native NPOT.

I think that the hardware *does* support NPOT, but the Windows drivers simply don't expose this (AFAIK, D3D and Linux OpenGL drivers can do NPOT). Try upgrading your drivers if at all possible.

OpenTK itself doesn't touch the data you pass in any way, so that cannot be the cause - at least not in this case. (Think of it as the equivalent of the "gl.h" header for C# applications).

Bicubic's picture

Ah, I remembered hearing somewhere that the only way non power of 2 textures will load with opengl in this situation is GL_TEXTURE_RECTANGLE.
I think I'll just pad my textures up to powers of 2 and call it a day.

Thanks for clearing this up.