Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[SFML] Słaba jakość napisów

Ostatnio zmodyfikowano 2012-06-10 20:29
Autor Wiadomość
pawajoro
Temat założony przez niniejszego użytkownika
[SFML] Słaba jakość napisów
» 2012-06-10 19:27:09
Jest kod w SFML:
C/C++
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <fstream>
#include <sstream>
#include <iostream>
#include <windows.h>

using namespace sf;
using namespace std;

const sf::Unicode::Text ZnakiPL()
{
    std::wstring znaki;
    znaki = L"abcdefghijklmnopqrstuvwxyz";
    znaki += L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    znaki += L"0123456789";
    znaki.append( L"ąćęłńóśźż" );
    znaki.append( L"ĄĆĘŁŃÓŚŹŻ /" );
    //tu można dopisać jeszcze inne znaki, które chcemy mieć zaimportowane
    return znaki;
}

sf::Image GetInvertedImage( sf::Image sprite )
{
    int hcount = 0;
    int wcount = 0;
    int width = sprite.GetWidth();
    int height = sprite.GetHeight();
    Color pixel;
    Image target( width, height );
    do
    {
        wcount = 0;
        do
        {
            pixel = sprite.GetPixel( wcount, hcount );
            target.SetPixel( wcount,( height - hcount - 1 ), pixel );
            wcount++;
        } while( wcount <= width );
       
        hcount++;
    } while( hcount <= height );
   
    return target;
}

sf::Image GetFullImage( sf::Sprite sprite )
{
    int hcount = 0;
    int wcount = 0;
    int width =( sprite.GetSize() ).x;
    int height =( sprite.GetSize() ).y;
    Color pixel;
    Image target( width, height );
    do
    {
        wcount = 0;
        do
        {
            pixel = sprite.GetPixel( wcount, hcount );
            target.SetPixel( wcount, hcount, pixel );
            wcount++;
        } while( wcount <= width );
       
        hcount++;
    } while( hcount <= height );
   
    return target;
}

int main()
{
    sf::RenderWindow oknoAplikacji;
    sf::Image obrazekdoc( 434, 180, Color( 0, 0, 0, 255 ) );
    oknoAplikacji.Create( sf::VideoMode( 434, 180, 32 ), "Kuidland 2.0 Obrazek" );
    oknoAplikacji.Clear( sf::Color( 255, 255, 255, 0 ) );
    sf::Image obrazekzr;
    sf::Image screen;
    sf::IntRect SourceRect = IntRect( 0, 0, 0, 0 );
    obrazekzr.LoadFromFile( "C:\\Kuidland\\data\\images\\PTT.png" );
    obrazekdoc.Copy( obrazekzr, 0, 0, SourceRect, true );
    obrazekzr.LoadFromFile( "C:\\Kuidland\\data\\images\\2009.png" );
    obrazekdoc.Copy( obrazekzr, 0, 0, IntRect( 0, 0, 0, 0 ), true );
    obrazekzr.LoadFromFile( "C:\\Kuidland\\data\\images\\line.png" );
    obrazekdoc.Copy( obrazekzr, 0, 0, IntRect( 0, 0, 0, 0 ), true );
    Sprite naszSprajt;
    naszSprajt.SetImage( obrazekdoc );
    naszSprajt.SetPosition( 0, 0 );
    Vector2f vector = naszSprajt.GetSize();
    float x = vector.x, y = vector.y;
    //while (true)
    {
        oknoAplikacji.Clear( sf::Color( 255, 255, 255 ) );
        sf::Font mojaCzcionka;
        mojaCzcionka.LoadFromFile( "C:\\Kuidland\\data\\verdana.ttf", 60, ZnakiPL() );
        sf::String name( L"Kurs SFML ba be bu bi by ebo" );
        name.SetFont( mojaCzcionka );
        name.SetSize( 14 );
        sf::RenderWindow ot;
        int wi =(( name.GetRect() ).GetWidth() );
        cout << wi;
        getchar();
        Image minitezt( wi,( name.GetRect() ).GetHeight(), Color( 0, 0, 0, 255 ) );
        ot.Create( sf::VideoMode((( name.GetRect() ).GetWidth() ),( name.GetRect() ).GetHeight(), 32 ), "Kuidland 2.0 Obrazek" );
        ot.Draw( name );
        minitezt.CopyScreen( ot, IntRect( 0, 0, 0, 0 ) );
        minitezt.SaveToFile( "C:\\Kuidland\\minitezt.png" );
        Image invtezt = GetInvertedImage( minitezt );
        obrazekdoc.Copy( invtezt,( 431 - wi ), 3, IntRect( 0, 0, 0, 0 ), true );
        invtezt.SaveToFile( "C:\\Kuidland\\invtezt.png" );
        wstring autorstr = L"autor: ";
        autorstr.append( L"Pawajoro" );
        sf::String autor( autorstr );
        mojaCzcionka.LoadFromFile( "C:\\Kuidland\\data\\arial.ttf", 1020, ZnakiPL() );
        autor.SetSize( 7 );
        autor.SetFont( mojaCzcionka );
        wi =(( autor.GetRect() ).GetWidth() );
        cout << wi;
        getchar();
        minitezt = Image( wi,( autor.GetRect() ).GetHeight(), Color( 0, 0, 0, 255 ) );
        ot.Create( sf::VideoMode((( autor.GetRect() ).GetWidth() ),( autor.GetRect() ).GetHeight(), 32 ), "Kuidland 2.0 Obrazek" );
        ot.Draw( autor );
        minitezt.CopyScreen( ot, IntRect( 0, 0, 0, 0 ) );
        minitezt.SaveToFile( "C:\\Kuidland\\minitezt2.png" );
        invtezt = GetInvertedImage( minitezt );
        ot.Clear( Color( 0, 0, 0, 255 ) );
        ot.Draw( maryca );
        ot.Display();
        getchar();
        obrazekdoc.Copy( invtezt,( 431 - wi ), 26, IntRect( 0, 0, 0, 0 ), true );
        obrazekdoc.SaveToFile( "C:\\Kuidland\\obrazek.png" );
        oknoAplikacji.Display();
    }
    oknoAplikacji.Close();
    return 0;
}
A obrazek wygląda tak: http://naforum.zapodaj.net/164b9adf7f2f.png.html
O ile efekt string'a "name" jest dla mnie satysfakcjonujący, to "autor" już nie. A efekt powinien być przynajmniej taki: http://www.trainz.org/ptt/_download/infrastruktura/infra_perony_zmodernizowane01.jpg(oczywiście, pomijając obrazek w tle). Co należy zrobić, by mój wyglądał podobnie?
P-58187
Admixior
» 2012-06-10 20:29:31
hmm... ładujesz czcionkę w rozmiarze 60 a później ją brutalnie zmniejszasz do 14. Tracisz pixele i efekt mizerny.
Ładuj czcionki w rozmiarze takim jak chcesz użyć.
P-58205
« 1 »
  Strona 1 z 1