I just finished writing new TFont and TGlyph classes. You can find it in
files I included.
Now I can test in only on sempron 2500+, so I dont know I solved problem
or not…
There is a one strange thing - when I inits video like that:
screen = SDL_SetVideoMode (800, 600, 16, SDL_SWSURFACE | SDL_FULLSCREEN);
and use
SDL_UpdateRect (screen, 0, 0, 0, 0);
I have about 80 fps. But when I inits video like that:
screen = SDL_SetVideoMode (800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF |
SDL_FULLSCREEN);
and use
SDL_Flip (screen);
I have only 10 fps. Why? Maybe I’m doing something wrong?
Yeah, you are using a hardware buffer. Writing to a hardware buffer in
software is very slow. This is especially true when you are doing alpha
blending or any other operation that requires you to read from the
hardware buffer.
Also, does you hardware actually support a 16 bit video format? Did you
check to see that you are getting 16 bit format? And, are your images in
the same 16 bit format as your screen. If not, then SDL may be
converting your images on the fly and that will slow you way down.
Bob PendletonOn Tue, 2005-09-13 at 01:20 +0200, kds71 wrote:
Regards
Seks, zdrowie, uroda, praca… >>> http://link.interia.pl/f18b3
plain text document attachment (fontman.h)
#ifndef FONTMAN
#define FONTMAN
#include <stdio.h>
#include “sdl/sdl.h”
#include “sdl/sdl_ttf.h”
#include “tstring.h”
class TGlyph
{
private:
SDL_Surface *glyph_;
int width_;
int height_;
public:
~TGlyph ();
void assign (Uint16 c, TTF_Font *font, const SDL_Color &color);
void render (SDL_Surface *dest, SDL_Rect &rect) const;
int width () const;
int height () const;
};
class TFont
{
private:
TGlyph glyphs_[112];
TString *chars_;
int height_;
Uint16 unicode_ (char) const;
public:
TFont (const char *path, int size, const SDL_Color &color);
~TFont ();
void render (SDL_Surface *dest, int x, int y, const TString &text) const;
int width (const TString &text) const;
int height () const;
};
#endif
plain text document attachment (fontman.cpp)
#include “fontman.h”
// TGLYPH
void TGlyph::assign (Uint16 c, TTF_Font *font, const SDL_Color &color)
{
Uint16 text[2];
text[0] = c;
text[1] = 0;
glyph_ = TTF_RenderUNICODE_Blended (font, text, color);
width_ = glyph_->w;
height_ = glyph_->h;
}
TGlyph::~TGlyph ()
{
if (glyph_)
SDL_FreeSurface (glyph_);
}
void TGlyph::render (SDL_Surface *dest, SDL_Rect &rect) const
{
SDL_BlitSurface (glyph_, 0, dest, &rect);
rect.x += width_;
}
int TGlyph::width () const
{
return width_;
}
int TGlyph::height () const
{
return height_;
}
// TFONT
Uint16 TFont::unicode_ (char c) const
{
Uint16 x = static_cast ©;
if (c == ‘?’) x = 0x0105;
if (c == ‘?’) x = 0x0104;
if (c == ‘?’) x = 0x0107;
if (c == ‘?’) x = 0x0106;
if (c == ‘?’) x = 0x0119;
if (c == ‘?’) x = 0x0118;
if (c == ‘?’) x = 0x0142;
if (c == ‘?’) x = 0x0141;
if (c == ‘?’) x = 0x0144;
if (c == ‘?’) x = 0x0143;
if (c == ‘?’) x = 0x00f3;
if (c == ‘?’) x = 0x00d3;
if (c == ‘?’) x = 0x015b;
if (c == ‘?’) x = 0x015a;
if (c == ‘?’) x = 0x017a;
if (c == ‘?’) x = 0x0179;
if (c == ‘?’) x = 0x017c;
if (c == ‘?’) x = 0x017b;
return x;
}
TFont::TFont (const char *path, int size, const SDL_Color &color)
{
TTF_Font *font;
font = TTF_OpenFont (path, size);
if (!font)
{
fprintf (stderr, “Failed TTF_OpenFont: %s\n”, TTF_GetError ());
exit (1);
}
chars_ = new TString (" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`!@#$%^&*()-_=+\|[]{};:’",<.>/???");
for (int i = 0; i < 112; i++)
{
Uint16 c = unicode_ ((*chars_) [i]);
glyphs_[i].assign (c, font, color);
}
height_ = TTF_FontHeight (font);
TTF_CloseFont (font);
}
TFont::~TFont ()
{
delete chars_;
}
void TFont::render (SDL_Surface *dest, int x, int y, const TString &text) const
{
SDL_Rect tmp_rect = {x, y, 0, 0};
for (int i = 0; i < text.length (); i++)
{
int glyphno = chars_->pos (text[i]);
glyphs_[glyphno].render (dest, tmp_rect);
}
}
int TFont::width (const TString &text) const
{
int result = 0;
for (int i = 0; i < text.length (); i++)
{
int glyphno = chars_->pos (text[i]);
result += glyphs_[glyphno].width ();
}
return result;
}
int TFont::height () const
{
return height_;
}
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
–
±-------------------------------------+