a little help

Started by
2 comments, last by python_regious 19 years, 8 months ago
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()
Advertisement
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.

If at first you don't succeed, redefine success.
thanks a lot, i have been looking for this in a lot of different vb forums, but most vb programmers use DirectX.
Oh, well, I don't know VB at all, just OpenGL.
If at first you don't succeed, redefine success.

This topic is closed to new replies.

Advertisement