Skip to content

Instantly share code, notes, and snippets.

@imxdn
Last active September 23, 2017 19:21
Show Gist options
  • Select an option

  • Save imxdn/f3417a8df698026c182925653bb9d270 to your computer and use it in GitHub Desktop.

Select an option

Save imxdn/f3417a8df698026c182925653bb9d270 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
#include "display.hpp"
int disp_init() {
int status = 0;
// Initialize SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << "Failed to initialize SDL (Error: " << SDL_GetError() << ")" << std::endl;
status = -1;
}
else {
// Create window
window = SDL_CreateWindow(
"Window Name Here xD", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN
);
if(window == NULL) {
std::cout << "Failed to create window (Error: " << SDL_GetError() << ")" << std::endl;
status = -1;
}
else {
// Get window surface
surface = SDL_GetWindowSurface(window);
}
}
return status;
}
void disp_destroy() {
// Destroy window
SDL_DestroyWindow(window);
window = NULL;
// Quit SDL subsystems
SDL_Quit();
}
#ifndef DISPLAY_HPP
#define DISPLAY_HPP
#include <cstdint>
#include <SDL2/SDL.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 320
// SDL
extern SDL_Window* window;
extern SDL_Surface* surface;
// Initilize SDL2 window
int disp_init();
// Render game
void disp_render();
// Destroy SDL2 window
void disp_destroy();
#endif
#include <iostream>
#include <cstdlib>
#include "display.hpp"
int main(int argc, char *argv[]) {
disp_init();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment