Sign in to follow this  
Followers 0
McGrane

OpenGL
glGenTextures

3 posts in this topic

Hi all,

I am currently working on a project using opengl and opencv. 

Heres a snippet of my code (please let me know if more is needed)

 

IplImage* frame = cvQueryFrame( capture );
        
m_currentFrameData = (unsigned char*)frame->imageData;
        
Image->setData( m_currentFrameData );

void cImage::setData( unsigned char* data ) { 
    m_bitmapData = data; 
    this->initialize();
}

void cImage::initialize() {
    glGenTextures( 1, &m_texture );
    glBindTexture( GL_TEXTURE_2D, m_texture );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, m_bitmapInfoHeader.biWidth, m_bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, m_bitmapData );
}

 

Correct me if im wrong, but im generating a new texture for every frame.

What i want to do is delete each old texture when a new one is generated. I looked into glDeleteTextures, but this seems to delete an array of textures ?

Is there a way to delete a single texture ? 

Thanks for any help smile.png

Edited by McGrane
0

Share this post


Link to post
Share on other sites

It works the same way as glGenTextures, just pass 1 and a pointer to the ID.

 

Edit: Although based on the code above, perhaps just glTexSubImage2D or glTexImage2D would be better (or even faster) than creating an entirely new texture every frame?

Edited by beans222
2

Share this post


Link to post
Share on other sites

There's no reason to constantly create and delete. For that matter, the only thing GenTextures does is to return an unused index. You can use it or not, but after you've got a valid texture name you can just BindTexture it and TexSubImage2D to it every frame. See this for more info:

http://www.opengl.org/wiki/Common_Mistakes#Updating_a_texture

But to sum up:

1) GenTextures once

2) TexImage2D once

3) BindTexture and TexSubImage2D every frame

4

Share this post


Link to post
Share on other sites

Ok, works like a charm! Thanks guys. And the problem with glDeleteTextures was solved by passing the address of the texture, so iv now added it to the deconstructor.

Thanks for the help ;)

0

Share this post


Link to post
Share on other sites

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  
Followers 0