See the code below. I’ve tried many things (not shown) to get the surface “textSurface” to display but I haven’t done it yet. I believe it must be simple. Will somebody show me how.
TIA. Bill S.
Code:
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
int main( int argc, char* args[] ){
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win1 = NULL;
win1 = SDL_CreateWindow("", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer* ren1 = SDL_CreateRenderer(win1, -1, 0);
SDL_SetRenderDrawColor(ren1, 255, 255, 255, 255);
SDL_RenderClear(ren1); // fill the screen with white
TTF_Init();
TTF_Font* font = TTF_OpenFont("/usr/share/fonts/truetype/msttcorefonts/arial.ttf", 12);
SDL_Color foregroundColor = { 0, 0, 0 };
SDL_Color backgroundColor = { 0, 0, 255 };
SDL_Surface* textSurface = TTF_RenderText_Shaded(font, “This is my text.”, foregroundColor, backgroundColor);
if (textSurface == NULL)
printf("\n\n failed to create surface \n\n");
SDL_Texture *tex1 = NULL;
tex1 = SDL_CreateTextureFromSurface(ren1,textSurface);
SDL_UpdateWindowSurface(win1);
SDL_Delay(5000);
SDL_RenderPresent(ren1);
SDL_Delay(5000);
SDL_FreeSurface(textSurface);
TTF_CloseFont(font);
TTF_Quit();
SDL_DestroyWindow(win1);
SDL_DestroyRenderer(ren1);
SDL_Quit();
return 0;
}
[/code]