Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int loadTextureFromText(char *textureText, TTF_Font *textFont, SDL_Color textColor, WTexture *finalTexture, SDL_Renderer *renderer)
- {
- int retVal = 1;
- SDL_Texture *newTexture = NULL;
- SDL_Surface *textSurface = NULL;
- /* Free texture */
- freeTexture(finalTexture);
- /* Render text surface */
- textSurface = TTF_RenderText_Solid(textFont, textureText, textColor);
- if (textSurface == NULL)
- {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load text %s! SDL_ttf error: %s\n", textureText, TTF_GetError());
- retVal = 0;
- goto cleanup;
- }
- /* Create texture from surface */
- newTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
- if (newTexture == NULL)
- {
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create texture from %s! SDL error:%s\n", textureText, SDL_GetError());
- retVal = 0;
- goto cleanup;
- }
- finalTexture->width = textSurface->w;
- finalTexture->height = textSurface->h;
- /* Assign texture and return status */
- (finalTexture->sdlTexture) = (newTexture);
- cleanup:
- /* Free pointers */
- SDL_FreeSurface(textSurface);
- newTexture = NULL;
- textSurface = NULL;
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement