Grabbing screenshot of fullscreen game

Hey all,

is there anyone who knows how to do this ( it’s for counter-strike 1.6 ). I was looking for this but I couldn’t find anywhere full code or explanation. I need this in C#.
Just to say that I am complete beginner in C# :slight_smile:

Maybe look here:

http://eonstrife.wordpress.com/2007/06/02/taking-a-screenshot-from-an-opengl-application/

I’m also a bit interested in this topic…

Or from here:

http://www.flashbang.se/archives/155



void screenshot (char filename[160],int x, int y)
{

// get the image data
long imageSize = x * y * 3;
unsigned char *data = new unsigned char[imageSize];
glReadPixels(0,0,x,y, GL_BGR,GL_UNSIGNED_BYTE,data);

// split x and y sizes into bytes
int xa= x % 256;
int xb= (x-xa)/256;

int ya= y % 256;
int yb= (y-ya)/256;

//assemble the header
unsigned char header[18]={0,0,2,0,0,0,0,0,0,0,0,0,(char)xa,(char)xb,(char)ya,(char)yb,24,0};

// write header and data to file
fstream File(filename, ios::out | ios::binary);
File.write (reinterpret_cast(header), sizeof (char)*18);
File.write (reinterpret_cast(data), sizeof (char)*imageSize);
File.close();

delete[] data;
data=NULL;
}

I just get these errors:

view.cpp:128:31: error: expected ‘<’ before ‘(’ token
view.cpp:128:31: error: expected type-specifier before ‘(’ token
view.cpp:128:31: error: expected ‘>’ before ‘(’ token
view.cpp:129:31: error: expected ‘<’ before ‘(’ token
view.cpp:129:31: error: expected type-specifier before ‘(’ token
view.cpp:129:31: error: expected ‘>’ before ‘(’ token

At these lines:


File.write (reinterpret_cast(header), sizeof (char)*18);
File.write (reinterpret_cast(data), sizeof (char)*imageSize);

I don’t understand this error. However, I don’t understand reinterpret_cast… Anyone?

First of all, why would you want to program a feature that already exists? What’s it exactly that you want to do? Taking screenshots is already an implemented feature of the Half-Life engine.

I am trying to make simple Anti Cheat with SS capture and upload to FTP…

So, if I get you correctly, you want to take screenshots from some running OpenGL app with a seperate app written in C#?

Yes :slight_smile:

Since I’ver never done this before I’m not quite sure how to realize this exactly. But since you need to read portions of the framebuffer of the OpenGL app you’ll either have to integrate your tool with the application directly, or use a shared context so you can access video memory. I doubt this is going to be easy to integrate with the Half-Life engine.