Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. int loadTextureFromText(char *textureText, TTF_Font *textFont, SDL_Color textColor, WTexture *finalTexture, SDL_Renderer *renderer)
  2. {
  3.  
  4. int retVal = 1;
  5. SDL_Texture *newTexture = NULL;
  6. SDL_Surface *textSurface = NULL;
  7.  
  8. /* Free texture */
  9.  
  10. freeTexture(finalTexture);
  11.  
  12. /* Render text surface */
  13.  
  14. textSurface = TTF_RenderText_Solid(textFont, textureText, textColor);
  15.  
  16. if (textSurface == NULL)
  17. {
  18. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load text %s! SDL_ttf error: %s\n", textureText, TTF_GetError());
  19. retVal = 0;
  20. goto cleanup;
  21. }
  22.  
  23. /* Create texture from surface */
  24. newTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
  25.  
  26. if (newTexture == NULL)
  27. {
  28. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create texture from %s! SDL error:%s\n", textureText, SDL_GetError());
  29. retVal = 0;
  30. goto cleanup;
  31. }
  32.  
  33. finalTexture->width = textSurface->w;
  34. finalTexture->height = textSurface->h;
  35.  
  36. /* Assign texture and return status */
  37. (finalTexture->sdlTexture) = (newTexture);
  38.  
  39. cleanup:
  40.  
  41. /* Free pointers */
  42. SDL_FreeSurface(textSurface);
  43. newTexture = NULL;
  44. textSurface = NULL;
  45.  
  46. return retVal;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement