You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.4 KiB
105 lines
2.4 KiB
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <SDL2/SDL.h> |
|
#include <SDL2/SDL_image.h> |
|
#include <string.h> |
|
#include <time.h> |
|
#include <stdbool.h> |
|
#include <pthread.h> |
|
|
|
#include "logger.h" |
|
#include "game.h" |
|
#include "draw.h" |
|
#include "garbo.h" |
|
|
|
const int screen_width = 800; |
|
const int screen_height = 600; |
|
|
|
|
|
struct SDL_Window* make_window(void) { |
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { |
|
printf("error initializing SDL: %s\n", SDL_GetError()); |
|
} |
|
return SDL_CreateWindow("sdl_tester", |
|
SDL_WINDOWPOS_CENTERED, |
|
SDL_WINDOWPOS_CENTERED, |
|
screen_width, screen_height, SDL_WINDOW_FULLSCREEN_DESKTOP); |
|
} |
|
|
|
|
|
|
|
void draw_pictures(struct SDL_Renderer * ren) { |
|
logwrite(INFO, "Draw pictures\n"); |
|
// display an initial splash screen |
|
|
|
/* |
|
*SDL_Surface * png_surface = IMG_Load(png_file) ; |
|
*if(!png_surface) { |
|
* printf("IMG_Load: %s\n", IMG_GetError()); |
|
* // handle error |
|
*} |
|
*/ |
|
|
|
SDL_Texture * png_image = load_image(ren, "trans.PNG"); //SDL_CreateTextureFromSurface(ren, png_surface); |
|
|
|
//render_texture_at(ren, texture, 100, 100); |
|
//render_texture_at(ren, png_image, 100, 100); |
|
SDL_RenderCopy(ren, png_image, NULL, NULL); |
|
|
|
} |
|
|
|
void redraw(struct SDL_Renderer * ren) { |
|
// check time |
|
// redraw if 1/60th of second passed |
|
|
|
SDL_RenderClear(ren); |
|
redraw_buffer(ren); |
|
SDL_RenderPresent(ren); |
|
} |
|
|
|
int main () { |
|
LOGLEVEL = DEBUG; |
|
STDOUTLEVEL = DEBUG; |
|
|
|
logwrite(INFO, "Starting\n"); |
|
SDL_Window * win = make_window(); |
|
SDL_Renderer * ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); |
|
|
|
queue_for_cleanup(win, WINDOW); |
|
queue_for_cleanup(ren, RENDERER); |
|
|
|
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG); |
|
|
|
if (ren == NULL) { |
|
SDL_DestroyWindow(win); |
|
SDL_Quit(); |
|
} |
|
|
|
int close = 0; |
|
|
|
//draw_pictures(ren); |
|
|
|
bool once = true; |
|
startgame(ren); |
|
while (!close) { |
|
step(100); |
|
|
|
/* Redraw Screen */ |
|
redraw(ren); |
|
|
|
SDL_Event event; |
|
SDL_PollEvent(&event); |
|
switch (event.type) { |
|
case SDL_QUIT: |
|
close = 1; |
|
break; |
|
} |
|
} |
|
|
|
empty_cleanup_queue(); |
|
printf("Cleanup queue length: %d\n", cleanup_queue_length); |
|
logwrite(DEBUG, "Emptied cleanup queue\n"); |
|
return 0; |
|
} |
|
|
|
|