Loading a new texture into an already defined texture name
I have an OpenGl program in which I display an image using textures. I want to be able to upload a new image to display.
In my Init function, I call:
Gl.glGenTextures(1, mTextures);
Since only one image will be displayed at the time of rendering, I use the same texture name for each image.
Every time a new image is loaded, I call the following:
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mTexture[0]);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_LUMINANCE, mTexSizeX, mTexSizeY, 0, Gl.GL_LUMINANCE, Gl.GL_UNSIGNED_SHORT, mTexBuffer);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
The first image will display as expected. However, all images are loaded after the first, displayed as all black.
What am I doing wrong?
source to share
When do you submit geometry with these textures? I am assuming it alternates with loading the texture, although you don't show it. Of course, if you're going to replace the texture name with different images, you don't need to use texture names at all, right? You can simply make a call glTextImage2D
whenever you need to set a new texture and then use it for as long as needed, never including glBindTexture()
at all.
It would be obvious, of course, to insert error checking code, OpenGL stores an error code when an operation fails, and this code is not overwritten until read by the application. See glGetError () for details .
source to share