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

Author Topic: OSX build displays strange results. [C++,OSX]  (Read 2792 times)

0 Members and 1 Guest are viewing this topic.

jakobnator

  • Newbie
  • *
  • Posts: 8
    • View Profile
OSX build displays strange results. [C++,OSX]
« on: February 03, 2014, 07:40:29 pm »
I have a macbook that I use for school and I am trying to get SFML to work for it but I don't consider myself an expert in xcode or OSX. I copied the code and images from my game and it builds, it doesn't load images though. However I get a strange result. (It also flashes in a siezure inducing manner)

Has anyone else ever had this problem is there something I need to do to my code in osx that doesn't need to be done in windows?

Here is my code sorry its not very well documented.

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
        using namespace sf;
        using namespace std;
        RenderWindow window;
        window.create(VideoMode(800, 600), "Red vs. Green Peppers", Style::Close);
   
        Texture tGreenpepper;
        if (tGreenpepper.loadFromFile("Assets/Greenpepper.png"))
                cout << "Loaded Greenpepper.png" << endl;
   
        Texture tRedpepper;
        if (tRedpepper.loadFromFile("Assets/Redpepper.png"))
                cout << "Loaded Redpepper.png" << endl;
   
        Texture tBoard;
        if (tBoard.loadFromFile("Assets/Board.png"))
                cout << "Loaded Board.png" << endl;
   
        Texture tMenu;
        if (tMenu.loadFromFile("Assets/Menu.png"))
                cout << "Loaded Menu.png" << endl;
   
        bool bFilled[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        bool bMenudebounce = false;
        int iTurns = 1;
   
        Sprite sPlaceholder;
        Sprite sBoard[9];
        Sprite sBackground;
        Sprite sMenu;
        sBackground.setTexture(tBoard);
        sMenu.setTexture(tMenu);
        // main loop
        while (window.isOpen())
        {
                if (iTurns % 2 == 0){
                        sPlaceholder.setTexture(tGreenpepper);
                }
                else{
                        sPlaceholder.setTexture(tRedpepper);
                }
                Event Event;
                while (window.pollEvent(Event))
                {
           
                        switch (Event.type)
                        {
                case Event::Closed:
                    window.close();
                    break;
                case Event::KeyReleased:
                    switch (Event.key.code)
                                {
                    case Keyboard::Return:
                        bMenudebounce = true;
                        break;
                    case Keyboard::Numpad1:
                        if (bFilled[0] == false && bMenudebounce == true){
                            bFilled[0] = true;
                            sBoard[0] = sPlaceholder;
                            sBoard[0].setPosition(10, 405);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad2:
                        if (bFilled[1] == false && bMenudebounce == true){
                            bFilled[1] = true;
                            sBoard[1] = sPlaceholder;
                            sBoard[1].setPosition(270, 407);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad3:
                        if (bFilled[2] == false && bMenudebounce == true){
                            bFilled[2] = true;
                            sBoard[2] = sPlaceholder;
                            sBoard[2].setPosition(548, 407);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad4:
                        if (bFilled[3] == false && bMenudebounce == true){
                            bFilled[3] = true;
                            sBoard[3] = sPlaceholder;
                            sBoard[3].setPosition(10, 205);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad5:
                        if (bFilled[4] == false && bMenudebounce == true){
                            bFilled[4] = true;
                            sBoard[4] = sPlaceholder;
                            sBoard[4].setPosition(270, 207);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad6:
                        if (bFilled[5] == false && bMenudebounce == true){
                            bFilled[5] = true;
                            sBoard[5] = sPlaceholder;
                            sBoard[5].setPosition(548, 207);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad7:
                        if (bFilled[6] == false && bMenudebounce == true){
                            bFilled[6] = true;
                            sBoard[6] = sPlaceholder;
                            sBoard[6].setPosition(10, 10);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad8:
                        if (bFilled[7] == false && bMenudebounce == true){
                            bFilled[7] = true;
                            sBoard[7] = sPlaceholder;
                            sBoard[7].setPosition(270, 10);
                            iTurns++;
                        }
                                                break;
                    case Keyboard::Numpad9:
                        if (bFilled[8] == false && bMenudebounce == true){
                            bFilled[8] = true;
                            sBoard[8] = sPlaceholder;
                            sBoard[8].setPosition(548, 10);
                            iTurns++;
                        }
                                                break;
                    default:
                        break;
                                }
                        }
                }
                if (bMenudebounce == false){
                        window.draw(sMenu);
                }
       
                if (bMenudebounce == true){
                        window.draw(sBackground);
                        window.draw(sBoard[0]);
                        window.draw(sBoard[1]);
                        window.draw(sBoard[2]);
                        window.draw(sBoard[3]);
                        window.draw(sBoard[4]);
                        window.draw(sBoard[5]);
                        window.draw(sBoard[6]);
                        window.draw(sBoard[7]);
                        window.draw(sBoard[8]);
           
                }
        window.display();
        }
        return 0;
}
 

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: OSX build displays strange results. [C++,OSX]
« Reply #1 on: February 03, 2014, 08:36:16 pm »
Why is this in the CSFML sub forum?
Anyways where is the call to clear?
« Last Edit: February 03, 2014, 09:42:39 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

jakobnator

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: OSX build displays strange results. [C++,OSX]
« Reply #2 on: February 04, 2014, 02:49:41 am »
Thanks, I guess window.clear() isn't necessary in windows all the time? However it still isn't loading any of the images. Are directories different from windows e.g. Assets/image.png

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Re: OSX build displays strange results. [C++,OSX]
« Reply #3 on: February 04, 2014, 08:06:26 am »
Thanks, I guess window.clear() isn't necessary in windows all the time?
It is necessary, it's how SFML work: clear, draw, display.

However it still isn't loading any of the images. Are directories different from windows e.g. Assets/image.png
Files get searched in the working directory. This is the directory the application is called from or some IDEs let you set it specifically.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jakobnator

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: AW: Re: OSX build displays strange results. [C++,OSX]
« Reply #4 on: February 04, 2014, 02:32:08 pm »

However it still isn't loading any of the images. Are directories different from windows e.g. Assets/image.png
Files get searched in the working directory. This is the directory the application is called from or some IDEs let you set it specifically.
[/quote]


I have the files in the working directory I placed it in all the folders through process of elimination and still none of them load, are OSX directories different \ instead of / perhaps?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: OSX build displays strange results. [C++,OSX]
« Reply #5 on: February 04, 2014, 02:48:12 pm »
Looks like I missed the OS X part in the title. ;)

Well on OS X things usually work a bit different, afaik. I think usually one goes with some ResourcePath header file, but since I've no idea about OS X development, you can either wait till someone more knowledgeable comes around or google for it. I think we should even have a discussion somewhere around here.

And no, you should always use forward slashes.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jakobnator

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: OSX build displays strange results. [C++,OSX]
« Reply #6 on: February 04, 2014, 04:00:13 pm »
I added the Resourcepath.hpp and Resourcepath.mm from the Xcode template which can load images using the format

icon.loadFromFile(resourcePath() + "icon.png")

which doesn't work. I did some googling on the SFML forum and all the links lead to a dead thread or saying use the full directory  home/user/documents/ etc.....
which doesn't work.

jakobnator

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: OSX build displays strange results. [C++,OSX]
« Reply #7 on: February 04, 2014, 05:20:53 pm »
I fixed it, make sure they are in the same path relative to the .app file.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: OSX build displays strange results. [C++,OSX]
« Reply #8 on: February 09, 2014, 12:43:25 pm »
Re-read the end of the getting started tutorial for OS X, you'll find a part explaining how to add resource to your project.
SFML / OS X developer

 

anything