Jump to content

  • Log In with Google      Sign In   
  • Create Account

glGenTextures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 McGrane   Members   -  Reputation: 1194

Like
0Likes
Like

Posted 11 February 2013 - 07:57 PM

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, 11 February 2013 - 08:01 PM.


Sponsor:

#2 beans222   Members   -  Reputation: 1169

Like
2Likes
Like

Posted 11 February 2013 - 09:27 PM

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, 11 February 2013 - 09:30 PM.

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

 


#3 Promit   Moderators   -  Reputation: 7587

Like
4Likes
Like

Posted 11 February 2013 - 09:42 PM

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 McGrane   Members   -  Reputation: 1194

Like
0Likes
Like

Posted 12 February 2013 - 04:14 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS