Sign in to follow this  

a little help

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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()

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this