1
我知道glGetTexImage
OpenGL函數允許從整個紋理中讀取像素。有沒有一個OpenGL函數可以做同樣的事情,但允許傳遞一個矩形來限制像素讀取?從OpenGL紋理的矩形中讀取像素
我知道glGetTexImage
OpenGL函數允許從整個紋理中讀取像素。有沒有一個OpenGL函數可以做同樣的事情,但允許傳遞一個矩形來限制像素讀取?從OpenGL紋理的矩形中讀取像素
這裏是我結束了在OpenTK做(應該很容易轉換爲C++或其他的OpenGL/OpenGL ES的啓用語言):
public Bitmap GetBitmap()
{
int fboId;
GL.Ext.GenFramebuffers(1, out fboId);
CheckGLError();
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboId);
CheckGLError();
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, TextureId, 0);
CheckGLError();
Bitmap b = new Bitmap(Width, Height);
var bits = b.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.ReadPixels(Rect.Left, Rect.Top, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bits.Scan0);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
GL.Ext.DeleteFramebuffers(1, ref fboId);
b.UnlockBits(bits);
return b;
}
FYI:我刪除了我的答案,因爲它是進入完全相反的方向。 – datenwolf 2013-02-19 12:13:34
感謝您的幫助datenwolf,聽起來像你知道很多有關OpenGL – jjxtra 2013-02-19 16:45:38
我不需要位圖,只是在特定的座標的RGB值,這仍然是最好的辦法? – 2016-04-18 05:05:26