Added fonts
This commit is contained in:
parent
347326a14a
commit
ded8682f82
2
Makefile
2
Makefile
@ -10,4 +10,4 @@ args = -o
|
|||||||
|
|
||||||
all:
|
all:
|
||||||
$(compiler) $(warningLevel) $(includes) $(sources) $(linker) $(libs) $(args) $(dir)\$(target)
|
$(compiler) $(warningLevel) $(includes) $(sources) $(linker) $(libs) $(args) $(dir)\$(target)
|
||||||
start cmd /K "cd $(dir) && $(target)"
|
start cmd /C "cd $(dir) && $(target)"
|
||||||
|
BIN
bin/assets/fonts/ae-bi.ttf
Normal file
BIN
bin/assets/fonts/ae-bi.ttf
Normal file
Binary file not shown.
BIN
bin/assets/fonts/ka1.ttf
Normal file
BIN
bin/assets/fonts/ka1.ttf
Normal file
Binary file not shown.
BIN
bin/assets/fonts/minecraft.ttf
Normal file
BIN
bin/assets/fonts/minecraft.ttf
Normal file
Binary file not shown.
55
main.c
55
main.c
@ -18,6 +18,7 @@ void DrawFrame();
|
|||||||
void INITIALIZE();
|
void INITIALIZE();
|
||||||
void QUIT();
|
void QUIT();
|
||||||
void GAMELOOP();
|
void GAMELOOP();
|
||||||
|
void printFontStyle(TTF_Font * ffont);
|
||||||
void mousePress(SDL_MouseButtonEvent b);
|
void mousePress(SDL_MouseButtonEvent b);
|
||||||
void keyPress(SDL_KeyboardEvent b);
|
void keyPress(SDL_KeyboardEvent b);
|
||||||
void windowChanged(SDL_WindowEvent b);
|
void windowChanged(SDL_WindowEvent b);
|
||||||
@ -31,6 +32,7 @@ SDL_Window * window;
|
|||||||
SDL_Renderer * renderer;
|
SDL_Renderer * renderer;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
bool running = true, fullscreen = false;
|
bool running = true, fullscreen = false;
|
||||||
|
TTF_Font * font = NULL;
|
||||||
|
|
||||||
Ball ball;
|
Ball ball;
|
||||||
|
|
||||||
@ -106,16 +108,61 @@ void DrawFrame(){
|
|||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
BREAKOUT_Draw(renderer);
|
BREAKOUT_Draw(renderer);
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
if (TTF_SizeText(font, "put your text here", &w, &h)) {
|
||||||
|
// perhaps print the current TTF_GetError(), the string can't be rendered...
|
||||||
|
} else {
|
||||||
|
printf("width=%d height=%d\n", w, h);
|
||||||
|
}
|
||||||
|
SDL_Color White = { 255, 255, 255 }; // this is the color in rgb format, maxing out all would give you the color white, and it will be your text's color
|
||||||
|
|
||||||
|
SDL_Surface * surfaceMessage = TTF_RenderText_Solid(font, "put your text here", White); // as TTF_RenderText_Solid could only be used on SDL_Surface then you have to create the surface first
|
||||||
|
|
||||||
|
SDL_Texture * Message = SDL_CreateTextureFromSurface(renderer, surfaceMessage); // now you can convert it into a texture
|
||||||
|
|
||||||
|
SDL_Rect Message_rect = (SDL_Rect) {.x = 0, .y = 0, .w = w, .h = h }; // create a rect
|
||||||
|
SDL_RenderCopy(renderer, Message, NULL, &Message_rect); // you put the renderer's name first, the Message, the crop size(you can ignore this if you don't want to dabble with cropping), and the rect which is the size and coordinate of your texture
|
||||||
|
|
||||||
|
SDL_FreeSurface(surfaceMessage);
|
||||||
|
SDL_DestroyTexture(Message);
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
} /* DrawFrame */
|
||||||
|
|
||||||
|
void printFontStyle(TTF_Font * ffont){
|
||||||
|
int style;
|
||||||
|
|
||||||
|
style = TTF_GetFontStyle(ffont);
|
||||||
|
printf("The font style is:");
|
||||||
|
if (style == TTF_STYLE_NORMAL)
|
||||||
|
printf(" normal");
|
||||||
|
else {
|
||||||
|
if (style & TTF_STYLE_BOLD)
|
||||||
|
printf(" bold");
|
||||||
|
if (style & TTF_STYLE_ITALIC)
|
||||||
|
printf(" italic");
|
||||||
|
if (style & TTF_STYLE_UNDERLINE)
|
||||||
|
printf(" underline");
|
||||||
|
if (style & TTF_STYLE_STRIKETHROUGH)
|
||||||
|
printf(" strikethrough");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void INITIALIZE() {
|
void INITIALIZE() {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) printf("SDL could not initialize! Error: %s\n", SDL_GetError());
|
||||||
else printf("SDL was successfully initialized!\n");
|
else printf("SDL was successfully initialized!\n");
|
||||||
if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) printf("IMG could not initialize! IMG_Error: %s\n", IMG_GetError());
|
if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) printf("IMG could not initialize! Error: %s\n", IMG_GetError());
|
||||||
else printf("IMG was successfully initialized!\n");
|
else printf("IMG was successfully initialized!\n");
|
||||||
TTF_Init();
|
if (TTF_Init() == -1) printf("TTF could not initialize! Error: %s\n", TTF_GetError());
|
||||||
|
else printf("TTF was successfully initialized!\n");
|
||||||
|
|
||||||
|
// load font.ttf at size 16 into font
|
||||||
|
font = TTF_OpenFont("assets/fonts/minecraft.ttf", 32);
|
||||||
|
if (!font) printf("Font could not initialize! Error: %s\n", TTF_GetError());
|
||||||
|
else printf("Font was successfully initialized!\n");
|
||||||
|
printFontStyle(font);
|
||||||
|
|
||||||
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
window = SDL_CreateWindow("BreakING", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
|
||||||
SDL_SetWindowResizable(window, true);
|
SDL_SetWindowResizable(window, true);
|
||||||
@ -129,6 +176,8 @@ void QUIT(){
|
|||||||
printf("De-initializing started...\n");
|
printf("De-initializing started...\n");
|
||||||
BREAKOUT_DEINITIALIZE();
|
BREAKOUT_DEINITIALIZE();
|
||||||
free(keystate);
|
free(keystate);
|
||||||
|
TTF_CloseFont(font);
|
||||||
|
font = NULL; // to be safe...
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
IMG_Quit();
|
IMG_Quit();
|
||||||
printf("Quitting SDL_IMG finished!\n");
|
printf("Quitting SDL_IMG finished!\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user