Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OpenGL - Screenshots always magenta  (Read 5057 times)

0 Members and 2 Guests are viewing this topic.

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
OpenGL - Screenshots always magenta
« on: May 27, 2012, 08:31:31 am »
So I've got a rather annoying problem.  I'm working on a project in OpenGL, and for the moment, my model and background are various shades of grey.  This works fine while I'm running the program, but when I take a screenshot of the scene using these methods:

sf::Image Screen = App->Capture();
Screen.SaveToFile("screenshot.bmp");

the resulting image is in shades of magenta-to-white, rather than grey.  This has the added problem of making much of the image disappear, because most of the areas that aren't brightly shaded (or under-shaded) are all absorbed into the same color.  I've tried to attach a screenshot - the object in the screenshot is supposed to be a full beveled triangle, but you can only barely see it.

What's up with this, and how can I produce accurate screenshots?

[attachment deleted by admin]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL - Screenshots always magenta
« Reply #1 on: May 27, 2012, 09:18:32 am »
Can you post a complete and minimal code that reproduces teh problem?
Laurent Gomila - SFML developer

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #2 on: May 27, 2012, 09:37:48 am »
It happens when I use the OpenGL example provided in the SFML folder and add
Code: [Select]
if ((Event.Type == sf::Event::KeyPressed) &&
    (Event.Key.Code == sf::Key::F1))
{
     sf::Image Screen = App.Capture();
     Screen.SaveToFile("screenshot.bmp");
}

I've attached the modified example file.  I didn't touch anything besides adding the above code into the while (App.IsOpened()) loop.

I am still using SFML 1.6.  Is this perhaps a known bug...?  Or perhaps something on my end beyond the code, most likely.  I don't know what settings or configurations might cause this.

[attachment deleted by admin]
« Last Edit: May 27, 2012, 09:40:43 am by GarrickW »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL - Screenshots always magenta
« Reply #3 on: May 27, 2012, 09:41:01 am »
Quote
I am still using SFML 1.6.
Ah... Could you test with SFML 2? SFML 1.6 is not maintained anymore.
Laurent Gomila - SFML developer

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #4 on: May 27, 2012, 09:48:18 am »
Quote
I am still using SFML 1.6.
Ah... Could you test with SFML 2? SFML 1.6 is not maintained anymore.

Okay - having just downloaded SFML 2, I see the OpenGL example is just an executable with some assets, is that right?  Or am I looking in the wrong place?

Also, just to make sure since the tutorials aren't up, installing SFML 2 works just like it did with SFML 1.6, right?  Or anything special to pay attention to?

If so, I guess I'll first go through my code and replace SFML 1.6 with SFML 2 code, and see if the problem persists.  Thankfully there isn't too much in there to replace, most of it is custom or regular OpenGL.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL - Screenshots always magenta
« Reply #5 on: May 27, 2012, 10:45:52 am »
Quote
I see the OpenGL example is just an executable with some assets, is that right?
Yes (what else could it be? ;D).

Quote
Also, just to make sure since the tutorials aren't up, installing SFML 2 works just like it did with SFML 1.6, right?
The installation tutorials are online.
Laurent Gomila - SFML developer

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #6 on: May 27, 2012, 11:26:03 am »
Quote
The installation tutorials are online.

I saw that afterwards - I initially just read the download page and didn't check the Tutorial page to confirm.  I guess I wasn't really paying attention! 

I think I've got SFML 2 properly integrated into my program, just scouring the code for old code to switch over.  I'll let you know if the problem persists.

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #7 on: May 27, 2012, 12:25:06 pm »
Okay!  So, the good news is, I've migrated to SFML 2.0 and the code all works!  Most of the changes just involved decapitalizing the initial letter of each method/function, although I did have to make an sf::Clock...

The bad news is that the screenshots are still pink.  Hm.  I'll see if I can make something small and self-contained.

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
UPDATE on magenta screenshots, full example code
« Reply #8 on: May 29, 2012, 06:58:34 pm »
So I've taken apart my code and hacked it down to the bare minimum, removing lighting, shading and all, and the screenshots are still pink.  Here is the entire code of a program that displays an empty OpenGL scene.  Perhaps you could remove even more, but I removed all the stuff that seemed superfluous.

The scene is dark grey when seen real-time, or captured with PrintScreen (with Windows, not within the program), but pressing F1 (which uses the SFML function) creates a pink/magenta image rather than a dark grey one as expected.  There are no polygons, but they aren't necessary to see the problem.

#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>

int main()
{
    //WindowSize
    int WindowWidth = 800;
    int WindowHeight = 600;
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(WindowWidth, WindowHeight, 32), "OpenGL Magenta Problem");

    // Set color and depth clear value
    glClearDepth(1.f);
    //Color here is in RGB, converted to a 0-1 scale.
    glClearColor(0.3f, 0.3f, 0.3f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.f, 1.33f, 0.1f, 512.f);

    // Start game loop
    while (App.isOpen())
    {
        sf::Event Event;
        while (App.pollEvent(Event))
        {
            // Close window : exit
            if (Event.type == sf::Event::Closed)
            {
                App.close();
            }

            // Escape key : exit
            if (Event.type == sf::Event::KeyPressed &&
                Event.key.code == sf::Keyboard::Escape)
            {
                App.close();

            }
            if (Event.type == sf::Event::KeyPressed &&
                Event.key.code == sf::Keyboard::F1)
            {
                sf::Image Screen = App.capture();
                Screen.saveToFile("screenshot.bmp");
                std::cout << "Screenshot saved!\n";
            }
        }

        //Clear color and depth buffer, and reset the screen
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        //Display
        App.display();
    }

    return 0;
}
 
« Last Edit: May 29, 2012, 07:34:00 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL - Screenshots always magenta
« Reply #9 on: May 29, 2012, 07:36:59 pm »
It seems like BMP export is broken, all other formats work.
Laurent Gomila - SFML developer

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #10 on: May 29, 2012, 08:23:44 pm »
It seems like BMP export is broken, all other formats work.

I just tried with .tga, .jpg and .png.  I can't open .tga files for some reason, but yes, .jpg files work fine!  I'll use the .jpg format from now on.

Unfortunately, .png gives me a picture that is mostly transparent instead of dark grey, except for polygons that are heavily lit/shadowed (when printing a screen with models), or fully transparent (with the above example code).  Perhaps that's just me, though the code is otherwise identical.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: OpenGL - Screenshots always magenta
« Reply #11 on: May 29, 2012, 08:30:16 pm »
Oh, your clear color has an alpha of 0. That explains everything (even the pink BMP: I checked and that how transparency is "transformed" for this format that doesn't support alpha). Your clear color alpha should be 1!
Laurent Gomila - SFML developer

GarrickW

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: OpenGL - Screenshots always magenta
« Reply #12 on: May 30, 2012, 06:55:05 am »
Ahh, I see.  I changed that - thanks!

 

anything