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

Author Topic: Getting Background On  (Read 1973 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Getting Background On
« on: September 02, 2010, 03:31:34 am »
Hey,

I've been trying to put a background into my program that has three "layers".

The top layer is the "default view" (GetDefaultView). It has my text on it.
The middle layer is the layer that I printed a map onto. (View)
The back layer is the layer I want to print a background onto. (BackG) I feel like I'm doing it correctly, but obviously not.

Here is all of the code relating to the declaration, adjustment, and displaying of those layers:
Code: [Select]
sf::Image BackImage;
    if (!BackImage.LoadFromFile("Pheonix.bmp"))
        return EXIT_FAILURE;
    sf::Sprite BackG(BackImage);

    sf::Image IconImage;
    if (!IconImage.LoadFromFile("TH Icon.bmp"))
        return EXIT_FAILURE;
    sf::Sprite Icon(IconImage);

sf::RenderWindow App(sf::VideoMode::GetMode(0), "Laz's Interactive Map :: The Wrath... :: PvP Created");
    App.SetIcon(64,64,IconImage.GetPixelsPtr());


sf::Shape MapPh;
    MapPh.AddPoint(0,0,sf::Color(0,100,0));
    MapPh.AddPoint(9000,0,sf::Color(0,100,0));
    //MapPh.AddPoint(3500,1500,sf::Color(0,125,0));
    MapPh.AddPoint(9000,3000,sf::Color(0,100,0));
    MapPh.AddPoint(0,3000,sf::Color(0,100,0));
    MapPh.EnableFill(true);
    MapPh.EnableOutline(false);
    MapPh.SetOutlineWidth(10);

    sf::Shape PhMid = sf::Shape::Line(3000, 0, 3000, 3000, 20, sf::Color::Black);
    sf::Shape DrMid = sf::Shape::Line(6000, 0, 6000, 3000, 20, sf::Color::Black);
    sf::Shape HorMid = sf::Shape::Line(0, 1500, 9000, 1500, 20, sf::Color::Black);

    sf::Vector2f Center(4500, 1500);
    sf::Vector2f HalfSize(2250, 750);
    sf::View View(Center, HalfSize);
    View.Zoom(0.35f);

    sf::Vector2f CenterBack(960, 540);
    sf::Vector2f HalfBack(480, 270);
    sf::View Background(CenterBack, HalfBack);


App.SetView(Background);

            App.Draw(BackG);

        App.SetView(View);

            App.Clear();

            App.Draw(MapPh);
            App.Draw(PhMid);
            App.Draw(DrMid);
            App.Draw(HorMid);

        // Reset to the default view to draw the interface
        App.SetView(App.GetDefaultView());

            App.Draw(TopLeft);

            if (help == true)
                App.Draw(Help);
            else
                App.Draw(Main);

                App.Draw(Coord);
                if (X == true)
                    App.Draw(Comma);

            App.Draw(CopyRight);

            sf::Vector2f CursorPos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
            Cursor.SetPosition(CursorPos);
            App.Draw(Cursor);

            App.Display();


Any help will be greatly appreciated.

==================================
EDIT: The problem is that the background won't display. The top two layers display fine, but the background is black instead of have the desired picture on it.
-Wander

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Re: Getting Background On
« Reply #1 on: September 02, 2010, 11:20:56 am »
Simple answer ;)
Code: [Select]
...
App.SetView(Background);
            App.Draw(BackG);
        App.SetView(View);
            App.Clear();   !!!!!!!! DON'T DO THAT !!!!!!
            App.Draw(MapPh);
            App.Draw(PhMid);
            App.Draw(DrMid);
            App.Draw(HorMid);
...

If you had tried to do a simple and minimal code, I'm sure you'll have found the solution alone !
Mindiell
----

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Getting Background On
« Reply #2 on: September 03, 2010, 11:44:55 pm »
Oh okay thanks.
-Wander