purrforce/main.c

57 lines
1.6 KiB
C
Raw Normal View History

2024-03-20 00:48:21 +00:00
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#include "api.h"
SDL_Window* window;
SDL_Renderer* renderer;
2024-03-20 06:25:29 +00:00
SDL_Texture* mascot_tex;
2024-03-20 00:48:21 +00:00
int main(int argc, char* argv[]) {
2024-03-20 06:25:29 +00:00
SDL_Surface* mascot_sur=NULL;
2024-03-20 00:48:21 +00:00
reportError("startup purrforce?");
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
reportError("Error SDL2 Initialization : %s",SDL_GetError());
return 1;
}
2024-03-20 06:25:29 +00:00
window = SDL_CreateWindow("First program", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL);
2024-03-20 00:48:21 +00:00
if (window == NULL) {
reportError("Error window creation");
return 3;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
reportError("Error renderer creation");
return 4;
}
2024-03-20 06:25:29 +00:00
//mascot_sur = IMG_Load("mascot.png");
if (mascot_sur == NULL) {
2024-03-20 00:48:21 +00:00
reportError("Error loading image: %s",IMG_GetError());
return 5;
}
2024-03-20 06:25:29 +00:00
mascot_tex = SDL_CreateTextureFromSurface(renderer, mascot_sur);
if (mascot_tex == NULL) {
2024-03-20 00:48:21 +00:00
reportError("Error creating texture");
return 6;
}
2024-03-20 06:25:29 +00:00
SDL_FreeSurface(mascot_sur);
2024-03-20 00:48:21 +00:00
while (1) {
SDL_Event e;
if (SDL_WaitEvent(&e)) {
if (e.type == SDL_QUIT) {
break;
}
}
SDL_RenderClear(renderer);
2024-03-20 06:25:29 +00:00
SDL_RenderCopy(renderer, mascot_tex, NULL, NULL);
2024-03-20 00:48:21 +00:00
SDL_RenderPresent(renderer);
}
2024-03-20 06:25:29 +00:00
SDL_DestroyTexture(mascot_tex);
2024-03-20 00:48:21 +00:00
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
2024-03-20 06:25:29 +00:00
// IMG_Quit();
2024-03-20 00:48:21 +00:00
SDL_Quit();
return 0;
}