57 lines
1.6 KiB
C
57 lines
1.6 KiB
C
#include <stdlib.h>
|
|
#include <SDL.h>
|
|
#include <SDL_image.h>
|
|
|
|
#include "api.h"
|
|
|
|
SDL_Window* window;
|
|
SDL_Renderer* renderer;
|
|
SDL_Texture* lettuce_tex;
|
|
int main(int argc, char* argv[]) {
|
|
SDL_Surface* lettuce_sur;
|
|
reportError("startup purrforce?");
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
|
|
reportError("Error SDL2 Initialization : %s",SDL_GetError());
|
|
return 1;
|
|
}
|
|
window = SDL_CreateWindow("First program", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);
|
|
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;
|
|
}
|
|
lettuce_sur = IMG_Load("lettuce.png");
|
|
if (lettuce_sur == NULL) {
|
|
reportError("Error loading image: %s",IMG_GetError());
|
|
return 5;
|
|
}
|
|
lettuce_tex = SDL_CreateTextureFromSurface(renderer, lettuce_sur);
|
|
if (lettuce_tex == NULL) {
|
|
reportError("Error creating texture");
|
|
return 6;
|
|
}
|
|
SDL_FreeSurface(lettuce_sur);
|
|
while (1) {
|
|
SDL_Event e;
|
|
if (SDL_WaitEvent(&e)) {
|
|
if (e.type == SDL_QUIT) {
|
|
break;
|
|
}
|
|
}
|
|
SDL_RenderClear(renderer);
|
|
SDL_RenderCopy(renderer, lettuce_tex, NULL, NULL);
|
|
SDL_RenderPresent(renderer);
|
|
}
|
|
SDL_DestroyTexture(lettuce_tex);
|
|
SDL_DestroyRenderer(renderer);
|
|
SDL_DestroyWindow(window);
|
|
IMG_Quit();
|
|
SDL_Quit();
|
|
return 0;
|
|
}
|
|
|