Another Texture Mapping Question
Hello wise ones....
I am having trouble texturing a bitmap image from a file onto a rectangular surface. I am using Tao Framework, VB.NET and Visual Studio 2008.
Here's my code :
Step 1: Generate texture data
Dim Image As Bitmap = New Bitmap("c:\test.jpg")
Image.RotateFlip(RotateFlipType.RotateNoneFlipY)
Dim bitmapdata As System.Drawing.Imaging.BitmapData
Dim rect As Rectangle = New Rectangle(0, 0, Image.Width, Image.Height)
bitmapdata = Image.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadOnly, Drawing.Imaging.PixelFormat.Format24bppRgb)
Gl.glGenTextures(1, textureID)
Gl.glBindTexture(Gl.GL_TEXTURE_2D, textureID(0))
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, Gl.GL_RGB8, 3, Image.Width, Image.Height, 0, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, bitmapdata.Scan0)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
Image.UnlockBits(bitmapdata)
Image.Dispose()
Step 2: In the Render routine (the vertices form a simple cube)
Gl.glEnable(Gl.GL_TEXTURE_2D)
Gl.glBindTexture(Gl.GL_TEXTURE_2D, textureID(0))
Gl.glBegin(Gl.GL_TRIANGLES)
For j = 0 To v1.Length / 3 - 1
Gl.glTexCoord2f((v1(3 * j) - BB.MinPoint.X) / Me.Width, (v1(3 * j + 2) - BB.MinPoint.Z) / Me.Depth)
Gl.glVertex3f(v1(3 * j), v1(3 * j + 1), -v1(3 * j + 2))
Next
Gl.glEnd()
Gl.glDisable(Gl.GL_TEXTURE_2D)
When I execute the code, I simply get a light gray surface and not the image in the jpg file.
Am I missing anything obvious?
Thanks for any help,
Siva

You're loading it into the
You're loading it into the 3rd mipmap level, not the base level (0). (the 3 before Image.Width in your glTexImage2D call)
----------------------
Download Tao svn snapshot build
Experimental Tao rpms (OpenSUSE Build Service)
Thanks SeaEagle, I did try
Thanks SeaEagle,
I did try various combinations to force it to work, and the following line works on machines with OpenGL > 1.5.
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB8, Image.Width, Image.Height, 0, 32992, Gl.GL_UNSIGNED_BYTE, bitmapdata.Scan0)
My laptop video driver uses ARB extensions and it doesn't display the texture on it. Does anyone know which portions of the code above is dependent on the type of OpenGL implementation, and which numbers should I be changing to get it to work with ARB extensions?
Thanks again.
Siva
Try the Gl Extensions viewer
Try the Gl Extensions viewer to find out what your laptop supports. I suspect it has something to with the format (RGB / BGR etc.).
----------------------
Download Tao svn snapshot build
Experimental Tao rpms (OpenSUSE Build Service)
Make sure the image size is
Make sure the image size is power of 2. If it is not in power of 2 (in both width and height), then, texture does not appear properly.