Compare commits
2 Commits
f32007496c
...
dc97f5aa81
Author | SHA1 | Date | |
---|---|---|---|
dc97f5aa81 | |||
ff9032bc22 |
53
~/SDL/Example Text/text_ttf.c
Normal file
53
~/SDL/Example Text/text_ttf.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// gcc -lSDL2 -lSDL2_ttf -o ttf text_ttf.c
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
|
int main(int argc, char ** argv) {
|
||||||
|
bool quit = false;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
TTF_Init();
|
||||||
|
|
||||||
|
SDL_Window * window = SDL_CreateWindow("SDL_ttf in SDL2",
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 192, 0);
|
||||||
|
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
|
|
||||||
|
TTF_Font * font = TTF_OpenFont("../assets/monogram-extended.ttf", 24);
|
||||||
|
const char * error = TTF_GetError();
|
||||||
|
SDL_Color color = { 255, 255, 255 };
|
||||||
|
SDL_Surface * surface = TTF_RenderUTF8_Solid(font, "Привет :)", color);
|
||||||
|
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
|
|
||||||
|
int texW = 0;
|
||||||
|
int texH = 0;
|
||||||
|
SDL_QueryTexture(texture, NULL, NULL, &texW, &texH);
|
||||||
|
SDL_Rect dstrect = { 320 / 2 - (texW / 2), 192 / 2 - (texH), texW, texH };
|
||||||
|
|
||||||
|
while (!quit) {
|
||||||
|
SDL_WaitEvent(&event);
|
||||||
|
|
||||||
|
switch (event.type) {
|
||||||
|
case SDL_QUIT:
|
||||||
|
quit = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderCopy(renderer, texture, NULL, &dstrect);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
TTF_Quit();
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
11
~/SDL/Scale2x/scale2x.c
Normal file
11
~/SDL/Scale2x/scale2x.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#define WIDTH 320
|
||||||
|
#define HEIGHT 192
|
||||||
|
|
||||||
|
#define SCALE 2
|
||||||
|
|
||||||
|
SDL_Window * window = SDL_CreateWindow("SDL 2x scale",
|
||||||
|
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, 0);
|
||||||
|
SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
|
||||||
|
|
||||||
|
SDL_SetWindowSize(window, WIDTH * SCALE, HEIGHT * SCALE);
|
||||||
|
SDL_RenderSetScale(renderer, SCALE, SCALE);
|
BIN
~/SDL/assets/monogram-extended.ttf
Normal file
BIN
~/SDL/assets/monogram-extended.ttf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user