Need help with screenshot function (dll) in opengl game

Discussion in 'Programming/Html' started by WhiteLightning, Feb 18, 2015.

  1. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    30,766
    Likes Received:
    3,932
    GPU:
    Inno3d RTX4070
    Hi,

    Just thought i would ask this maybe someone can help me or point me in the right direction.

    What i need is a dll which will allow to take screenshots of an opengl game (MOHAA which is based on the Quake3 engine).

    Its purpose would be to integrate it into a anti-cheat tool.
    we have tried the windows printscreen version, but sometimes there is a grey screen, and we have no clue how to solve this.
    if i take screenshots with one of those screenshot programs like FRAPS or MSI Afterburner they all end up fine.

    So it would be nice if anyone could help me with this , or point in the right direction ?

    Cheers!
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,540
    Likes Received:
    13,556
    GPU:
    GF RTX 4070
    http://stackoverflow.com/questions/5844858/how-to-take-screenshot-in-opengl
    http://pngwriter.sourceforge.net/
    Code:
    Generally, OpenGL don't provide functions to save image. I think the fastest and simplest way to do this is save to .PPM format. However, this kind of format is uncompressed which means it's file size would be very large. And it can be support only by quite a few programs nowadays.
    
    I prefer to save image to .png file which is compressed but also gives lossless image and supported by many browsers. To save the OpenGL to .png format, I first recommend the PNGwriter. It's pretty simple and easy to use. For example, to save a pixel of a image with color (R, G, B) in the position (x, y), your code will be(see "quickstart" in the PNGwriter website):
    
    pngwriter PNG(width, height, 1.0, fileName); // "1.0" stand for the white background
    PNG.plot(x, y, R, G, B);
    PNG.close();
    Note that, since the PNGwriter save each pixel starting from the top-left corner of the image, while the array get from glReadPixels() start from the bottom-left of the window, your code to save the whole image might probably look like this:
    
    GLfloat* pixels = new GLfloat[nPixels];
    glReadPixels(0.0, 0.0, width, height,GL_RGB, GL_FLOAT, pixels);
    pngwriter PNG(width, height, 1.0, fileName);
    size_t x = 1;   
    size_t y = 1;
    double R, G, B;
    for(size_t i=0; i<npixels; i++) // "i" is the index for array "pixels"
    {
          switch(i%3)
         {
               case 2:
                     B = static_cast<double>(pixels[i]); break;
               case 1:
                     G = static_cast<double>(pixels[i]); break;
               case 0:
                     R = static_cast<double>(pixels[i]);
                     PNG.plot(x, y, R, G, B);     // set pixel to position (x, y)
                     if( x == width )             // Move to the next row of image
                     {
                           x=1;
                           y++;
                      }
                      else                       // To the next pixel
                      { x++; }
                      break;
         }
    }
    PNG.close();
    
    Edit:
    http://www.david-amador.com/2012/09/how-to-take-screenshot-in-opengl/
    https://www.opengl.org/discussion_boards/showthread.php/174466-Screenshot-of-opengl-window
    https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=7686&lngWId=3
    http://programmingexamples.net/wiki/OpenGL/Screenshot
     
    Last edited: Feb 18, 2015
  3. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    30,766
    Likes Received:
    3,932
    GPU:
    Inno3d RTX4070
    you are awesome! , ill show this information and hopefully it will be what he needs. thanks a lot :thumbup:
     
  4. ibitato

    ibitato Guest

    https://sites. google. com/site/screenshotlibrarynetdll/home/downloads
     

Share This Page