73 lines
1.9 KiB
C
73 lines
1.9 KiB
C
#include "gui.h"
|
|
#include <stdbool.h>
|
|
|
|
#include <SDL.h>
|
|
#include <SDL_image.h>
|
|
#include <SDL_ttf.h>
|
|
|
|
const SCREEN_WIDTH = 800;
|
|
const SCREEN_HEIGHT = 600;
|
|
|
|
SDL_Window* window = NULL;
|
|
// SDL_Surface* screenSurface = NULL;
|
|
SDL_Renderer *window_renderer = NULL;
|
|
SDL_Texture* tile_texture = NULL;
|
|
|
|
void gui_init() {
|
|
|
|
//Initialize SDL
|
|
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
|
|
{
|
|
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
|
|
}
|
|
|
|
window = SDL_CreateWindow( "2048", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
|
|
if( window == NULL )
|
|
{
|
|
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
|
|
}
|
|
// screenSurface = SDL_GetWindowSurface(window);
|
|
// SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 255, 255, 255));
|
|
|
|
|
|
// create renderer and render white window
|
|
window_renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
SDL_SetRenderDrawColor(window_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
|
|
SDL_RenderClear(window_renderer);
|
|
SDL_RenderPresent(window_renderer);
|
|
// SDL_UpdateWindowSurface(window);
|
|
|
|
// load up textures
|
|
SDL_Surface *tile_surface = IMG_Load("res/tile.png");
|
|
tile_texture = SDL_CreateTextureFromSurface( window_renderer, tile_surface);
|
|
SDL_FreeSurface(tile_surface);
|
|
}
|
|
|
|
void gui_destroy() {
|
|
//Destroy window
|
|
SDL_DestroyWindow( window );
|
|
SDL_DestroyRenderer(window_renderer);
|
|
|
|
//Quit SDL subsystems
|
|
SDL_Quit();
|
|
|
|
}
|
|
|
|
void gui_loop(Game *game) {
|
|
bool quit = false;
|
|
SDL_Event e;
|
|
while(!quit) {
|
|
while( SDL_PollEvent( &e ) != 0 )
|
|
{
|
|
//User requests quit
|
|
if( e.type == SDL_QUIT )
|
|
{
|
|
quit = true;
|
|
}
|
|
}
|
|
|
|
SDL_RenderCopy( window_renderer, tile_texture, NULL, NULL );
|
|
SDL_RenderPresent(window_renderer);
|
|
}
|
|
|
|
} |