Created
November 29, 2017 13:58
-
-
Save wutipong/35bef55fd88614a42ad9c436d7488d11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <codecvt> | |
#include <iomanip> | |
#include <SDL2/SDL.h> | |
#include <ft2build.h> | |
#include FT_FREETYPE_H | |
constexpr char teststring[] {"Hello World"}; | |
constexpr int WIDTH = 800; | |
constexpr int HEIGHT = 600; | |
FT_Library library; | |
FT_Face face; | |
int main(int argc, char** argv) { | |
SDL_Init(SDL_INIT_EVERYTHING); | |
SDL_Window* window = SDL_CreateWindow ( | |
"Test Window", | |
SDL_WINDOWPOS_UNDEFINED, | |
SDL_WINDOWPOS_UNDEFINED, | |
WIDTH, | |
HEIGHT, | |
0); | |
SDL_Renderer* renderer; | |
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); | |
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv16; | |
std::u16string str16 = u"\u0E40\u0E21\u0E37\u0E48\u0E2D\u0E01\u0E32\u0E23\u0E17\u0E48\u0E2D\u0E07\u0E40\u0E17\u0E35\u0E48\u0E22\u0E27\u0E41\u0E25\u0E30\u0E08\u0E2D\u0E07\u0E17\u0E35\u0E48\u0E1E\u0E31\u0E01";//conv16.from_bytes(teststring); | |
std::cout << "code points: \n"; | |
for (char16_t c : str16) | |
std::cout << "\tU+" << std::hex << std::setw(4) << std::setfill('0') << c << '\n'; | |
std::cout<<std::dec; | |
FT_Init_FreeType(&library); | |
FT_New_Face(library, "test.ttf", 0, &face); | |
FT_Set_Pixel_Sizes(face, 0, 64); | |
std::cout<<"glyph indices:" <<std::endl; | |
for (char16_t c : str16) | |
std::cout << "\t" << FT_Get_Char_Index(face, c) << '\n'; | |
SDL_Color color; | |
color.r = 0x80; | |
color.g = 0xff; | |
color.b = 0xaa; | |
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); | |
while (true) | |
{ | |
SDL_Event event; | |
if (SDL_PollEvent(&event)) | |
{ | |
if (event.type == SDL_QUIT) break; | |
} | |
SDL_SetRenderDrawColor(renderer, 0x50, 0x82, 0xaa, 0xff); | |
SDL_RenderClear(renderer); | |
SDL_RenderPresent(renderer); | |
SDL_Delay(10); | |
} | |
FT_Done_Face(face); | |
FT_Done_FreeType(library); | |
SDL_DestroyWindow(window); | |
SDL_Quit(); | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment