0

Basically, I want to have one texture which contains both text and an image.

How would I go about doing that? I've been Google-ing around, but I can't seem to find a way to combine surfaces with other surfaces, textures with other textures, nor surfaces with textures.

EDIT: So, I'm making a simple RPG, and I want to have it so that when you talk to an NPC, that NPC either can or can't have an image attached to the text.

I would ideally do this by sending the text and image to a function which will gererate a texture I can just render, instead of having to worry about rendering two different ones, and where they should be positioned.

Something like this:

void setSayingText(std::string const& text, std::string const& imageLoc = "") {
   SDL_Surface* text = TTF_RenderText_Blended(font, text.c_str(), whiteColor);
   if (imageLoc != "") {
      SDL_Surface* image = IMG_Load(imageLoc);
      texture = SDL_CreateTextureFromSurface(renderer, text + image);
   } else {
      texture = SDL_CreateTextureFromSurface(renderer, text);
   }
}
HelpMe000
  • 98
  • 2
  • 5
  • possible duplicate of [SDL: Render Texture on top of another texture](http://stackoverflow.com/questions/18647592/sdl-render-texture-on-top-of-another-texture) – CinchBlue Jun 08 '15 at 19:11

1 Answers1

1

It should be trivial to get your text and image as surfaces and then call https://wiki.libsdl.org/SDL_BlitSurface to copy one surface onto the other surface. Afterwards you would probably want to load the combined image into a texture to use with the render API.

It's also possible to use the Render API to render to a texture using https://wiki.libsdl.org/SDL_SetRenderTarget, but if I were you I'd stick to the simpler Surface API for one-off compositing.

joeforker
  • 40,459
  • 37
  • 151
  • 246
  • Thanks man, can't believe I missed that. I just want to make one thing clear with SDL_BlitSurface: the parameter "dstrect" is the area on the "bigger" surface where the "smaller" surface will be pasted to? Or is it just a rect showing the size and such of the "bigger" surface? – HelpMe000 Jun 08 '15 at 21:23
  • 1
    Yes, it will copy `srcrect` from within the source surface onto `dstrect` in the destination surface. If they are not the same size then there will be scaling. – joeforker Jun 09 '15 at 13:19