I'm trying to render multiple lines of text to one texture so I only have to render one texture to the screen. However, when I use a dstrect argument in SDL_RenderCopy the text doesn't show up and when I use NULL for the dstrect argument it does work, but it is stretch to the entire texture which I don't want. I've checked the values of the dstrect (x,y,w,h) and they all seem to be at the right values when I try to render.
Here is the creation of the "Font Texture"
void Font::setMessage(std::string textureMessage, SDL_Color textColour){
if(text != NULL){
SDL_DestroyTexture( text );
text = NULL;
}
//contents is a string
contents = textureMessage;
//Render text surface
SDL_Surface* loadedSurface = TTF_RenderText_Blended( fontType, contents.c_str(), textColour );
if( loadedSurface == NULL ){
std::cout << TTF_GetError() << std::endl;
}
if( loadedSurface == NULL ){
//Error Check
std::cout << "COULDN'T RENDER TEXT." << std::endl;
}
else
{
//Create texture from surface pixels
//text is of type SDL_Texture
text = SDL_CreateTextureFromSurface( rendererPtr, loadedSurface );
if( text == NULL ){
//Error Check
std::cout << "COULDN'T LOAD FONT TO TEXTURE." << SDL_GetError() << std::endl;
}
else{
//w and h are int pointers to the SDL_Rect "textBox" offsets
w = &textBox.w;
h = &textBox.h;
if( TTF_SizeText(fontType, contents.c_str(), w, h) != 0){
std::cout << "COULDN'T SIZE FONT." << SDL_GetError() << std::endl;
}
}
}
//Get rid of old loaded surface
SDL_FreeSurface( loadedSurface );
loadedSurface = NULL;
}
And here is where I'm trying to render it to another texture:
dstRect->x = xTemp;
dstRect->y = yTemp;
dstRect->w = messageLog.at(placeCount)->getW();
dstRect->h = messageLog.at(placeCount)->getH();
std::cout << dstRect->x << " " << dstRect->y << " " << dstRect->w << " " << dstRect->h << std::endl;
if (messageLog.at(placeCount)->getSelf() != NULL){
if ( SDL_RenderCopy(rendererPtr, messageLog.at(placeCount)->getSelf(), NULL, dstRect) != 0){
std::cout << SDL_GetError() << std::endl;
}
}
Any ideas why giving an argument would make it not work but using NULL would?