简体   繁体   English

OpenGL帧缓冲离屏渲染

[英]OpenGL Framebuffer Offscreen Rendering

I'm doing an SDL/OpenGL project on MinGW Windows Code::Blocks 12.11, using GLEW. 我正在使用GLEW在MinGW Windows Code :: Blocks 12.11上执行SDL / OpenGL项目。 I'm trying to implement 2D off-screen rendering, so that I can eventually try some fragment shader effects. 我正在尝试实现2D屏幕外渲染,以便最终可以尝试一些片段着色器效果。

Here is the scene rendered to the default framebuffer: 这是渲染到默认帧缓冲区的场景:

场景正常

However, if I render the scene to a Framebuffer Object's texture (called fbo_texture) and then try and render that to a full-screen quad, I get this: 但是,如果将场景渲染为帧缓冲区对象的纹理(称为fbo_texture),然后尝试将其渲染为全屏四边形,则会得到以下信息:

带帧缓冲对象的场景

The image appears flipped, mirrored and green. 图像显示为翻转,镜像和绿色。 I'm pretty sure that the rendering to the Framebuffer is working correctly, but for the life of me I can't figure out why the texture is appearing so skewed. 我非常确定帧缓冲区的渲染工作正常,但是对于我一生来说,我无法弄清楚纹理为何如此偏斜。

Here is how I tried to render fbo_texture to a textured quad, after calling glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0). 这是我在调用glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0)之后尝试将fbo_texture渲染为带纹理的四边形的方法。 I am using glMatrixMode(GL_MODELVIEW) and glOrtho(0, screen_width, screen_height, 0, 0, 1) when the program initializes. 程序初始化时,我正在使用glMatrixMode(GL_MODELVIEW)和glOrtho(0,screen_width,screen_height,0,0,1)。 Screen_width is 400 and screen_height is 400. Screen_width是400,screen_height是400。

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, fbo_texture);
glBegin(GL_QUADS);
    x1= 0.5;
    x2= 400.5;
    y1= 0.5;
    y2 = 400.5;
    glTexCoord2f(0.0f, 0.0f); glVertex2f(x1, y1);
    glTexCoord2f(1.0f, 0.0f); glVertex2f(x2, y1);
    glTexCoord2f(0.0f, 1.0f); glVertex2f(x2, y2);
    glTexCoord2f(1.0f, 1.0f); glVertex2f(x1, y2);
glEnd();


glDisable(GL_TEXTURE_2D);

I really appreciate any help, please let me know if I should provide any more information. 非常感谢您的帮助,如果我需要提供更多信息,请告诉我。

This might not be your only problem, but from the part you show, two vertices are swapped in your texture coordinates. 这可能不是您唯一的问题,但是从您显示的部分来看,纹理坐标中交换了两个顶点。 The 3rd of the 4 vertices is the top-right corner, with coordinates (x2, y2) , so it should have texture coordinates (1.0f, 1.0f) : 4个顶点中的第3个是右上角,坐标为(x2, y2) ,因此它应具有纹理坐标(1.0f, 1.0f)

glTexCoord2f(0.0f, 0.0f); glVertex2f(x1, y1);
glTexCoord2f(1.0f, 0.0f); glVertex2f(x2, y1);
glTexCoord2f(1.0f, 1.0f); glVertex2f(x2, y2);
glTexCoord2f(0.0f, 1.0f); glVertex2f(x1, y2);

You're also saying that you call glOrtho() after glMatrixMode(GL_MODELVIEW) . 您还说在glMatrixMode(GL_MODELVIEW)之后调用glOrtho() glMatrixMode(GL_MODELVIEW) glOrtho() sets a projection matrix, so it should normally be called after glMatrixMode(GL_PROJECTION) . glOrtho()设置投影矩阵,因此通常应在glMatrixMode(GL_PROJECTION)之后调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM