Skip to main content
gamedev.net
🔒 Locked

Saving BMP from the framebuffer

Started by Coroner 2 replies 3.6k views
Original Post
Coroner
Coroner
Does anybody know how to save an image from the framebuffer into a bmp file in OpenGL? Something like auxDIBImageSave.
_wintermute
_wintermute
just call saveBitmapFromFramebuffer()

works for me


oh yeah, you might also need to learn about the BMP file format and how to read data from the framebuffer so that saveBitmapFromFramebuffer() works properly...

live and learn...it''s quite simple really

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Kierkegaard reminds us that belief
has nothing to do with how or why.
Belief is beyond reason.

I believe because it is absurd."

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"Kierkegaard reminds us that belief has nothing to do with how or why.Belief is beyond reason.I believe because it is absurd."
JTippetts
JTippetts
void GetScreenShot(char *Filename)
{
FILE *Out;
unsigned char *Buff;

// Capture a screen shot. Save as a RAW-format file.
// First, allocate memory.
Buff = new unsigned char[ScreenWidth*ScreenHeight*3];

// Now, get pixels.
glReadBuffer(GL_FRONT);
glReadPixels(0,0, ScreenWidth, ScreenHeight, GL_RGB, GL_UNSIGNED_BYTE, Buff);

// Now, open to file and write pixels.
Out = fopen(Filename, "wb");
if(!Out) return;
fwrite(Buff, 3, ScreenWidth*ScreenHeight, Out);
fclose(Out);
delete[] Buff;
}

This is a quick function that will grab a screenshot and save it to a .RAW format (without any header data). You would have to modify it to save to .BMP (I never use .BMP, so I don't know the format), but this should be fairly simple if you read up on the file format here. The important part is the glReadPixels(), call which basically grabs RGB pixels from the front buffer into your own buffer. You can do basically whatever you want with it after that.

Of course, Windows may have it's own little functions for doing this; I wouldn't know, as I choose not to use Windows.

Josh
vertexnormal AT linuxmail DOT org


Check out Golem at:
My cheapass website

[edited by - VertexNormal on September 10, 2003 2:13:23 PM]
Coroner
Coroner
I realized that BMP file format doesn''t look very well for me. So I decided to save into PPM file. It''s the same as RAW but it holds some extra info (width, height and depth). Thx VertexNormal and _wintermute

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.