Text not drawing

I want draw a text using this class on a sdl window, but it wont work, won't draw anything.
CText.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//=============================================================================
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include <string>
#ifndef _CTEXT_H_
#define _CTEXT_H_
//=============================================================================
class CText  {
    public:
        CText();

char *text;
SDL_Surface *background = NULL;
SDL_Surface *message = NULL;
SDL_Surface *screen = NULL;


//The font that's going to be used
TTF_Font *font = NULL;

//The color of the font
SDL_Color textColor = { 255, 255, 255 };

  
virtual bool DrawText(char *pfont,char *ptext, int psize, SDL_Window *window);
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip );   



};

//=============================================================================

#endif  

CText.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//=============================================================================

#include "CText.h"

void CText::apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip )
{
    //Holds offsets
    SDL_Rect offset;

    //Get offsets
    offset.x = x;
    offset.y = y;

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}
CText::CText() {

}
bool CText::DrawText(char *pfont,char *ptext, int psize, SDL_Window *window){
SDL_Color textColor = { 255, 255, 255 };
font = TTF_OpenFont( pfont, psize );
SDL_Surface *message =  TTF_RenderText_Solid( font, ptext, textColor );
SDL_Surface *screen;
screen = SDL_GetWindowSurface(window);
CText::apply_surface( 0, 0, message, screen,NULL );
SDL_UpdateWindowSurface(window);
  
}

//=============================================================================

Last edited on
i dont know to much about SDL
but dont you have to flip the screen?
My Problem, i was missing rendering the image on a loop.
is working now
Yes you missing rendering the images on loop i check your code but it;s great you find the solution
Topic archived. No new replies allowed.