Basically I'm trying to end up with a Texture class that can take in text and have it be drawn over simple geometry (such as a letter 'A' over a filled rectangle). However I'm running into issues when thinking about how to combine these two concepts.

First, following lazy foo's tutorials, Geometry rendering is simple and is done with an

SDL_RECT and SDL_RenderFillRect(SDL_Renderer*, &SDL_Rect);

However, when rendering text it uses Surfaces and Textures in order to 'draw' the text. Specifically these lines:

SDL_Surface* textSurface = TTF_RenderText_Solid( gFont, textureText.c_str(), textColor );
mTexture = SDL_CreateTextureFromSurface( SDL_Renderer*, textSurface );

My confusing comes from trying to figure out several things:

a) Is it possible to maybe first Render the Geometry to a texture, and then render the text over that same texture?

b) I believe a call to SDL_SetRenderTarget is going to be necessary, but I'm not sure where and when during my combination stage this would need to be done.

c) Right before posting this question, I saw further down on the tutorials this link which describes rendering geometry to a texture, however I'm still not sure how to combine Text with this.

Any help is appreciated, Thanks


1 Answer 1


To anyone else that ever needs help, I found a simple solution after thinking about it real quick, just set the target and then Draw any geometry you need before rendering the texture.

void LTexture::render( int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip )
//Set rendering space and render to screen
SDL_Rect renderQuad = { x, y, mWidth, mHeight };

//Set clip rendering dimensions
if( clip != NULL )
    renderQuad.w = clip->w;
    renderQuad.h = clip->h;
//Draw geometry
SDL_Rect fillRect = { 0, 0, mWidth, mHeight };
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0x00, 0x00, 0xFF );
SDL_RenderFillRect( gRenderer, &fillRect );

//Render to screen (when mTexture = a font loaded texture/surface)
SDL_RenderCopyEx( gRenderer, mTexture, clip, &renderQuad, angle, center, flip );

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .