Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GAME_H
- #define GAME_H
- class Game {
- private:
- SDL_Event _ev;
- bool _isRunning;
- public:
- Game();
- ~Game();
- void run();
- };
- #endif
- /*
- * Graphics.cpp
- * Holds info for dealing with game's graphics
- *
- *
- */
- #include <SDL2/SDL.h>
- #include <iostream>
- #include "Graphics.h"
- #include "functions.h"
- Graphics::Graphics() :
- _windowTitle ("SDL2 project"),
- _windowWidth (640),
- _windowHeight (480),
- _renderingDriverIndex (-1), // get the index of the first graphics driver available(?)
- _rendererFlags (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC) // use GPU, VSYNC
- {
- _window= SDL_CreateWindow(_windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, SDL_WINDOW_SHOWN);
- if(_window == 0){
- printError("SDL_CreateWindow");
- SDL_Quit();
- }
- _renderer= SDL_CreateRenderer(_window, _renderingDriverIndex, _rendererFlags);
- if(_renderer == NULL){
- printError("SDL_CreateRenderer");
- SDL_Quit();
- }
- }
- Graphics::~Graphics() {
- SDL_DestroyWindow(_window);
- SDL_DestroyRenderer(_renderer);
- }
- void Graphics::changeWindowSize(int width, int height){
- SDL_SetWindowSize(_window, width, height);
- }
- SDL_Renderer* Graphics::getRenderer(){
- return _renderer;
- }
- int Graphics::getWindowWidth(){
- return _windowWidth;
- }
- int Graphics::getWindowHeight(){
- return _windowHeight;
- }
- Layer::Layer(SDL_Renderer* renderer, int width, int height) :
- _texture(SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height))
- {
- }
- Layer::~Layer(){
- SDL_DestroyTexture(_texture);
- }
- SDL_Texture* Layer::getTexture(){
- return _texture;
- }
- /*
- * functions.h
- *
- */
- #ifndef FUNCTIONS_H
- #define FUNCTIONS_H
- void printError(const char* errorMessage);
- #endif /* FUNCTIONS_H */
- /*
- * functions.cpp
- *
- */
- #include <SDL2/SDL_log.h>
- #include <SDL2/SDL_error.h>
- #include <iostream>
- #include "functions.h"
- void printError(const char* errorMessage){
- std::cout << errorMessage << " error: " << SDL_GetError() << std::endl;
- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, errorMessage, " error: %sn", SDL_GetError());
- }
- /*
- * main.cpp
- * Entry point for game
- *
- */
- #include <SDL2/SDL.h>
- #include <iostream>
- #include "Game.h"
- #include "functions.h"
- int main(int argc, char* argv[]) {
- Game game;
- game.run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement