sYnced's picture

Black Screen Shot

Well OpenTK people, im new here, and im a noobiest c# coder.

I want take screenshot a game (counter strike 1.6), but when i take the screen has black.

Here is my code (i have see here.)

// Creates a 1.0-compatible GraphicsContext with GraphicsMode.Default
        GameWindow window = new GameWindow();
 
        // Creates a 3.0-compatible GraphicsContext with 32bpp color, 24bpp depth
        // 8bpp stencil and 4x anti-aliasing.
        GLControl control = new GLControl(new GraphicsMode(32, 24, 8, 4), 3, 0, 0);
 
        public Bitmap GrabScreenshot()
        {
            if (GraphicsContext.CurrentContext == null)
                throw new GraphicsContextMissingException();
 
            Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            System.Drawing.Imaging.BitmapData data =
                bmp.LockBits(this.ClientRectangle, System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            OpenTK.Graphics.OpenGL.GL.ReadPixels(0, 0, this.ClientSize.Width, this.ClientSize.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgr, OpenTK.Graphics.OpenGL.PixelType.UnsignedByte, data.Scan0);
            bmp.UnlockBits(data);
 
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            return bmp;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(10000);
            pictureBox1.Image = GrabScreenshot();
        }

Anyone can help me ?

Sorry im really noob in opengl, but im are reading about this.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
winterhell's picture

Hey. With this code you are taking a screenshot out of YOUR OpenGL program, and not from the CS 1.6.
Taking a screenshot from another application is very complicated. Almost every scenario you could think of (like periodically taking screenshots) could be accomplished with the help of likes of FRAPS or PlayClaw.

sYnced's picture

How i can put into cs 1.6 ?

Thanks!

AndyKorth's picture

You definitely can not put your OpenTK C# code into counterstrike.

sYnced's picture

Method to take screenshot to counterstrike ?

winterhell's picture

Download http://www.fraps.com/ . Configure the screenshot key or just press F10 during the game. The screenshot will appear at (C:/)FRAPS/screenshots/

AndyKorth's picture

In fact, I believe Counterstrike Source has a screenshot button, I believe it defaults to F5.