🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

can't render more than one line with this code

Started by
0 comments, last by tkialwan 4 years, 2 months ago

why I can't render more than one line with this code it's render only last line with loadtext() ,this is the code:

void Ltext::loadtext(const char* text, SDL_Color textColor,SDL_Renderer* gren)

{

free();

gFont = TTF_OpenFont("carson.ttf", 24);

SDL_SetRenderDrawColor(gren, 255,255,255,255);

SDL_RenderClear(gren);

int n;

//Render text surface

SDL_Surface* textSurface = TTF_RenderText_Solid(gFont, text, textColor);

if(textSurface != NULL)

{

//Create texture from surface pixels

mTexture = SDL_CreateTextureFromSurface(gren, textSurface);

if (mTexture == NULL)

{

printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError());

}

//Get rid of old surface

SDL_FreeSurface(textSurface);

}

else

{

printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError());

}

int texw = 0;

int texh = 0;

SDL_QueryTexture(mTexture, NULL, NULL, &texw, &texh);

dest[i] = { 0,y,texw,texh };

SDL_RenderCopy(gren, mTexture, NULL, &dest[i]);

SDL_RenderPresent(gren);

y += 30;

i++;

}

void Ltext::free()

{

//Free texture if it exists

if (mTexture != NULL)

{

SDL_DestroyTexture(mTexture);

mTexture = NULL;

}

}

None

This topic is closed to new replies.

Advertisement