a little help
i am using OpenGL in an application i am making. I am using visual basic .net and am having a little bit of trouble becuase the NeHe tutorials are written in C++. The problem i am having is trying to load multiple textures. When i try and use a loop or somthing it overwrites the first texture and makes a blank second one. Here is the code i am using to load a single texture:
Dim texture(50) as UInt32
Dim Image As Bitmap = New Bitmap("\myimage.bmp")
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, texture)
GL.glBindTexture(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), texture(0))
GL.glTexImage2D(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), 0, Convert.ToInt32(GLFlags.GL_RGB8), _
Image.Width, Image.Height, 0, Convert.ToUInt32(32992), _
Convert.ToUInt32(GLFlags.GL_UNSIGNED_BYTE), bitmapdata.Scan0)
GL.glTexParameteri(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), Convert.ToUInt32(GLFlags.GL_TEXTURE_MIN_FILTER), Convert.ToUInt32(9729))
GL.glTexParameteri(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), Convert.ToUInt32(GLFlags.GL_TEXTURE_MAG_FILTER), Convert.ToUInt32(9729))
Image.UnlockBits(bitmapdata)
Image.Dispose()
When you use glGenTextures you're constantly overwriting the first element of the Texture array. Replace it with
GL.glGenTextures(50, texture)
which will fill the array with texture id's that you can use.
You'll obviously have to bind to a different id when you load another texture, so
GL.glBindTexture(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), texture(1))
or something to load the second texture.
GL.glGenTextures(50, texture)
which will fill the array with texture id's that you can use.
You'll obviously have to bind to a different id when you load another texture, so
GL.glBindTexture(Convert.ToUInt32(GLFlags.GL_TEXTURE_2D), texture(1))
or something to load the second texture.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement