Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#ifndef FONT_HPP #define FONT_HPP #include "SDL_ttf.h" #include "Menü.hpp" class CFont { public: CFont (); void Run (); private: TTF_Font *font; SDL_Color textColor; SDL_Surface *m_pScreen; SDL_Surface *message; void load (); void Render (); void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ); void Quit (); };#endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include "Font.hpp" CFont::CFont (){ SDL_Surface *message = NULL; TTF_Font *font = NULL; SDL_Color textColor = { 255, 255, 255 }; m_pScreen = g_pFramework->GetScreen ();}void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ) { SDL_Rect offset;//Get offsets offset.x = x; offset.y = y;//Blit SDL_BlitSurface( source, clip, destination, &offset );}void CFont::load () { if( TTF_Init() == -1 ) { exit (0); } //Open the font font = TTF_OpenFont( "lazy.ttf", 28 ); //If there was an error in loading the font if( font == NULL ) { exit (0); }}void CFont::Render () { //Render the text message = TTF_RenderText_Solid( font, "(1) Starten", textColor ); //If there was an error in rendering the text if( message == NULL ) { exit (0); }//Apply the images to the screen apply_surface( 0, 150, message, m_pScreen );//Update the screen if( SDL_Flip( m_pScreen ) == -1 ) { exit (0); }}void CFont::Run () { load (); Render ();}void CFont::Quit () { SDL_FreeSurface( message );//Close the font that was used TTF_CloseFont( font );//Quit SDL_ttf TTF_Quit();} |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
/**
Once you are done trying to ‘optimize’ this routine,
and have realized what a terrible mistake that was,
please increment the following counter as a warning
to the next guy:
total_hours_wasted_here = 11
*/
|
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ) { SDL_Rect offset; //Get offsets offset.x = x; offset.y = y; //Blit SDL_BlitSurface( source, clip, destination, &offset ); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 |
void CFont::apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ) { SDL_Rect offset; //Get offsets offset.x = x; offset.y = y; //Blit SDL_BlitSurface( source, clip, destination, &offset ); } |
Community-Fossil
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
TTF_Init(); ... CFont font(file, size);//font aus datei laden ... while(is_game_run) { ... font.Render(x,y, text);//Surface erzeugen, blitten, freigeben ... SDL_Flip(screen); //Puffer umschalten } ... TTF_Quit(); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
/**
Once you are done trying to ‘optimize’ this routine,
and have realized what a terrible mistake that was,
please increment the following counter as a warning
to the next guy:
total_hours_wasted_here = 11
*/
|
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »xXSlayerXx« (26.12.2012, 21:55)
Community-Fossil
weiß da jemand um rat?
Werbeanzeige