0
votes

Alright, so here's my current workflow for rendering. I create a framebuffer object without a depth/stencil attachment and only a colour texture attachment. I bind the framebuffer and render all my textures onto it. I then copy the texture data from the render buffer texture onto another texture (although this part isn't really relevant because the problem occurs when rendering to the frame buffer). So the problem is that once the rendering goes past the window bounds, it stops drawing. So here's an image of what is currently rendered (sorry I have to post links, I don't have enough reputation to post images yet):

http://i.imgur.com/lj2o7yO.jpg

And here's an image of the actual texture data (provided by gDEBUgger).

enter image description here

As you can see, the part where it cuts off is where the window width is. Using glClear also only covers the window size of the texture and nothing else. I have tried using glDisable(GL_SCISSOR_TEST) along with glViewport(0, 0, texture_width, texture_height) but it's still cutting off the texture. Making the viewport smaller cuts off at the same point, making it larger just stretches the image and cuts off more of the texture.

I mean, it makes sense, why would you want to draw pixels off-screen when you can't even see them, that would be horrible for performance. In my case though, I need to do it. That's why I'm looking for a way to disable it or something like that.

Also note that I have disabled depth testing so it couldn't be that the depth clear doesn't go past the window bounds since I disabled it.

Anyone got any ideas?

Edit: Just in case anyone sees this thread in the future, just wanted to say what solved it for me. I just needed to set the viewport to the size of the texture AND scale the perspective matrix to the same size when rendering. In my case, I used my own matrix class. Here's an example:

glViewport(0, 0, texture_width, texture_height);
perspective_mat.identity();
perspective_mat.scale(1.0f / (texture_width / 2), -1.0f / (texture_height / 2));
perspective_mat.translate(-1.0f, 1.0f);

In case you are using fixed-pipeline stuff (no shaders, ect) then you can use the openGL matrix functions to scale and translate. :)

1

1 Answers

1
votes

Without seeing your actual code, it's difficult to say what's going wrong, but this code works.

// ************************************** Save the Current Viewport Size

GLint screenViewPort[4];
glGetIntegerv(GL_VIEWPORT, screenViewPort);

// ***************************** Define a Second Output Buffer and Bind it for Writing

glGenFramebuffersEXT(1, wispSecondOutputBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wispSecondOutputBuffer[0]);

// ******************************* Set the Viewport to the Texture Size and Reshape

glViewport(0,0,TEXTUREWIDTH, TEXTUREHEIGHT);
[self resizeTextureGL];

// ************************************** Create the Output Imgage Texture

glGenTextures( 1, wispOutputTexture);
glBindTexture(GL_TEXTURE_2D, wispOutputTexture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)TEXTUREWIDTH, (GLsizei)TEXTUREHEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

// ********************************* Attach the Output Texture to the Frame Buffer

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, wispOutputTexture[0], 0);

GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers);

// ************************************ Check that the Frame Buffer is Complete

GLenum frameBufferStatus;

frameBufferStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

if(frameBufferStatus != GL_FRAMEBUFFER_COMPLETE_EXT) NSLog(@"There is a problem with the output frame buffer");

// ****************************************** Render to the Texture

[self runTextureShaders];
[self runTextureShaders2];

// ************************************ Reset the Viewport and Frame Buffer

glViewport(screenViewPort[0],screenViewPort[1],(GLsizei)screenViewPort[2], (GLsizei)screenViewPort[3]);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

// ******************************* Copy the Texture Data Into the Bitmap Image

glBindTexture(GL_TEXTURE_2D, wispOutputTexture[0]);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmapData);

The call to resizeTextureGL calculates the Model, View and Projection matrices.

Later in the code I also have:

// ******************************************* Cleanup Memory

glDeleteTextures(1, wispOutputTexture);
glDeleteFramebuffersEXT(1, wispSecondOutputBuffer);