I'm new to SFML (and external libraries in general - I messed around with OpenGL and GLUT for awhile, but it was long ago and I only ever messed around with shapes), so maybe I just have an error that I can't see, but my compiler (Xcode 5) isn't picking up any errors. Here's the code:
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "ResourcePath.hpp"
usingnamespace sf;
int main()
{
RenderWindow window(VideoMode(800, 600), "Name here", Style::Default);
window.setVerticalSyncEnabled(true);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
{
window.close();
}
}
window.clear(Color::Black);
//Draw everything here
Font font;
if (!font.loadFromFile("Arial.ttf"))
{
//Nothing goes here...?
}
Text text;
text.setFont(font);
text.setString("Hello World");
text.setCharacterSize(24);
text.setColor(Color::White);
window.draw(text);
window.display();
}
return 0;
}
I tried Googling the question, but 90% of what came up were answers like "You didn't set a font, that's why the text isn't being displayed." But I set a font, and I included it in my Resources folder. Maybe I've just defined everything in the wrong place??
The program doesn't know to look in your resources folder. Whenever you give a filename without a full path, it looks first in the current directory.
This directory is usually the same directory as the exe. Though in some IDEs (like VS), when you run from the IDE the directory is configurable, and it'll default to the project directory.
If you're on Windows... you can do this to see the current directory:
1 2 3 4
// be sure to #include <Windows.h> .. at least temporarily
char path[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH,path);
MessageBoxA(NULL,path,"Current Directory",MB_OK);