orden y concierto
parent
46087c840f
commit
16c4321a56
@ -1,69 +1,9 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <stdbool.h>
|
#include "functions.c"
|
||||||
|
|
||||||
SDL_Window* window;
|
|
||||||
SDL_Renderer* renderer;
|
|
||||||
SDL_Surface* surface;
|
|
||||||
SDL_Texture* texture;
|
|
||||||
SDL_Event event;
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int loadLogo(void){
|
|
||||||
surface = SDL_LoadBMP("imgs/bocm.bmp");
|
|
||||||
if (!surface) {
|
|
||||||
return throw_sdl_err("Could not load BMP image: %s");
|
|
||||||
}
|
|
||||||
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
||||||
if (!texture) {
|
|
||||||
return throw_sdl_err("Could not create new texture from surface: %s");
|
|
||||||
}
|
|
||||||
SDL_FreeSurface(surface); // free a RGB surface
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
initWindow();
|
initWindow();
|
||||||
loadLogo();
|
loadLogo();
|
||||||
|
windowLoop();
|
||||||
while (1) {
|
destroy();
|
||||||
SDL_PollEvent(&event);
|
|
||||||
if (event.type == SDL_QUIT) {
|
|
||||||
break;
|
|
||||||
} // break the loop
|
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
SDL_Rect rect = {10, 10, 100, 73};
|
|
||||||
SDL_RenderCopy(renderer, texture, NULL, &rect);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
} // window loop
|
|
||||||
|
|
||||||
SDL_DestroyTexture(texture);
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
SDL_Window* window;
|
||||||
|
SDL_Renderer* renderer;
|
||||||
|
SDL_Surface* surface;
|
||||||
|
SDL_Texture* texture;
|
||||||
|
SDL_Event event;
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loadLogo(void){
|
||||||
|
surface = SDL_LoadBMP("imgs/bocm.bmp");
|
||||||
|
if (!surface) {
|
||||||
|
return throw_sdl_err("Could not load BMP image: %s");
|
||||||
|
}
|
||||||
|
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
|
if (!texture) {
|
||||||
|
return throw_sdl_err("Could not create new texture from surface: %s");
|
||||||
|
}
|
||||||
|
SDL_FreeSurface(surface);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loadBackgroundColor(void){
|
||||||
|
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int presentLogo(void){
|
||||||
|
SDL_Rect rect = {10, 10, 100, 73};
|
||||||
|
SDL_RenderCopy(renderer, texture, NULL, &rect);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int windowLoop(void){
|
||||||
|
while (1) {
|
||||||
|
SDL_PollEvent(&event);
|
||||||
|
if (event.type == SDL_QUIT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadBackgroundColor();
|
||||||
|
presentLogo();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int destroy(void){
|
||||||
|
SDL_DestroyTexture(texture);
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue