I'm currently programming a 2D-sidescroll game with c++ and OpenGL. To get the window I'm using SFML, but that should'nt be relevant as I draw all my quads directly with OpenGL.
Now the problem is when I use a Framebufferobject to draw some light-textures on it and then use it as a mask over the scene, the framerate drops down. Normally the game reaches its limit at 60 fps, but with the fbo, its about 40 fps, sometimes even 30.
The effect looks nice thought :D
I have never used a framebuffer befor, and this:
Framebuffer FBO render to texture is very slow, using OpenGL ES 2.0 on Android, why?
doesn't seem to help.
So my question: What am I doing wrong? Or is there even a much simpler way to reach the same effect?
I'm running it on Ubuntu 12.04.
My code:
void init() {
GLuint fbo, mask; //framebufferobject and texture
glewInit();
glGenTextures(1, &mask);
glBindTexture(GL_TEXTURE_2D, mask);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1024, 600, 0, GL_RGBA, GL_UNSIGNED_BYTE,
0);
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mask,
0);
glClearColor(darkness, darkness, darkness, 1);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
GL_FRAMEBUFFER_COMPLETE)CMain::game.usefbo = false;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void render() {
//render usual stuff, then
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, 1024, 600);
glBlendFunc(GL_SRC_COLOR, GL_ONE);
//render lights
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
//render fbo over the screen:
glBindTexture(GL_TEXTURE_2D, mask);
glTranslatef(0, 0, 9);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
glTexCoord2f(0, 1); glVertex2i(0, 600);
glTexCoord2f(1, 1); glVertex2i(1024, 600);
glTexCoord2f(1, 0); glVertex2i(1024, 0);
glEnd();
glLoadIdentity();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//display
}
Edit:
At //render lights three light-textures (round, radial, black-to-white) are rendered to the fbo via glBegin(GL_QUADS) etc.
Later of course I want to use much more lights.
I need to refresh the fbo every frame cause the lights are moving and overlapping each other.
render lights:
for(std::vector<LightSource*>::iterator it = lights.begin(); it != lights.end(); it++) {
(*it)->draw();
}
where lights is a vector of LightsSources.
Lightssource::draw():
void LightsSource::draw() {
if (visible()) {
if (activated) {
glTranslatef(this->x, this->y, 0);
glBindTexture(GL_TEXTURE_2D, this->texture);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
glTexCoord2f(0, 1); glVertex2i(0, height);
glTexCoord2f(1, 1); glVertex2i(width, height);
glTexCoord2f(1, 0); glVertex2i(width, 0);
glEnd();
glLoadIdentity();
}
}
}
visible() and activated are usually true.
What kind of GPU are you using?
The only thing I see right now is that you're using the texture format "GL_RGBA" instead of "GL_BGRA", which is considered the fastest format on many GPUs. So if you GPU is very old, that might be the issue.
Related
I'm attempting to to render a jpeg image (1024x1024 pixels) in the form of an FFmpeg AVFrame as a texture in OpenGL. What I get instead is something that appears as a 1024x1024 dark green quad:
The code to render the AVFrame data in OpenGL is shown below. I have convinced myself that the raw RGB data held within the FFmpeg AVFrame data is not solely dark green.
GLuint g_texture = {};
//////////////////////////////////////////////////////////////////////////
void display()
{
// Clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Operate on model-view matrix
glEnable(GL_TEXTURE_2D);
GLuint texture = g_texture;
glBindTexture(GL_TEXTURE_2D, texture);
// Draw a quad
glBegin(GL_QUADS);
glVertex2i(0, 0); // top left
glVertex2i(1024, 0); // top right
glVertex2i(1024, 1024); // bottom right
glVertex2i(0, 1024); // bottom left
glEnd();
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
glFlush();
}
/* Initialize OpenGL Graphics */
void initGL(int w, int h)
{
glViewport(0, 0, w, h); // use a screen size of WIDTH x HEIGHT
glEnable(GL_TEXTURE_2D); // Enable 2D texturing
glMatrixMode(GL_PROJECTION); // Make a simple 2D projection on the entire window
glOrtho(0.0, w, h, 0.0, 0.0, 100.0);
glMatrixMode(GL_MODELVIEW); // Set the matrix mode to object modeling
//glTranslatef( 0, 0, -15 );
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the window
}
//////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
std::shared_ptr<AVFrame> apAVFrame;
if (!load_image_to_AVFrame(apAVFrame, "marble.jpg"))
{
assert(false);
return 1;
}
// From here on out, the AVFrame is RGB interleaved
// and is sized to 1,024 x 1,024 (power of 2).
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(1060, 1060);
glutInitWindowPosition(0, 0);
glutCreateWindow("OpenGL - Creating a texture");
glGenTextures(1, &g_texture);
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, g_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, apAVFrame->width,
apAVFrame->height, 0, GL_RGB, GL_UNSIGNED_BYTE,
apAVFrame->data[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear interpolation for magnification filter */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear interpolation for minifying filter */
initGL(1060, 1060);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Environment:
Ubuntu 18.04
GCC v8.2
EDIT: As per #immibis' suggestion below, it all works when I change the rendering of the quad to:
// Draw a quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0); // top left
glTexCoord2f(1, 0);
glVertex2i(1024, 0); // top right
glTexCoord2f(1, 1);
glVertex2i(1024, 1024); // bottom right
glTexCoord2f(0, 1);
glVertex2i(0, 1024); // bottom left
glEnd();
You forgot to give your vertices texture coordinates, so all the pixels on your screen are reading the same pixel from the texture. (The top-left, or wherever the default texture coordinates are)
Use glTexCoord2f before glVertex2i to set the texture coordinates for the vertex. They go from 0 on the top/left of the texture, to 1 on the bottom/right, so the corners of the texture are 0,0, 1,0, 1,1 and 0,1.
I have code which is the equivalent of the following:
init code:
glCullFace(GL_FRONT_AND_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//clear to pink
glClearColor(1.0f, 0.0f, 1.0f, 0.0f);
GLuint textureObject;
glGenTextures(1, &textureObject);
glBindTexture(GL_TEXTURE_2D, textureObject);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA,
GL_UNSIGNED_BTYE, NULL);
GLuint fbo;
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
textureObject, 0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
assert(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)
== GL_FRAMEBUFFER_COMPLETE);
Object obj = CreateAFullscreenQuad(textureObject);
draw code:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glViewport(0, 0, 512, 512);
//clear to cyan
GLfloat clear[] = {0, 1, 1, 1};
glClearBufferfv(GL_COLOR, 0, clear);
SetUpPerspectiveAndCameraMatrix();
DrawSomeStuff();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glViewport(0, 0, window.width, window.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SetUpPerspectiveAndCameraMatrix();
obj.Draw();
SwapBuffers();
glxinfo excerpt:
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.4, 128 bits)
OpenGL version string: 2.1 Mesa 10.1.3
The problem is that the call to glClearBufferfv doesn't seem to clear the whole buffer. As you can see, it clears the triangular shape, but it doesn't touch the other areas. They are also not the glClearColor color (pink). If I use the regular glClear call, it does the same thing, but pink instead of cyan.
Turns out I created a feedback loop by drawing the fullscreen quad while the FBO was bound, drawing the contents of the buffer to itself. Apparently the effects of this end up being interspersed with the effects of glClear.
I have searched for this but unfortunately the only answers I find are those that deal with the issue of textures not being mapped, in this case the texture is mapped but does not look like the loaded surface.
Anyway, ignoring the fact that power of 2 square images aren't required (which I've yet to properly look into yet) I've made a functional script for expanding the surface to power of 2 dimensions and a structure for storing the resized surface, the old dimensions of the surface and the ID for the texture.
My surface to texture code is (arguments are SDL_Surface* surf, antTex* tex):
tex->w=surf->w;
tex->h=surf->h;
tex->surf=resizeToNearestPow2(surf);
glGenTextures(1, &tex->id);
glBindTexture(GL_TEXTURE_2D, tex->id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->surf->w, tex->surf->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, tex->surf->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, NULL);
The antTex struct is:
GLuint id; //Texture ID
int w, h; //Original Image Size
int rw, rh; //Resized Canvas Size
SDL_Surface* surf; //Resized Surface
Everything about resizing the image appears to be working fine (having used SDL's SDL_SaveBMP function to check the resulting image), I used SDL2_image.h's IMG_Load for loading the original image.
When I draw a plane with the texture mapped to it while GL_BLEND is enabled nothing shows up at all, when I disable it I get this (the red is the window's background colour):
http://i1200.photobucket.com/albums/bb336/DarknessXeagle/error_zps03e1e5a1.png
The original image was this:
http://i1200.photobucket.com/albums/bb336/DarknessXeagle/d_zpsc8b9af6f.png
This is my function for drawing plane with the texture mapped to it (arguments are antTex* tex, int x, int y):
glBindTexture(GL_TEXTURE_2D, tex->id);
int w, h;
w=tex->w;
h=tex->h;
GLfloat tw, th;
th=(GLfloat)tex->h/(GLfloat)tex->rh;
tw=(GLfloat)tex->w/(GLfloat)tex->rw;
glPushMatrix();
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2f(0, th); glVertex2f(0, h);
glTexCoord2f(tw, th); glVertex2f(w, h);
glTexCoord2f(tw, 0); glVertex2f(w, 0);
glTexCoord2f(0, 0); glVertex2f(0, 0);
glEnd();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, NULL);
You have a problem with u and v coordinates passed to render the texture into the quad using glTexCoord2f.
You need to change:
glTexCoord2f(0, th); glVertex2f(0, h);
glTexCoord2f(tw, th); glVertex2f(w, h);
glTexCoord2f(tw, 0); glVertex2f(w, 0);
glTexCoord2f(0, 0); glVertex2f(0, 0);
into:
glTexCoord2f(0, 1); glVertex2f(0, h);
glTexCoord2f(1, 1); glVertex2f(w, h);
glTexCoord2f(1, 0); glVertex2f(w, 0);
glTexCoord2f(0, 0); glVertex2f(0, 0);
I have a test program that programmatically renders a texture and then renders a simple quad that is skinned with the previously drawn texture. The program is extremely simple and everything is done in 2D. This program works great under linux and everything looks like it should:
However when I run the program on my mac running 10.7 nothing shows up:
I'm at a complete loss as to why this program isn't working on my mac.
Here are the relevant bits of the program.
Creating the texture:
void createTextureObject(){
cout<<"Creating a new texture of size:"<<textureSize<<endl;
//glDeleteTextures(1, &textureId);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap generation included in OpenGL v1.4
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, textureSize, textureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
isTextureValid = true;
createFBObject();
}
Creating the Frame Buffer Object:
void createFBObject(){
cout<<"Creating a new frame buffer object"<<endl;
glDeleteFramebuffers(1, &fboId);
glGenFramebuffersEXT(1, &fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glGenRenderbuffersEXT(1, &rboId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboId);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, textureSize, textureSize);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureId, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboId);
bool status = checkFramebufferStatus();
if(!status){
cout<<"FrameBufferObject not created! Quitting!"<<endl;
exit(1);
fboUsed = false;
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
Rendering to the texture:
void drawToTexture(){
if (!isTextureValid)
createTextureObject();
glViewport(0, 0, textureSize, textureSize);
glLoadIdentity();
// set the rendering destination to FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
// clear buffer
glClearColor(0, 0, 0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw to the texture
glColor3f(0.0, 1.0, 0.0);
for (int i=1; i<=5; i++){
glBegin(GL_LINE_LOOP);
glVertex2f(-1 * i/5.0f, -1 * i/5.0f);
glVertex2f( 1 * i/5.0f, -1 * i/5.0f);
glVertex2f( 1 * i/5.0f, 1 * i/5.0f);
glVertex2f(-1 * i/5.0f, 1 * i/5.0f);
glEnd();
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
Rendering the textured quad:
void drawTexturedQuad(){
glViewport(50, 50, textureSize, textureSize);
glLoadIdentity();
glClearColor(0.2, 0.2, 0.2, 0.2);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, textureId);
int size = 1;
int texS = 1;
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1);
glTexCoord2f(texS, texS); glVertex3f(size, size,0);
glTexCoord2f(0, texS); glVertex3f(-1 * size , size,0);
glTexCoord2f(0, 0); glVertex3f(-1 * size, -1 * size,0);
glTexCoord2f(texS, 0); glVertex3f(size, -1 * size,0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
}
I'm using GLUT and my display call back is simply:
void displayCB(){
drawToTexture();
drawTexturedQuad();
glutSwapBuffers();
}
Additionally I have other methods check to see if FrameBufferObjects are supported by OpenGL and if they are not the program quits. Additionally I have other logic that sets textureSize whenever the window is resized.
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap generation included in OpenGL v1.4
This might be a problem. The GL specification doesn't say exactly at what point mipmaps should be generated, and of course, this generates problems with render to texture. So the GL_EXT_framebuffer_object (and core versions too) introduced glGenerateMipmapEXT, which you call exactly in the point where you want mipmaps generated (usually after rendering to the texture).
So, remove the GL_GENERATE_MIPMAP stuff and use glGenerateMipmap manually when needed. You can read more about this problem in the GL_EXT_framebuffer_object specification.
Are you sure that your buffer id is 0 and not 1?
Maybe another FBO was already created before.
Also check texture dimensions try make them power of 2
I'm trying to perform hidden line removal using polygon offset fill. The code works perfectly if I render directly to the window buffer but fails to draw the lines when passed through a FBO as shown below
The code I use to draw the objects
void drawCubes (GLboolean removeHiddenLines)
{
glLineWidth(2.0);
glPushMatrix();
camera.ApplyCameraTransform();
for(int i = 0; i < 50; i ++){
glPushMatrix();
cube[i].updatePerspective();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(1.0,1.0,1.0);
cube[i].draw();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(removeHiddenLines){
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);
glColor3f(1.0, 0.0, 0.0); //fill polygons for hidden line removal
cube[i].draw();
glDisable(GL_POLYGON_OFFSET_FILL);
}
glPopMatrix();
}
glPopMatrix();
}
For this example, the first pass involves rendering to both the window buffer and a FBO.
void firstPass()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, fboWidth, fboHeight);
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
drawParticleView(GL_TRUE);
glDisable(GL_DEPTH_TEST);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, fboWidth, fboHeight);
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
drawParticleView(GL_TRUE);
glDisable(GL_DEPTH_TEST);
}
Second pass renders FBO back to window buffer.
void secondPass()
{
glEnable(GL_TEXTURE_2D);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, renderTextureID[0]);
glViewport(fboWidth, 0, fboWidth, fboHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2f(-1.0f, -1.0f);
glTexCoord2i(1, 0);
glVertex2f(1.0f, -1.0f);
glTexCoord2i(1, 1);
glVertex2f(1.0f, 1.0f);
glTexCoord2i(0, 1);
glVertex2f(-1.0f, 1.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
}
Setup FBO's
void setupRC()
{
setupTextures();
glGenFramebuffersEXT(2, framebufferID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[0]);
glGenRenderbuffersEXT(1, &renderbufferID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbufferID);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, fboWidth, fboHeight);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderbufferID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[0], 0);
GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT){
fprintf(stderr, "FBO #1 Error!");
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID[1]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, renderTextureID[1], 0);
fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT){
fprintf(stderr, "FBO #2 Error!");
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
Setup textures
void setupTextures(void)
{
glGenTextures(2, renderTextureID);
for (GLint i = 0; i < 2; i++){
glBindTexture(GL_TEXTURE_2D, renderTextureID[i]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// this may change with window size changes
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, fboWidth, fboHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}
glBindTexture(GL_TEXTURE_2D, 0);
}
I don't understand why the two views wouldn't be the same? Am I missing something (obviously I am)?
Thanks
The problem is that I was rendering to a FBO without a depth attachment. Setting up the second FBO the same as the first gave the correct results.
Your code seems ok to me. The weird stuff is that you still have the red cube drawn, but not the lines... What is your OpenGL implementation, driver version?
Can you test without enabling GL_POLYGON_OFFSET_FILL and/or glLineWidth to see if you see the lines (albeit hidden parts visible)?