绘制纹理不起作用LWJGL
我正在尝试绘制2d纹理,并在3D场景中绘制该纹理。
初始化帧缓冲区对象和纹理的代码:
public static void initFBO()
{
renderEngine.framebuffers = new int[7];
renderEngine.monitorTextures = new int[7];
for(int i = 0;i < 7;i++)
{
renderEngine.framebuffers[i] = glGenFramebuffers();
renderEngine.monitorTextures[i] = glGenTextures();
glBindFramebuffer(GL_FRAMEBUFFER, renderEngine.framebuffers[i]);
glBindTexture(GL_TEXTURE_2D, renderEngine.monitorTextures[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer)null);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderEngine.monitorTextures[i], 0);
}
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
System.err.println("Error while creating FBO");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
用于将四边形渲染到帧缓冲区的代码:glUseProgram(0);
for(int i = 0;i < 6;i++)
{
glBindFramebuffer(GL_FRAMEBUFFER, framebuffers[i]);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, 512, 512);
glClearColor(0f, 0f, 0f, 1f);
glClear(GL_COLOR_BUFFER_BIT);
//glActiveTexture(GL_TEXTURE0);
//glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 512, 512, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glUseProgram(0);
glColor4f(1f, 0f, 0f, 1f);
glBegin(GL_QUADS);
glVertex2f(20, 20);
glVertex2f(420, 20);
glVertex2f(420, 420);
glVertex2f(20, 420);
glEnd();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glPopAttrib();
}
如果我更改了清晰的颜色,纹理在我的3D场景中渲染时会获得该颜色。 但我无法看到四方。 我做错了什么吗?
如果找到解决方案。 原因我正在使用3D环境并启用了GL_CULL_FACE并将其设置为CCW(逆时针),未显示顺时针方向绘制的四边形。
我只是在绘制到帧缓冲区之前将其禁用,然后重新启用它。
glDisable(GL_CULL_FACE);
glEnable(GL_CULL_FACE);
链接地址: http://www.djcxy.com/p/34039.html