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

Author Topic: [SFML 2.0] VS2008 Compile error  (Read 2411 times)

0 Members and 1 Guest are viewing this topic.

LA

  • Newbie
  • *
  • Posts: 5
    • View Profile
[SFML 2.0] VS2008 Compile error
« on: September 01, 2012, 10:11:50 pm »
Everything works fine, except sf::String. Its in constructor with wchar or something...

This code:
sf::Text text ( std::wstring(L"hello") , Font, 50 );
 

generate compiller error
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)"


my programm use cyrillic fonts, and i think in 2.0 using wchar is only way to proper render it.
In 1.6 ver you just need to set your own charset, like
std::wstring std_charset = L"russian letters :)";
sf::Font Font1;
Font1.LoadFromFile("some.ttf", 30, std_charset );
 

but in 2.0 i dont see this option. Maybe you rename it or some?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: [SFML 2.0] VS2008 Compile error
« Reply #1 on: September 01, 2012, 10:35:22 pm »
Are you mixing release and debug libraries?

As for the charset, I guess things have changed and it's not needed anymore, but then again I've not much experience with diffrent charsets and unicode strings. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0] VS2008 Compile error
« Reply #2 on: September 01, 2012, 11:21:21 pm »
Project settings > C++ > Language > Treat wchar_t as native type --> yes

Or, recompile SFML with this option disabled if you really need it (for example if you're using Qt).
Laurent Gomila - SFML developer

LA

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: [SFML 2.0] VS2008 Compile error
« Reply #3 on: September 02, 2012, 12:18:33 pm »
Project settings > C++ > Language > Treat wchar_t as native type --> yes

Yes! It works! Many many thanks :)
Russian letters also works perfect.

Goodbye SDL  ;D

LA

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: [SFML 2.0] VS2008 Compile error
« Reply #4 on: September 02, 2012, 08:24:59 pm »
So, in SFML 2.0 text drawing function will be like this:
Maybe it help others who have trouble with this )

...
setlocale(LC_ALL, "Russian");
...

wchar_t* MultiCharToUniChar(char* mbString)
{
  int len = 0;
  len = (int)strlen(mbString) + 1;
  wchar_t *ucString = new wchar_t[len];
  mbstowcs(ucString, mbString, len);
  return ucString;
}

void DrawText ( int x, int y, char *format, ... )
{
        char buffer[512];
        wchar_t *wbuffer = NULL;

        va_list msg;
        va_start(msg, format);
        vsnprintf(buffer, 512, format, msg);
        va_end(msg);

        wbuffer = MultiCharToUniChar ( buffer );

        sf::Text text ( wbuffer, YOUR_FONT, YOUR_FONT_SIZE );
        text.setPosition ( x, y );

        sfRenderWindow.pushGLStates();
        sfRenderWindow.draw ( text );
        sfRenderWindow.popGLStates();

              delete []wbuffer;
}
 

After that you can call it like this:

DrawText ( 10, 10, "SDL, давай, до свидания! also current fps: %0.f", MyGameFPSCounterFloat );


Still, its probably more harder than in 1.6 ver, because in 1.6 there is no need in wchar, thanx to "handmade" charsets.
« Last Edit: September 02, 2012, 08:34:29 pm by LA »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [SFML 2.0] VS2008 Compile error
« Reply #5 on: September 02, 2012, 08:53:02 pm »
Quote
Still, its probably more harder than in 1.6 ver, because in 1.6 there is no need in wchar, thanx to "handmade" charsets.
Nop. In SFML 2, charsets are just created dynamically on the fly. The behaviour is exactly the same, with a simpler API.

The encoding is a totally different thing. You would probably run into less problems by using wide string literals:
L"...russian characters..."

If you want to use locals, then your code can be improved to use C++ and SFML functions, rather than C ones.
std::locale::global(std::locale("Russian"));
...
sf::Text text("...russian characters...", YOUR_FONT, YOUR_FONT_SIZE );

Or

sf::String str("...russian characters...", std::locale("Russian"));
sf::Text text(str, YOUR_FONT, YOUR_FONT_SIZE);
« Last Edit: September 02, 2012, 08:54:46 pm by Laurent »
Laurent Gomila - SFML developer

 

anything