我尝试在更大的四边形上渲染一个小四边形,但它似乎不起作用。它使两个四边形呈现一个小的洋红色四边形和一个大的白色四边形,上面有一条线,彼此相邻,而不是一个在另一个上面。
glEnable( GL_TEXTURE );
glEnable( GL_TEXTURE_2D );
float *data = new float[ 756 * 756 * 3 ];
for( int i = 0 ; i < 756 ; i++ )
for( int j = 0 ; j < 756 ; j++ )
if( i == j )
for( int k = 0; k < 3 ; k++ )
data[i * 756 * 3 + j * 3 + k] = 0.0f;
else
for( int k = 0; k < 3 ; k++ )
data[ i * 756 * 3 + j * 3 + k ] = 1.0f;
GLuint Texture;
GLuint FrameBufferObject;
glGenTextures( 1 , &Texture );
glBindTexture( GL_TEXTURE_2D , Texture );
glTexImage2D( GL_TEXTURE_2D , 0 , 3 , 756 , 756 , 0 , GL_RGB , GL_FLOAT , data );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture( GL_TEXTURE_2D , 0 );
glewInit();
glGenFramebuffers( 1 , &FrameBufferObject );
glBindFramebuffer( GL_DRAW_FRAMEBUFFER , FrameBufferObject );
glBindTexture( GL_TEXTURE_2D , Texture );
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Texture, 0);
//GLuint atchements[] = { GL_COLOR_ATTACHMENT0 };
//glDrawBuffers( 1 , atchements );
GLenum e = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
if (e != GL_FRAMEBUFFER_COMPLETE)
cout << " MASIVE ERROR, ABORT ! " << endl;
glBindFramebuffer( GL_DRAW_FRAMEBUFFER , 0 );
/* program main loop */
while (!bQuit)
{
/* check for messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
/* OpenGL animation code goes here */
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glRotatef(theta, 0.0f, 0.0f, 1.0f);
glBindTexture( GL_TEXTURE_2D , 0 );
glBindFramebuffer( GL_DRAW_BUFFER , FrameBufferObject );
//GLuint atchements[] = { GL_COLOR_ATTACHMENT0 };
//glDrawBuffers( 1 , atchements );
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture( GL_TEXTURE_2D , 0 );
glBegin(GL_QUADS);
glColor3f( 1 , 0 , 1 );
glVertex2f( 0 , 0 );
glVertex2f( 0 , .1 );
glVertex2f( .1 , .1 );
glVertex2f( .1 , 0 );
glColor3f( 1 , 1 , 1 );
glEnd();
glBindFramebuffer( GL_DRAW_BUFFER , 0 );
glScalef( 0.5 , .5 , .5 );
glTranslatef( 0 , 0.3 , 0 );
glBindTexture( GL_TEXTURE_2D , Texture );
glBegin(GL_QUADS);
glTexCoord2f( 0 , 0 );
glVertex2f( 0 , 0 );
glTexCoord2f( 0 , 1 );
glVertex2f( 0 , 1 );
glTexCoord2f( 1 , 1 );
glVertex2f( 1 , 1 );
glTexCoord2f( 1 , 0 );
glVertex2f( 1 , 0 );
glEnd();
glPopMatrix();
SwapBuffers(hDC);
theta += 1.0f;
Sleep (1);
}
}
答案 0 :(得分:0)
您的代码存在许多问题,但我认为主要问题是您没有正确使用GL_READ_FRAMEBUFFER
。这是 not 从您渲染的纹理中读取,而只是glBlitFramebuffer()
的源操作数。这完全不相关。
您目前在主循环中正在做什么:
Texture
步骤4和6组合创建了无效的反馈循环,因为此时您仍然会渲染到Texture
。你永远不会渲染到屏幕上,所以你根本不应该看到任何东西。事实上,你实际上看到的东西除了黑屏之外意味着我忽略了其他一些错误,因为你不应该这样做。 (编辑:OP注意到他最初写的是glBindFramebuffer(GL_DRAW_BUFFER,...)
而不是GL_DRAW_FRAMEBUFFER
,现在完全解释了观察到的行为。)
您可能希望glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0)
代替第4步和第5步,再次渲染到默认的帧缓冲区。
其他一些问题: