mtwallet's picture

Texture not rendering on quad across various HW platforms.

I happily render a texture onto a quad on the following HW: ATI FirePro V3750 (FireGL)

However, I want to deploy on a low-cost kiosk PC. It's not rendering the quad, but neither is another box here on my bench that has an...

NVidia GeForce 7050 / NVidia nForce 610i (I just updated the driver too, still no luck).

I load the texture using the code below, and I render it in the Paint() method.

****What am I not understanding about HW/SW interplay relating to using textures? Is there a simple fix I am missing? I'm rendering into a GLControl. Do I need to modify the control, or is there something I can do on the texture load or paint below?

static int LoadTexture(System.Drawing.Bitmap bmap)
{

int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id);

Bitmap bmp = new Bitmap(bmap);
BitmapData bmp_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_data.Width, bmp_data.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

bmp.UnlockBits(bmp_data);

// We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
// On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
// mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

return id;
}

public void Paint()
{
if (!_loaded || (_window == null)) // Play nice
return;

_window.MakeCurrent();

OpenTK.Graphics.GL.Clear(OpenTK.Graphics.ClearBufferMask.ColorBufferBit | OpenTK.Graphics.ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.Texture2D);

Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);

OpenTK.Graphics.GL.MatrixMode(OpenTK.Graphics.MatrixMode.Modelview);
OpenTK.Graphics.GL.LoadMatrix(ref modelview);

GL.Begin(BeginMode.Quads);
GL.Color3(Color.White);

// chart boundary...
GL.TexCoord2(0.0f, 0.0f); OpenTK.Graphics.GL.Vertex3(new Vector3(XMIN, -1.0f, -3f));
GL.TexCoord2(1.0f, 0.0f); OpenTK.Graphics.GL.Vertex3(new Vector3(XMAX, -1.0f, -3f));
GL.TexCoord2(1.0f, 1.0f); OpenTK.Graphics.GL.Vertex3(new Vector3(XMAX, 1f, -3f));
GL.TexCoord2(0.0f, 1.0f); OpenTK.Graphics.GL.Vertex3(new Vector3(XMIN, 1f, -3f));
OpenTK.Graphics.GL.End();

_window.SwapBuffers();

}


Comments

Comment viewing options

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

I solved my problem. It looks to be an issue withe the size of the bitmap, so I'm happily rendering textures on quads across platforms now.

Smilinger's picture

Could you describe your solution in more details? I think I have the same problem. Thanks :)

Edit: I've solved the mystery by myself :) Width and height of textures have to be powers of 2.

mtwallet's picture

Try reducing the size of your image via bits-per-pixel, overall memory size of the image.

For example, letss say who have a big png, save it as a gif or something, 16 or 24 bits-per-pixel, and try again.

I'm a bit removed from this problem now, but that was the area I played around in in order to ultimately get my texture to render across platforms.

Smilinger's picture

I've solved the mystery by myself :) Width and height of textures have to be powers of 2.

My textures are really small, but I will remember your trick if I have problems again. Thanks.

mtwallet's picture

Smilinger,
Thanks for posting back. I ran into this problem again, and my memory was foggy. I looked back here and saw your solution, which solved my problem too.