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

Author Topic: Code Generated Image does not display on Windows  (Read 5456 times)

0 Members and 1 Guest are viewing this topic.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« 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.
I use the latest build of SFML2

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6272
  • Thor Developer
    • View Profile
    • Bromeon
Code Generated Image does not display on Windows
« Reply #1 on: January 31, 2010, 01:04:22 am »
Hm, could you show a minimal code example? What compiler and OS are you using?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #2 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!
I use the latest build of SFML2

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Code Generated Image does not display on Windows
« Reply #3 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!
Pluma - Plug-in Management Framework

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #4 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.
I use the latest build of SFML2

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #5 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.
I use the latest build of SFML2

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Code Generated Image does not display on Windows
« Reply #6 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).

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #7 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?
I use the latest build of SFML2

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Code Generated Image does not display on Windows
« Reply #8 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.

Dravere

  • Newbie
  • *
  • Posts: 37
    • View Profile
Code Generated Image does not display on Windows
« Reply #9 on: February 03, 2010, 07:31:04 pm »
Tried the code on Win7 64 Bit with TDM MinGW 4.4.1:


Works like a charm. Well the points are perhaps a bit small. ;)

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #10 on: February 04, 2010, 01:38:21 am »
Quote from: "Dravere"
Tried the code on Win7 64 Bit with TDM MinGW 4.4.1:


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.
I use the latest build of SFML2

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #11 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:
I use the latest build of SFML2

Xeon06

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Code Generated Image does not display on Windows
« Reply #12 on: February 13, 2010, 03:46:38 pm »
Can you draw other things like loaded images, text or shapes?

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #13 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
I use the latest build of SFML2

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Code Generated Image does not display on Windows
« Reply #14 on: February 13, 2010, 11:06:12 pm »
...
It's been fixed. How? I upgraded from the Win7 RC to the RTM.
I use the latest build of SFML2