SDL_Surface* Font::renderText( std::string text ) const
{
int width = this->getWidth( text );
SDL_Surface* surface = SDL_CreateRGBSurface( SDL_SRCCOLORKEY,
width, chars[0].h,
bitmap->format->BitsPerPixel,
bitmap->format->Rmask,
bitmap->format->Gmask,
bitmap->format->Bmask,
0 );
int current_char = 0;
SDL_Rect rect;
rect.x = 0;
rect.y = 0;
while( current_char < text.length() ) {
SDL_BlitSurface( bitmap, &chars[text[current_char]], surface, &rect );
rect.x += chars[text[current_char]].w;
current_char++;
}
return surface;
}
Compiling: font.cpp
E:\Programming\Base-Devel-Physics\font.cpp: In member function `SDL_Surface* Font::renderText(std::string) const':
E:\Programming\Base-Devel-Physics\font.cpp:93: error: invalid conversion from `const SDL_Rect*' to `SDL_Rect*'
E:\Programming\Base-Devel-Physics\font.cpp:93: error: initializing argument 2 of `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*)'
.. Ugh
I need Font::renderText() to be const, because I'm passing constant references of Font objects in certain functions that use this function. Theoretically, a renderText() function that renders to a extranous surface and returns that should be totaly okay with being const. I don't quite understand what I'm doing wrong.