You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
221 lines
5.5 KiB
C
221 lines
5.5 KiB
C
#include <SDL.h>
|
|
|
|
SDL_Window* window;
|
|
SDL_Renderer* renderer;
|
|
SDL_Surface* surface;
|
|
SDL_Texture* font;
|
|
|
|
|
|
const int screenWidth = 800;
|
|
const int screenHeight = 600;
|
|
|
|
int throw_sdl_err(const char* fmt)
|
|
{
|
|
SDL_LogError(
|
|
SDL_LOG_CATEGORY_APPLICATION,
|
|
fmt,
|
|
SDL_GetError()
|
|
);
|
|
return 3;
|
|
}
|
|
|
|
int initWindow(void){
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
return throw_sdl_err("Could not init the SDL: %s");
|
|
}
|
|
if (SDL_CreateWindowAndRenderer(screenWidth, screenHeight, SDL_WINDOW_OPENGL, &window, &renderer)) {
|
|
return throw_sdl_err("Could not create new window and renderer: %s");
|
|
}
|
|
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
|
SDL_SetWindowTitle(window, "Fanta 0.1");
|
|
return 0;
|
|
}
|
|
|
|
int loadFont(void){
|
|
surface = SDL_LoadBMP("imgs/font.bmp");
|
|
if (!surface) {
|
|
return throw_sdl_err("Could not load BMP image: %s");
|
|
}
|
|
font = SDL_CreateTextureFromSurface(renderer, surface);
|
|
if (!font) {
|
|
return throw_sdl_err("Could not create new texture from surface: %s");
|
|
}
|
|
SDL_FreeSurface(surface);
|
|
return 0;
|
|
}
|
|
|
|
int loadBackgroundColor(void){
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
SDL_RenderClear(renderer);
|
|
return 0;
|
|
}
|
|
|
|
void putChar(int x, int y, int size, char value){
|
|
|
|
if (value=='a'){
|
|
SDL_Rect srcrect = {0, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='b'){
|
|
SDL_Rect srcrect = {16, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='c'){
|
|
SDL_Rect srcrect = {32, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='d'){
|
|
SDL_Rect srcrect = {48, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='e'){
|
|
SDL_Rect srcrect = {64, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='f'){
|
|
SDL_Rect srcrect = {80, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='g'){
|
|
SDL_Rect srcrect = {96, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='h'){
|
|
SDL_Rect srcrect = {112, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='i'){
|
|
SDL_Rect srcrect = {128, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='j'){
|
|
SDL_Rect srcrect = {144, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='k'){
|
|
SDL_Rect srcrect = {160, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='l'){
|
|
SDL_Rect srcrect = {176, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='m'){
|
|
SDL_Rect srcrect = {192, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='n'){
|
|
SDL_Rect srcrect = {208, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='o'){
|
|
SDL_Rect srcrect = {224, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='p'){
|
|
SDL_Rect srcrect = {240, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='q'){
|
|
SDL_Rect srcrect = {256, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='r'){
|
|
SDL_Rect srcrect = {272, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='s'){
|
|
SDL_Rect srcrect = {288, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='t'){
|
|
SDL_Rect srcrect = {304, 0, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='u'){
|
|
SDL_Rect srcrect = {0, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='v'){
|
|
SDL_Rect srcrect = {16, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='w'){
|
|
SDL_Rect srcrect = {32, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='x'){
|
|
SDL_Rect srcrect = {48, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='y'){
|
|
SDL_Rect srcrect = {64, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
if (value=='z'){
|
|
SDL_Rect srcrect = {80, 17, 14, 14};
|
|
SDL_Rect dstrect = {x, y, size, size};
|
|
SDL_RenderCopy(renderer, font, &srcrect, &dstrect);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
int destroy(void){
|
|
SDL_DestroyTexture(font);
|
|
SDL_DestroyRenderer(renderer);
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
return 0;
|
|
}
|