1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
////////////////////////////////////////////////////////////
RenderTexture::RenderTexture()
{
myTexture = NULL;
}
////////////////////////////////////////////////////////////
RenderTexture::~RenderTexture()
{
glDeleteFramebuffers(1, &myFramebuffer);
delete myTexture;
}
////////////////////////////////////////////////////////////
void RenderTexture::create( int width, int height )
{
// Création de la texture
myTexture = new Texture();
myTexture->setSize( width, height );
// 1 - Texture
glBindTexture(GL_TEXTURE_2D, myTexture->getId());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// 2 - FBO
glGenFramebuffers(1, &myFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, myFramebuffer);
// 3 - Attache la texture au FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, myTexture->getId(), 0);
// 4 - Une erreur s'est produite ?
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER) ;
if(status != GL_FRAMEBUFFER_COMPLETE) {
Log::getInstance()->add(Log::ERROR, "Erreur lors de la création du framebuffer");
} else {
Log::getInstance()->add(Log::ERROR, "FrameBuffer : OK");
}
// 5 - On desactive le FBO
glBindFramebuffer( GL_FRAMEBUFFER, 0);
}
////////////////////////////////////////////////////////////
void RenderTexture::start()
{
glBindFramebuffer(GL_FRAMEBUFFER, myFramebuffer);
}
////////////////////////////////////////////////////////////
void RenderTexture::finish()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void RenderTexture::bind()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture( GL_TEXTURE_2D, myTexture->getId() );
} |
Partager