
Texturing Issues
Posted Wednesday, 16 November, 2011 - 19:33 by raiderred inHello all,
I have ran into some issues with texturing my models. I am not getting the expected texturing results and I am not sure if I understand how the coordinate system is working. Currently I am just reading in the obj data from a model I made in Blender and using the texture coordinates from this file to set up the model accordingly. When I run the program, it appears that the texture data is flipped and mirrored on the x-axis.
I am using the example texture loading code from the OpenTK documentation :
public static int LoadTexture(string filename) { if (String.IsNullOrEmpty(filename)) throw new ArgumentException(filename); int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); Bitmap bmp = new Bitmap(filename); 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); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); bmp.UnlockBits(bmp_data); return id; }
and before my drawing code I am just using :
GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D,texture.Id);
the model data i am using is for a simple plane, which is the playing surface:
# Blender v2.60 (sub 0) OBJ File: 'Table.blend' # www.blender.org mtllib PlayArea.mtl o Plane v 5.871777 3.283382 -2.875700 v 5.871777 3.283382 3.542528 v -5.863399 3.283382 3.542528 v -5.863397 3.283382 -2.875701 vt 0.000000 0.000000 vt 1.000000 0.000000 vt 1.000000 1.000000 vt 0.000000 1.000000 vn 0.000000 1.000000 0.000000 usemtl floor.jpg s off f 1/1/1 4/2/1 3/3/1 f 1/1/1 3/3/1 2/4/1
Any pointers in the right direction would be greatly appreciated.
Thanks!


Comments
Re: Texturing Issues
After Bitmap data is loaded, use
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);Or other rotation or/and flip, to solve this problem.