Renderbuffers larger than window size - OpenGL
Asked Answered
A

1

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);
Artificiality answered 30/5, 2013 at 1:57 Comment(4)
There's a clipping rectangle that defaults to the size of the window. There's probably a way to change it.Saintsimon
See item 10.040 here: opengl.org/archives/resources/faq/technical/clipping.htmSaintsimon
What's all this BGL nonsense? Also, is this about OpenGL or OpenGL ES?Adim
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. :PArtificiality
A
1

Here's the answer.

Change this line: bglBindFramebuffer(BGL_RENDERBUFFER, canvasFrameBuffer);

to this: bglBindFramebuffer(BGL_FRAMEBUFFER, canvasFrameBuffer);

Artificiality answered 30/5, 2013 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.