Screenshot

Started by
9 comments, last by dragonsimoto 22 years, 1 month ago
how do i take a screenshot of just the window of my program?
Advertisement
I don't know if this will work with OpenGL (it does with DirectX if you allow it). Just press ALT+"Print Screen". Then, you can go into any image program and paste the capture into an image. There are other ways of doing it too, but this requires no coding :-)

Edited by - xelius on March 1, 2002 7:37:41 PM
-------------------"Pointer?" -Anonymous-=Xelius=-
Two ways:

1) You could write a function using a function like glGetPixels, and output it as a BMP, JPG, or custom file format.

2) You could use the "Print Scrn" key to screen capture, then edit the resulting image (paste it from your clipboard) in an image editing program like PSP, MS PAINT, or the GIMP.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

thanks alot
never tried that but i got psp7 so that will work
thanks
try this:

#include gl/gl.h
#include string.h
#include stdio.h

void SaveScreenShot(void)
{
unsigned char *pixels,buf;
int width,height;
FILE *shot;
char name[256];
BOOL D = FALSE;
unsigned int i=0;
int handle;
while(D==FALSE) {
sprintf(name,"Shot%i.tga",i);
if ((handle = open(name, O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) == -1) { i++; }
else { close(handle); break; }
}
if((shot=fopen(name, "wb"))==NULL) return;
width = EngineData.ResolutionWidth;
height = EngineData.ResolutionHeight;
pixels = new unsigned char[width*height*4];
glReadPixels(0, 0, width, height,GL_RGBA, GL_UNSIGNED_BYTE, pixels);
for (int x = 0; x < ((width)*(height)*4)-5; x++) {
buf = pixels[x];
pixels[x] = pixels[x+2];
pixels[x+2] = buf;
x++;
}
unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};
unsigned char header[6]={((int)(width%256)),((int)(width/256)),((int)(height%256)),((int)(height/256)),32,0};
fwrite(TGAheader, sizeof(unsigned char), 12, shot);
fwrite(header, sizeof(unsigned char), 6, shot);
fwrite(pixels, sizeof(unsigned char), width*height*4, shot);
fclose(shot);
delete [] pixels;
return;
}

How do yu use that plz
Quote:Michael TanczosCut that shit out. You shouldn't be spying on other people.. especially your parents. If your dad wanted to look at horses having sex with transexual eskimo midgets, that's his business and not yours.
Check this out:

  void SaveScreenShot(unsigned int i, int width, int height){   unsigned char *pixels,buf;   FILE *shot;   char name[20];   sprintf(name,"screenshot%i.tga",i);   if((shot=fopen(name, "wb"))==NULL)       return;   pixels = new unsigned char[width*height*4];   glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);   for (int x = 0; x < ((width)*(height)*4)-5; x++)    {      buf = pixels[x];      pixels[x] = pixels[x+2];      pixels[x+2] = buf;      x++;    }   unsigned char TGAheader[12]={0,0,2,0,0,0,0,0,0,0,0,0};   unsigned char header[6] = {width%256,width/256,height%256,height/256,32,0};   fwrite(TGAheader, sizeof(unsigned char), 12, shot);   fwrite(header, sizeof(unsigned char), 6, shot);   fwrite(pixels, sizeof(unsigned char), width*height*4, shot);   fclose(shot);      delete [] pixels;      return;}  


Basically the same thing, but a little bit clearer. Simply pass it a number(this number will be appended to "screenshot" to make the filename, as in "screenshot4.tga"), and the height and width of your current screen settings (like 800x600 or 1024x768, etc.)

Just call it at any time when you want to take a screenshot, but be aware that on a 1.3 Ghz machine, it''ll take about 1/3 of a second to execute, so you won''t want to do it every frame of anything. Just call it based on a keypress, like VK_SNAPSHOT or VK_F12.

Drop a line if you need more help,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

>>for (int x = 0; x < ((width)*(height)*4)-5; x++)
{
buf = pixels[x];
pixels[x] = pixels[x+2];
pixels[x+2] = buf;
x++;
}
<<
r u sure about this?

btw u can use BGR with readpixels so no swaping necessary
also does your window have dst alpha if not then doing RGB will be better than RGBA

http://uk.geocities.com/sloppyturds/gotterdammerung.html
zedzeek >> how do you use BGR ? I didn''t find GL_BGR or something in gl.h file...
zedzeek: I''m sure about it only because it works. I freely admit that I don''t know why, but I have tested it, and sure enough, it does the job.

last poster: GL_BGR_EXT is what you''re looking for. You can''t use glReadPixels in BGR format without this extension, but I''m betting that it''s standard now. Also, remove the code segment that zedzeek questioned if you use GL_BGR_EXT - you don''t need to swap the R and B if you use it.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement