hello,
i would like to use SFML in a project on my mac, because i liked the provided functionality and the clean C++ style.
i downloaded the full SDK v.15 but i can't get my simple example working (based on the c++ tool / cmdline SFML xcode template).
my system:
mac book pro, macosx v10.5.8
architecture: intel
gfx: nvidia 8600m gt
IDE: xcode 3.0
here is the code of my simple example:
#include <cstdio>
#include <string>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics.hpp>
//#include <SFML/System.hpp>
#include "config_sensorvis.hpp"
int main()
{
//allocate resources
std::string fontFilename("arial.ttf");
sf::Font font;
if (!font.LoadFromFile(fontFilename, 50))
{
printf("[ERROR] could NOT load font %s\n", fontFilename.c_str());
//return EXIT_FAILURE;
}
else
{
font = sf::Font::GetDefaultFont();
}
//setup
sf::WindowSettings settings;
settings.DepthBits = 24;
settings.StencilBits = 8;
settings.AntialiasingLevel = 0;
sf::RenderWindow app(sf::VideoMode(640, 480, 32), APP_TITLE /*, sf::Style::Close, settings*/);
//app.UseVerticalSync(false);
//app.SetFramerateLimit(60); // Limit to 60 frames per second
//app.SetFramerateLimit(0); // No limit
app.PreserveOpenGLStates(true);
app.SetPosition(0, 0);
/*sf::View view;
app.SetView(view);*/
//timer
sf::Clock clock;
sf::Event event;
const sf::Input& input = app.GetInput();
//main loop
while (app.IsOpened())
{
//timing update - get elapsed time since last loop
float dt = clock.GetElapsedTime();
clock.Reset();
float framerate = 1.f / clock.GetElapsedTime();
unsigned int mouseX = input.GetMouseX();
unsigned int mouseY = input.GetMouseY();
while (app.GetEvent(event))
{
//process all events from message queue ...
if (event.Type == sf::Event::Closed)
{
app.Close();
}
else
if (event.Type == sf::Event::KeyPressed)
{
if (event.Key.Code == sf::Key::Escape)
{
app.Close();
}
else
if (event.Key.Code == sf::Key::F1)
{
sf::Image screen = app.Capture();
screen.SaveToFile("screenshot.jpg");
}
}
else
if (event.Type == sf::Event::Resized)
{
// glViewport(0, 0, event.Size.Width, event.Size.Height);
}
else
{
printf("[WARNING] uncatched event\n");
}
}
//render
app.SetActive();
app.Clear(sf::Color(255, 0, 0));
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glColor3f(255.f, 0.f, 0.f);
glBegin(GL_QUADS);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);
glEnd();
//render hud
sf::String fps;
fps.SetText("fps: ");
fps.SetFont(font);
fps.SetSize(50);
fps.SetColor(sf::Color(128, 128, 0));
//fps.SetRotation(90.f);
//fps.SetScale(2.f, 2.f);
fps.Move(100.f, 200.f);
app.Draw(fps);
app.Display();
}
app.Close();
return EXIT_SUCCESS;
}
i launch the example and after a short while gdb receives a EXC_BAD_ACCESS signal from "sf::RenderTarget::Clear" and then i only see assembler code (why? i don't strip the symbols as far as i can see and the source comes with the full SDK) in the debugger. so i don't know what is wrong with it. when i comment the SetActive() Clear() or Draw(text) functions of the RenderWindow object it works, but of course i don't see anything then ... maybe there is a problem with the window settings (resolution, depth, ...)? does anybody have any idea?
thanks in advance,
didi