gpt4 book ai didi

opengl - 大于窗口大小的渲染缓冲区 - OpenGL

转载 作者:行者123 更新时间:2023-12-05 06:46:19 31 4
gpt4 key购买 nike

我正在尝试绘制到大于屏幕尺寸(即 320x480)的渲染缓冲区 (512x512)。

执行 glReadPixels 后,图像看起来是正确的,除非图像的尺寸超过屏幕尺寸——在本例中,超过 320 水平和 480 垂直。是什么导致了这种异常?有什么我想念的吗?当窗口大小 >= 渲染缓冲区的大小时,此代码绝对可以正常工作。

渲染到缓冲区和 glReadPixel 的示例图像: 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);

最佳答案

答案在这里。

更改此行: bglBindFramebuffer(BGL_RENDERBUFFER, canvasFrameBuffer);

对此: bglBindFramebuffer(BGL_FRAMEBUFFER, canvasFrameBuffer);

关于opengl - 大于窗口大小的渲染缓冲区 - OpenGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826750/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com