Home > Software engineering >  Turn to for help. Incomplete when opengl create frame buffer
Turn to for help. Incomplete when opengl create frame buffer

Time:09-15

Recently in learning opengl frame buffer, in the MFC framework viewport onCreate function with the following the init function to create frame buffer, the results have been return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT inspection function, consult everybody what went wrong is a great god
# include "stdafx. H"
# include "PickingEntity. H"
# include "IO. H"


PickingEntity: : PickingEntity ()
{
}


PickingEntity: : ~ PickingEntity ()
{
}

Bool PickingEntity: : Init (unsigned int WindowWidth, unsigned int WindowHeight)
{
//Create the FBO
GlGenFramebuffers (1, & amp; M_fbo);
GlBindFramebuffer (GL_FRAMEBUFFER m_fbo);
//Create the texture object for the primitive information buffer
GlGenTextures (1, & amp; M_pickingTexture);
GlBindTexture (GL_TEXTURE_2D m_pickingTexture);
GlTexImage2D (GL_TEXTURE_2D, 0, GL_RGB32UI WindowWidth, WindowHeight,
0, GL_RGB_INTEGER, GL_UNSIGNED_INT, NULL);
GlFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 GL_TEXTURE_2D,
M_pickingTexture, 0);
//Create the texture object for the depth buffer
GlGenTextures (1, & amp; M_depthTexture);
GlBindTexture (GL_TEXTURE_2D m_depthTexture);
GlTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT WindowWidth, WindowHeight,
0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
GlFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT GL_TEXTURE_2D,
M_depthTexture, 0);
//Disable reading to get the problems with older GPUs
GlReadBuffer (GL_NONE);
//Verify that the FBO is correct
GLenum Status=glCheckFramebufferStatus (GL_FRAMEBUFFER);
If (Status==GL_FRAMEBUFFER_COMPLETE) {
//printf (" FB error, status: 0 x % x \ n ", status);
GL_FRAMEBUFFER_COMPLETE ioMessage (" ");
//ioMessage (Status);
return false;
}
Else if (Status==GL_FRAMEBUFFER_UNDEFINED)
{
GL_FRAMEBUFFER_UNDEFINED ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
{
GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
{
GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER)
{
GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER)
{
GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_UNSUPPORTED)
{
GL_FRAMEBUFFER_UNSUPPORTED ioMessage (" ");
}
Else if (Status==GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE)
{
GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE ioMessage (" ");
}
The else
{
UNKNOW_MISTAKE ioMessage (" ");
}
//Restore the default framebuffer
GlBindTexture (GL_TEXTURE_2D, 0);
GlBindFramebuffer (GL_FRAMEBUFFER GL_NONE);
//return GLCheckError ();
return true;
}

Void PickingEntity: : EnableWriting ()
{
GlBindFramebuffer (GL_DRAW_FRAMEBUFFER m_fbo);
}

Void PickingEntity: : DisableWriting ()
{
GlBindFramebuffer (GL_DRAW_FRAMEBUFFER GL_NONE);
}

PickingEntity: : PixelInfo PickingEntity: : ReadPixel (unsigned int x, unsigned int y)
{
GlBindFramebuffer (GL_READ_FRAMEBUFFER m_fbo);
GlReadBuffer (GL_COLOR_ATTACHMENT0);
PixelInfo Pixel;
GlReadPixels (x, y, 1, 1, GL_RGB_INTEGER, GL_UNSIGNED_INT, & amp; Pixel);
GlReadBuffer (GL_NONE);
GlBindFramebuffer (GL_READ_FRAMEBUFFER GL_NONE);
Return Pixel;
}
  • Related