I am trying to teach myself OpenGL and and looking to reuse opengl textures. What I would like to do is load a video and then bind each of the video frame to a texture and just show it in an opengl window. I know there is a Pixel Buffer Object which might be more appropriate but the idea for me is to learn OpenGL.
So, I wrote a simple C++ texture class as follows:
class Texture
{
public:
Texture(GLenum target=GL_TEXTURE_2D);
~Texture();
void load(int rows, int cols, uchar * data);
protected:
GLenum _texture_target;
GLuint _texture_obj;
};
The implementation is as follows:
Texture::Texture(GLenum target)
{
_texture_target = target;
glGenTextures(1, &_texture_obj);
}
void Texture::load(int rows, int cols, uchar * data)
{
glBindTexture(_texture_target, _texture_obj);
glTexImage2D(_texture_target, 0, GL_BGRA, cols, rows, 0,
GL_BGRA, GL_UNSIGNED_BYTE, data);
glTexParameterf(_texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(_texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
My question is that as I get subsequent video frames, can I make calls to my load() function with the new frame data and will this reuse the texture object correctly? Is this the preferred way to do this using textures or should I delete this texture with glDeleteTextures and generate new texture everytime?