3

I'm trying to draw to a renderbuffer (512x512) that's larger than the screen size (i.e., 320x480).

After doing a glReadPixels, the image looks correct, except once the dimensions of the image exceed that of the screen size- in this example, past 320 horizontal and 480 vertical. What causes this anomaly? Is there something I'm missing? When the window size is >= the size of the renderbuffer, this code works absolutely fine.

Example image that was rendered to the buffer & glReadPixel'd: http://img593.imageshack.us/img593/3220/rendertobroke.png

unsigned int canvasFrameBuffer; bglGenFramebuffers(1, &canvasFrameBuffer); bglBindFramebuffer(BGL_RENDERBUFFER, canvasFrameBuffer); // Attach renderbuffer unsigned int canvasRenderBuffer; bglGenRenderbuffers(1, &canvasRenderBuffer); bglBindRenderbuffer(BGL_RENDERBUFFER, canvasRenderBuffer); bglRenderbufferStorage(BGL_RENDERBUFFER, BGL_RGBA4, width, height); bglFramebufferRenderbuffer(BGL_FRAMEBUFFER, BGL_COLOR_ATTACHMENT0, BGL_RENDERBUFFER, canvasRenderBuffer); bglViewport(0, 0, width, height); Matrix::matrix_t identity, colorMatrix; Matrix::LoadIdentity(&identity); Matrix::LoadIdentity(&colorMatrix); bglClearColor(1.0f, 1.0f, 1.0f, 1.0f); bglClear(BGL_COLOR_BUFFER_BIT); Vector::vector_t oldPos, oldScale; Vector::Copy(&oldPos, &pos); Vector::Mul(&pos, 0.0f); Vector::Copy(&oldScale, &scale); Vector::Load(&scale, 1, 1, 1); int oldHAlign = halignment; int oldVAlign = valignment; halignment = Font::HALIGN_LEFT; valignment = Font::VALIGN_BOTTOM; float oldXRatio = vid.xratio; float oldYRatio = vid.yratio; vid.xratio = 1; vid.yratio = 1; Drawing::Set2D(this->size.x, this->size.y); // glOrtho and setup projection/modelview matrices Draw(&identity, &colorMatrix); Vector::Copy(&pos, &oldPos); Vector::Copy(&scale, &oldScale); halignment = oldHAlign; valignment = oldVAlign; vid.xratio = oldXRatio; vid.yratio = oldYRatio; byte *buffer = (byte*)Z_Malloc(width * height * 3, ZT_STATIC); bglPixelStorei(BGL_PACK_ALIGNMENT, 1); bglReadPixels(0, 0, width, height, BGL_RGB, BGL_UNSIGNED_BYTE, buffer); byte *final = RGBtoLuminance(buffer, width, height); SaveTGA("canvas.tga", final, width, height, 1); Z_Free(buffer); // unbind frame buffer bglBindRenderbuffer(BGL_RENDERBUFFER, 0); bglBindFramebuffer(BGL_FRAMEBUFFER, 0); bglDeleteRenderbuffers(1, &canvasRenderBuffer); bglDeleteFramebuffers(1, &canvasFrameBuffer); bglViewport(0, 0, vid.width, vid.height); 
4
  • There's a clipping rectangle that defaults to the size of the window. There's probably a way to change it. Commented May 30, 2013 at 3:00
  • See item 10.040 here: opengl.org/archives/resources/faq/technical/clipping.htm Commented May 30, 2013 at 3:01
  • What's all this BGL nonsense? Also, is this about OpenGL or OpenGL ES? Commented May 30, 2013 at 8:39
  • bgl is just a wrapper that helps avoid EXT/ARB issues with different kinds of drivers. This is both desktop GL and GLES, but using the GLES subset. I thought it might be clipping too, but I'm properly setting the glOrtho. Turns out I was using GL_RENDERBUFFER instead of GL_FRAMEBUFFER on glBindFramebuffer. How simple. :P Commented May 30, 2013 at 12:01

1 Answer 1

1

Here's the answer.

Change this line: bglBindFramebuffer(BGL_RENDERBUFFER, canvasFrameBuffer);

to this: bglBindFramebuffer(BGL_FRAMEBUFFER, canvasFrameBuffer);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.