Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to display score using SDL in c++

int fontsize = 24;
int t_width = 0; // width of the loaded font-texture
int t_height = 0; // height of the loaded font-texture
SDL_Color text_color = {0,0,0};
string fontpath = "my font path";
string text = "text I want to display";
TTF_Font* font = TTF_OpenFont(fontpath.c_str(), fontsize);
SDL_Texture* ftexture = NULL; // our font-texture

// check to see that the font was loaded correctly
if (font == NULL) {
    cerr << "Failed the load the font!
";
    cerr << "SDL_TTF Error: " << TTF_GetError() << "
";
}
else {
    // now create a surface from the font
    SDL_Surface* text_surface = TTF_RenderText_Solid(font, text.c_str(), text_color);

    // render the text surface
    if (text_surface == NULL) {
        cerr << "Failed to render text surface!
";
        cerr << "SDL_TTF Error: " << TTF_GetError() << "
";
    }
    else {
        // create a texture from the surface
        ftexture = SDL_CreateTextureFromSurface(renderer, text_surface);

        if (ftexture == NULL) {
            cerr << "Unable to create texture from rendered text!
";
        }
        else {
            t_width = text_surface->w; // assign the width of the texture
            t_height = text_surface->h; // assign the height of the texture

            // clean up after ourselves (destroy the surface)
            SDL_FreeSurface(surface);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: operator using 
Cpp :: construct string with repeat limit 
Cpp :: check if string in vector c++ 
Cpp :: wap in c++ to understand function template 
Cpp :: android call custom managed method from native code 
Cpp :: Structure of s void function 
Cpp :: how to input a file path in c++ 
Cpp :: C++ system("pause") 
Cpp :: converter python to c++ code 
Cpp :: 1162261467 
Cpp :: import matrix from excel to matlab 
Cpp :: lcm recursive program in c++ 
Cpp :: write c++ code using glbegin and gland() function 
Cpp :: c++ convert const char* to LPCWSTR 
Cpp :: subsequence 
Cpp :: concatenate 2 vectors in c++ 
Cpp :: transform cpp 
Cpp :: math in section latex 
Cpp :: pointer to constant 
Cpp :: un aliment traduction espagnol 
C :: C bold output 
C :: get pid c 
C :: arma 3 get group size 
C :: if statement shorthand c 
C :: binary search in c 
C :: how to find sum of two nums 
C :: A binary tree whose every node has either zero or two children is called 
C :: selection sort in c 
C :: c programing strtok use 
C :: dynamic memory in c 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =