#include <SDL.h>
#include <SDL_ttf.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Texture* texture;
int mWidth;
int mHeight;
SDL_Window* window = NULL;
SDL_Renderer* ren = NULL;
TTF_Font *font = NULL;
int main( int argc, char* args[] )
{
SDL_Init( SDL_INIT_VIDEO );
window = SDL_CreateWindow( "test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
ren = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
SDL_SetRenderDrawColor( ren, 0xFF, 0xFF, 0xFF, 0xFF );
TTF_Init();
font = TTF_OpenFont( "lazy.ttf", 28 );
SDL_Color textColor = { 0, 0, 0 };
SDL_Surface* textSurface = TTF_RenderText_Solid( font, "test", textColor );
texture = SDL_CreateTextureFromSurface( ren, textSurface );
mWidth = textSurface->w;
mHeight = textSurface->h;
SDL_FreeSurface( textSurface );
bool quit = false;
SDL_Event e;
while( !quit )
{
while( SDL_PollEvent( &e ) != 0 )
{
if( e.type == SDL_QUIT )
{
quit = true;
}
}
SDL_SetRenderDrawColor( ren, 0, 0xFF, 0xFF, 0xFF );
SDL_RenderClear( ren );
int w = (SCREEN_WIDTH - mWidth) / 2;
int h = (SCREEN_HEIGHT - mHeight ) / 2;
SDL_Rect renderQuad = { w, h, mWidth, mHeight};
SDL_RenderCopyEx( ren, texture, 0, &renderQuad, 0.0, 0,SDL_FLIP_NONE );
SDL_RenderPresent( ren );
}
TTF_CloseFont(font);
font = NULL;
SDL_DestroyRenderer( ren );
SDL_DestroyWindow( window );
window = NULL;
ren = NULL;
TTF_Quit();
SDL_Quit();
}
|