Forum > OpenGL
Flipping after glReadPixels
gilsonalencar:
After many efforts, i can to put a OpenGLControl graphics in a bitmap image. But it is inverted from original source, when glReadPixels is used. After weeks searching in the web, i can“t to find any solution to flip it using gl functions. Anybody knows how to do it? Technics using Canvas.Pixels[X,Y] are very slow.
Leledumbo:
What format parameter (5th position) do you give?
gilsonalencar:
The complet code is here.
--- Code: ---
function BitmapImage(c:TOpenGLControl):TBitmap;
var
data,rdata: pbyte;
w,h,s: integer;
bitMap: TBitmap;
begin
c.Repaint;
w := c.Width;
h := c.Height;
s := w*h*4;
result := TBitmap.Create;
bitMap:=result; try
bitMap.SetSize(w,h);
bitMap.PixelFormat:=pf32bit;
getMem(data,s); try
glPixelStorei(GL_PACK_ALIGNMENT, 4);
pixel}
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, data);
rdata := bitMap.RawImage.Data;
Move(data^,rdata^,bitMap.RawImage.DataSize);
finally
freemem(data);
end;
except
bitMap.free;
end;
end;
--- End code ---
KpjComp:
When you say inverted, do you mean the R & B are swapped.
I wrote a routine here that might help ->
http://80.123.225.56/index.php/topic,17383.msg95733.html#msg95733
User137:
If it's about colors, then this code:
--- Code: ---glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, data);
--- End code ---
you can switch to GL_BGR.
If it's graphics upside down, then you need to draw then in OpenGL differently. If you use ortho (2D) mode, you should set the screen so that origo (0, 0) is in top left.
Or that may not help at all, who knows. I haven't used glReadPixels, i hear it's slow operation. Even slower than canvas operations.
Navigation
[0] Message Index
[#] Next page