glGenTextures

Started by
2 comments, last by McGrane 11 years, 2 months ago

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

Advertisement

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?

New C/C++ Build Tool 'Stir' (doesn't just generate Makefiles, it does the build): https://github.com/space222/stir

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

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

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

This topic is closed to new replies.

Advertisement