Cleanup
This commit is contained in:
-110
@@ -1,110 +0,0 @@
|
|||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <SDL3/SDL_events.h>
|
|
||||||
#include <SDL3_image/SDL_image.h>
|
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
TTF_Init();
|
|
||||||
|
|
||||||
SDL_Window* window =
|
|
||||||
SDL_CreateWindow("SDL3 Demo", 800, 600, SDL_WINDOW_RESIZABLE);
|
|
||||||
|
|
||||||
SDL_Renderer* renderer =
|
|
||||||
SDL_CreateRenderer(window, NULL);
|
|
||||||
|
|
||||||
// log window size
|
|
||||||
int w, h;
|
|
||||||
SDL_GetWindowSize(window, &w, &h);
|
|
||||||
SDL_StartTextInput(window);
|
|
||||||
printf("Window size: %d x %d\n", w, h);
|
|
||||||
|
|
||||||
// ---------------- LOAD IMAGE ----------------
|
|
||||||
SDL_Texture* image = IMG_LoadTexture(renderer, "./assets/images/arrow.png");
|
|
||||||
|
|
||||||
SDL_SetTextureScaleMode(image, SDL_SCALEMODE_NEAREST);
|
|
||||||
|
|
||||||
// ---------------- LOAD FONT ----------------
|
|
||||||
TTF_Font* font = TTF_OpenFont("./assets/fonts/charybdis.ttf", 24);
|
|
||||||
|
|
||||||
SDL_Color white = {255, 255, 255, 255};
|
|
||||||
|
|
||||||
SDL_Surface* text_surface =
|
|
||||||
TTF_RenderText_Solid(font, "Hello SDL3 + TTF!", 17, white);
|
|
||||||
|
|
||||||
SDL_Texture* text_tex =
|
|
||||||
SDL_CreateTextureFromSurface(renderer, text_surface);
|
|
||||||
|
|
||||||
SDL_SetTextureScaleMode(text_tex, SDL_SCALEMODE_NEAREST);
|
|
||||||
|
|
||||||
int running = 1;
|
|
||||||
float angle = 0.0f;
|
|
||||||
|
|
||||||
while (running) {
|
|
||||||
SDL_Event e;
|
|
||||||
|
|
||||||
while (SDL_PollEvent(&e)) {
|
|
||||||
if (e.type == SDL_EVENT_QUIT) {
|
|
||||||
running = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.type == SDL_EVENT_TEXT_INPUT) {
|
|
||||||
printf("Text input: %s\n", e.text.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.type == SDL_EVENT_KEY_DOWN) {
|
|
||||||
printf("key down: %d\n", e.key.key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float mx, my;
|
|
||||||
SDL_GetMouseState(&mx, &my);
|
|
||||||
|
|
||||||
// ---------------- UPDATE ----------------
|
|
||||||
angle += 1.0f;
|
|
||||||
|
|
||||||
// ---------------- RENDER ----------------
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// ---- draw mouse box ----
|
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
|
||||||
SDL_FRect mouse_rect = { mx, my, 10, 10 };
|
|
||||||
SDL_RenderFillRect(renderer, &mouse_rect);
|
|
||||||
|
|
||||||
// ---- draw image (scaled + rotated) ----
|
|
||||||
SDL_FRect dst_img = { 200, 150, 200, 200 };
|
|
||||||
|
|
||||||
SDL_RenderTextureRotated(
|
|
||||||
renderer,
|
|
||||||
image,
|
|
||||||
NULL, // full texture
|
|
||||||
&dst_img,
|
|
||||||
angle, // rotation degrees
|
|
||||||
NULL, // center (NULL = center of rect)
|
|
||||||
SDL_FLIP_NONE
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---- draw text ----
|
|
||||||
SDL_FRect dst_text = { 50, 50, 400, 50 };
|
|
||||||
SDL_RenderTexture(renderer, text_tex, NULL, &dst_text);
|
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
|
|
||||||
SDL_Delay(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- CLEANUP ----------------
|
|
||||||
SDL_DestroyTexture(text_tex);
|
|
||||||
SDL_DestroyTexture(image);
|
|
||||||
TTF_CloseFont(font);
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
|
|
||||||
TTF_Quit();
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user