SFML community forums

Help => Graphics => Topic started by: OniLinkPlus on January 31, 2010, 12:44:56 am

Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on January 31, 2010, 12:44:56 am
I have a RenderWindow with a size of 300x200, and an Image with the same size. I go through each pixel in the image and generate a color for it(Mandelbrot calculations), and when I try Window.Draw(sf::Sprite(Image)); then Window.Display();, the Window stays black as if the image were black. I know this is not true because I also SaveToFile("Mandelbrot.png") the Image, and that image looks just fine. The weirdest part is, I am getting no errors and the code works just fine on Ubuntu 9.10.
Title: Code Generated Image does not display on Windows
Post by: Nexus on January 31, 2010, 01:04:22 am
Hm, could you show a minimal code example? What compiler and OS are you using?
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on January 31, 2010, 01:16:51 am
Quote from: "Nexus"
Hm, could you show a minimal code example? What compiler and OS are you using?
I'm using Windows 7 and TDM GCC. I can't shrink the code, but here:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <complex>
#include <iostream>
#include <cmath>

long double Zoom;
std::complex<long double> Center;
sf::RenderWindow Window;
sf::Image Mandelbrot;
const unsigned int MaxIterations = 65536;

int main(){
    Window.Create(sf::VideoMode(300, 200, 32), "Mandelbrot Set", sf::Style::Close);
    Mandelbrot.Create(300, 200);
    Mandelbrot.SetSmooth(false);
    Zoom = 1.0;
    Center = std::complex<long double>(0.0, 0.0);
    sf::Event Event;
    bool BackToStart;
    beginning:
    BackToStart = false;
    for (long double CurY = 0; CurY < 200 && Window.IsOpened(); CurY++){
        for (long double CurX = 0; CurX < 300 && Window.IsOpened(); CurX++){
            std::complex<long double> C(Center.real() + (CurX/100.0 - 1.5)/Zoom, Center.imag() + (CurY/100.0 - 1.0)/Zoom);
            std::complex<long double> Z(0.0, 0.0);
            unsigned int Iteration = 0;
            long double P = sqrt(pow(C.real()-0.25, 2.0)+pow(C.imag(), 2.0));
            if (C.real() < P - 2.0*pow(P, 2.0) + 0.25 || pow(C.real()+1.0, 2.0)+pow(C.imag(), 2.0) < 0.0625)
                Iteration = MaxIterations;
            else while (Z.real()*Z.real() + Z.imag()*Z.imag() <= 4.0 && Iteration < MaxIterations){
                Z = pow(Z, 2)+C;
                Iteration += 1;
            }
            if (Iteration == MaxIterations)
                Mandelbrot.SetPixel(CurX, CurY, sf::Color(0, 0, 0));
            else
                Mandelbrot.SetPixel(CurX, CurY, sf::Color((Iteration&0xFF0000)>>16, (Iteration&0xFF00)>>8, (Iteration&0xFF)));
        }
        while (Window.GetEvent(Event)){
            if (Event.Type == sf::Event::Closed)
                Window.Close();
            else if (Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left){
                long double NewX = Center.real() + (Event.MouseButton.X/100.0 - 1.5)/Zoom;
                long double NewY = Center.imag() + (Event.MouseButton.Y/100.0 - 1.0)/Zoom;
                Center = std::complex<long double>(NewX, NewY);
                Zoom *= 2;
                BackToStart = true;
            }
        }
        Window.Draw(sf::Sprite(Mandelbrot));
        Window.Display();
        if (BackToStart)
            break;
        std::cout << "Row " << CurY << " finished.\n";
    }
    if (BackToStart)
        goto beginning;
    while (Window.IsOpened()){
        while (Window.GetEvent(Event)){
            if (Event.Type == sf::Event::Closed)
                Window.Close();
            else if (Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left){
                long double NewX = Center.real() + (Event.MouseButton.X/100.0 - 1.5)/Zoom;
                long double NewY = Center.imag() + (Event.MouseButton.Y/100.0 - 1.0)/Zoom;
                Center = std::complex<long double>(NewX, NewY);
                Zoom *= 2;
                BackToStart = true;
            }
        }
        if (BackToStart)
            break;
    }
    if (BackToStart)
        goto beginning;
    Mandelbrot.SaveToFile("Mandelbrot.png");
    return EXIT_SUCCESS;
}

75 lines of code to generate a Mandelbrot and zoom in on a position that you click. Not bad, I think!
Title: Code Generated Image does not display on Windows
Post by: gsaurus on January 31, 2010, 02:47:15 am
weird.
I tried the code and it runs fine here. Windows XP, compiled with C::B (MinGW)

PS1: I love fractals  :D
PS2: I didn't see goto statements on C++ for a while!
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on January 31, 2010, 03:04:18 am
Quote from: "gsaurus"
weird.
I tried the code and it runs fine here. Windows XP, compiled with C::B (MinGW)

PS1: I love fractals  :D
PS2: I didn't see goto statements on C++ for a while!
You're using plain MinGW? Ok, it may be a TDM GCC problem. Going to try installing regular MinGW and testing.
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on January 31, 2010, 06:57:55 am
Tested with regular MinGW. Didn't work. It's a Win7 problem. Going to try updating drivers.
Title: Code Generated Image does not display on Windows
Post by: Imbue on February 01, 2010, 05:59:33 am
I also tested it. Works fine with MinGW, g++ 4.4.0 on Vista (although it's very slow).
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 02, 2010, 01:52:27 am
Alright, tried to install 4.4.0 of MinGW. Get the libgmp-3.dll entry point error. D= Anyone know a fix so I can test this one last compiler before blaming Windows 7?
Title: Code Generated Image does not display on Windows
Post by: Imbue on February 03, 2010, 12:50:56 am
Yeah, there is a package you need to download for that. Read the notes here for everything to download:

http://sourceforge.net/projects/mingw/files/GCC%20Version%204/Current%20Release_%20gcc-4.4.0/gcc-4.4.0-mingw32-notes.txt/download

It sounds like SFML or OpenGL has a Windows 7 problem though.
Title: Code Generated Image does not display on Windows
Post by: Dravere on February 03, 2010, 07:31:04 pm
Tried the code on Win7 64 Bit with TDM MinGW 4.4.1:
(http://img23.imageshack.us/img23/7545/mandelbrot.png)

Works like a charm. Well the points are perhaps a bit small. ;)
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 04, 2010, 01:38:21 am
Quote from: "Dravere"
Tried the code on Win7 64 Bit with TDM MinGW 4.4.1:
(http://img23.imageshack.us/img23/7545/mandelbrot.png)

Works like a charm. Well the points are perhaps a bit small. ;)
Yes, the screen is a little small. However, you can click on a point to zoom in.
Sadly, it does appear that this is a problem with my system, since others do not have this problem.
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 13, 2010, 07:05:50 am
Updated to Build 1404. It is most likely a driver error, but it still is not working. D:
Title: Code Generated Image does not display on Windows
Post by: Xeon06 on February 13, 2010, 03:46:38 pm
Can you draw other things like loaded images, text or shapes?
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 13, 2010, 10:45:01 pm
Quote from: "Xeon06"
Can you draw other things like loaded images, text or shapes?
Yes, and I can draw texture-free images with OpenGL just fine. However, if I try to bind a SFML Image then Draw(with TexCoords), it draws nothing. :S
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 13, 2010, 11:06:12 pm
...
It's been fixed. How? I upgraded from the Win7 RC to the RTM.
Title: Code Generated Image does not display on Windows
Post by: OniLinkPlus on February 20, 2010, 01:33:49 am
Update that I forgot to post: It seems that when I applied latest Windows Updates, sf::Sprite Rendering works but smashes the image to the top so it's only one row of pixels. Raw GL Rendering works.