我试图一个OpenGL创建场景保存为TBitmap。我遇到的问题是glReadPixels将返回所有空数据(全0)。为什么会发生这种想法?我试图捕获当前的OpenGL上下文。 (在屏幕上显示的都是正常工作)。这是在Windows下的Delphi 7。保存OpenGL场景到TBitmap - glReadPixels返回空闲数据?
var
pbuf: pointer;
y: integer;
bmp: TBitmap;
p1, p2: pointer;
begin
GetMem(pbuf, pnScene.Width * pnScene.Height * 4);
glReadPixels(0, 0, pnScene.Width, pnScene.Height, GL_RGBA, GL_UNSIGNED_BYTE, pbuf);
//<------ pbuf now contains all 0's ---------->
bmp := TBitmap.Create;
bmp.PixelFormat := pf32bit;
bmp.Width := pnScene.Width;
bmp.Height := pnScene.height;
for y := 0 to (pnScene.Height -1) do
begin
p1 := bmp.ScanLine[y];
p2 := pointer(integer(pbuf)+ (y * bmp.Width * 4));
CopyMemory(p1, p2, bmp.Width * 4);
end;
bmp.SaveToFile('c:\test\temp.bmp');
bmp.Free;
FreeMem(pbuf);
end;
非常欢迎您的建议/想法!
附录:
最终的计划是放置glReadPixels()调用渲染要求录制视频的目的之后。当我这样做的时候,它运作良好,所以这最终成为一个没有问题的东西。
您是否检查错误? glGetError – Bart 2011-05-15 08:26:31
是的,对不起,我应该提到 - 没有错误glReadPixels() – GrandmasterB 2011-05-15 17:33:21