Results 1 to 3 of 3

Thread: [HELP]Getting a black screen(C#-GL.glReadPixels)

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    1

    [HELP]Getting a black screen(C#-GL.glReadPixels)

    Hello everyone,
    I have 2 codes (I found in here/internet) that suppost to copy the pixels from my screen (By the OpenGL lib) into a Bitmap class.
    The problem is that both of them print a black screen.

    The codes:
    Code :
            static Bitmap GrabScreenshot()
            {
                Bitmap bmp = new Bitmap(800, 600);
                System.Drawing.Imaging.BitmapData data = bmp.LockBits(new Rectangle(0, 0, 800, 600), System.Drawing.Imaging.ImageLockMode.WriteOnly,
                    System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                GL.glReadPixels(0, 0, 800, 600, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, data.Scan0);
                GL.glFinish();
                bmp.UnlockBits(data);
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                return bmp;
            }

    Code :
             static Bitmap GrabScreenshot()
    {
                Size s = new Size();
                s.Width = 800;
                s.Height = 600;
                Bitmap b = new Bitmap(s.Width, s.Height, PixelFormat.Format32bppArgb);
                BitmapData bd = b.LockBits(new Rectangle(0, 0, s.Width, s.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                GL.glReadPixels(0, 0, s.Width, s.Height, GL.GL_BGRA_EXT, GL.GL_UNSIGNED_BYTE, bd.Scan0);
                b.UnlockBits(bd);
                b.RotateFlip(RotateFlipType.Rotate180FlipX);
                 return b




    My main idea is to capture a screen when you are in a 3D game (Like: Counter-Strike/Counter-Strike:Source),
    and few people told me that the solution for it is using OpenGL,


    Thanks in advanced,
    Elad.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Posts
    357

    Re: [HELP]Getting a black screen(C#-GL.glReadPixels)

    The code is correct: this will capture the contents of an OpenGL context into a System.Drawing.Bitmap.

    However, the context will have to be current on the thread you are calling GrabScreenshot() from. If the context is in another process, this code is not going to work.
    [The Open Toolkit library: C# OpenGL 4.4, OpenGL ES 3.1, OpenAL 1.1 for Mono/.Net]

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: [HELP]Getting a black screen(C#-GL.glReadPixels)

    I think it is related to this recent thread:
    http://www.opengl.org/discussion_boa...160#Post261160

    Does that help you?

Similar Threads

  1. Black screen using Print Screen
    By specifikys in forum OpenGL: Windows
    Replies: 1
    Last Post: 11-01-2010, 01:32 PM
  2. Replies: 0
    Last Post: 07-29-2009, 12:54 PM
  3. Replies: 0
    Last Post: 09-30-2003, 08:58 AM
  4. BLACK SCREEN :(
    By afalloN in forum OpenGL: User Software
    Replies: 0
    Last Post: 02-19-2003, 11:14 AM
  5. glReadPixels gives only black...
    By Nick Nougat in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-21-2002, 02:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean