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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - NewbiZ

Pages: [1]
1
Feature requests / Outlined text
« on: June 25, 2008, 11:09:26 pm »
This is a quick and dirty implementation which only purpose is to show the result of the inner/outter trick.
You may have to add OpenGL.hpp & FontManager.hpp (from SFML sources headers) to your headers.

As Laurent said, it would be better to draw the outline offseted in each direction instead. Just some lines to change.

2
Feature requests / Outlined text
« on: June 25, 2008, 04:30:03 pm »
The simple inner/outter border trick seems to provide pretty nice results as long as the size is >=20.


Code: [Select]
#include <cstdlib>

#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include <SFML/Graphics/String.hpp>
#include <SFML/Graphics/FontManager.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/OpenGL.hpp>
#include <locale>

namespace sf { namespace ext
{
  class OutlinedString : public sf::String
  {
  public:
    OutlinedString(const std::string& Text, const std::string& Font = "", float Size = 32.f):
      String(Text, Font, Size) {}

    OutlinedString(const std::wstring& Text = L"", const std::string& Font = "", float Size = 32.f):
      String(Text, Font, Size) {}

  protected:
    virtual void Render(const RenderWindow& Window) const
    {
      // No text, no rendering :)
    if (GetText().empty())
        return;

    // Get the bitmap font from the font manager
    const priv::FontManager::Font& BitmapFont = priv::FontManager::GetInstance().GetBitmapFont(GetFont(), static_cast<unsigned int>(GetSize()));

    // Set the scaling factor to get the actual size
    float FactorX = GetScaleX() * GetSize() / BitmapFont.CharSize;
    float FactorY = GetScaleY() * GetSize() / BitmapFont.CharSize;
    GLCheck(glScalef(FactorX, FactorY, 1.f));

    // Bind the font texture
    BitmapFont.Texture.Bind();

    float X = 0;
    float Y = 0;

    // Draw the sprite
    glBegin(GL_QUADS);
    for (std::size_t i = 0; i < GetText().size(); ++i)
    {
        // Get the current character
        wchar_t c = GetText()[i];

        // Check if the character is in the charset
        std::map<wchar_t, priv::FontManager::Font::Character>::const_iterator It = BitmapFont.Characters.find(c);
        if (It == BitmapFont.Characters.end())
        {
            // No : add a space and continue to the next character
            X += GetSize();
            continue;
        }
        const priv::FontManager::Font::Character& CurChar = It->second;

        // Get the dimensions of the current character from font description
        const IntRect&   Rect       = CurChar.Rect;
        const FloatRect& Coord      = CurChar.Coord;
        const unsigned int AdvanceX = CurChar.Advance;
        const unsigned int AdvanceY = BitmapFont.CharSize;

        // Handle special characters
        switch (c)
        {
            case L' ' :  X += AdvanceX;        continue;
            case L'\n' : Y += AdvanceY; X = 0; continue;
            case L'\t' : X += AdvanceX * 4;    continue;
            case L'\v' : Y += AdvanceY * 4;    continue;
        }

        // Draw a textured quad for the current character
        glColor4f(0,0,0,1); //TODO: Make the outline color settable
       
        // Outter outline
        glTexCoord2f(Coord.Left,  Coord.Top);    glVertex2f(X + Rect.Left -1, Y + Rect.Top   -1 + AdvanceY);
        glTexCoord2f(Coord.Left,  Coord.Bottom); glVertex2f(X + Rect.Left -1, Y + Rect.Bottom+1 + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Bottom); glVertex2f(X + Rect.Right+1, Y + Rect.Bottom+1 + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Top);    glVertex2f(X + Rect.Right+1, Y + Rect.Top   -1 + AdvanceY);

        // Inner outline
        glTexCoord2f(Coord.Left,  Coord.Top);    glVertex2f(X + Rect.Left +1, Y + Rect.Top   +1 + AdvanceY);
        glTexCoord2f(Coord.Left,  Coord.Bottom); glVertex2f(X + Rect.Left +1, Y + Rect.Bottom-1 + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Bottom); glVertex2f(X + Rect.Right-1, Y + Rect.Bottom-1 + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Top);    glVertex2f(X + Rect.Right-1, Y + Rect.Top   +1 + AdvanceY);

        // Text
        glColor4f( GetColor().r, GetColor().g, GetColor().b, GetColor().a );
        glTexCoord2f(Coord.Left,  Coord.Top);    glVertex2f(X + Rect.Left,  Y + Rect.Top    + AdvanceY);
        glTexCoord2f(Coord.Left,  Coord.Bottom); glVertex2f(X + Rect.Left,  Y + Rect.Bottom + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Bottom); glVertex2f(X + Rect.Right, Y + Rect.Bottom + AdvanceY);
        glTexCoord2f(Coord.Right, Coord.Top);    glVertex2f(X + Rect.Right, Y + Rect.Top    + AdvanceY);

        // Advance to the next character
        X += AdvanceX;
    }
    glEnd();
    }
  };
}}

int main( int argc, char** argv )
{
  sf::RenderWindow app( sf::VideoMode( 800, 600 ), "Outlined text example" );
  app.SetBackgroundColor( sf::Color::Red );
  app.Show( true );
  app.SetCurrent();

  sf::ext::OutlinedString str( "Example outlined string", "classic.ttf", 40.f);
  str.SetColor( sf::Color::White );

  bool done=false;
  while (!done)
  {
   
    // =================================== <Events>
    sf::Event Event;
    while ( app.GetEvent(Event) )
      if (Event.Type == sf::Event::Closed)
        done = false;
    // =================================== </Events>

    // =================================== <Display>
    str.SetColor( sf::Color::White   );str.SetPosition( 10,  10 ); str.SetSize( 50.f ); app.Draw( str  );
    str.SetColor( sf::Color::Blue    );str.SetPosition( 10, 100 ); str.SetSize( 40.f ); app.Draw( str  );
    str.SetColor( sf::Color::Green   );str.SetPosition( 10, 200 ); str.SetSize( 30.f ); app.Draw( str  );
    app.Display();
    // =================================== </Display>
  }

  return EXIT_SUCCESS;
}




3
Feature requests / Outlined text
« on: June 25, 2008, 02:59:50 am »
Quote from: "Laurent"
You could also draw the text twice and slightly offsetted, to create a kind of shadow.

Example: http://newbiz.developpez.com/tutoriels/opengl/heightmap/#LVII-E
:)

4
Graphics / [Solved] Unwanted pixels showing up...
« on: June 24, 2008, 01:51:19 am »
Right after the loading of your image:
Code: [Select]
image->SetSmooth( false );

5
General discussions / SFML 1.3 -- sonames
« on: June 23, 2008, 04:16:16 pm »
Hey, I suggest the creation of a tool [used to generate an autotool config file [used to generate makefiles [used to generate gcc calls]]] ...

Oops, that was obviously ironic :>

Voting for make here too.
It's simpler (and widely known) for "the rest of us", those only willing to quickly build on linux without additionnal needs other than make.

6
General discussions / SFML 1.3 and OS X
« on: June 23, 2008, 03:59:20 pm »
Same here, waiting for the OSX release, and willing to help ;) Do not hesitate if you need any help or build/runtime feedbacks (mac intel on 10.5.3)
Good luck!

7
Graphics / PNG loader might be broken in 1.2
« on: June 21, 2008, 05:42:31 am »
Quote from: "quasius"
automatically grouping images together on one texture to reduce wasted white space
And binds! these are so time expensive!

8
Graphics / RenderWindow not showing OpenGL elements
« on: May 24, 2008, 11:19:23 pm »
I suppose the raised exception is a std::bad_alloc.

It seems you defined _DEBUG ( Project -> Properties -> C++ -> Preprocessor ) and linked release libs.

Pages: [1]