Jump to content
  • Advertisement

markblank

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

104 Neutral

About markblank

  • Rank
    Newbie
  1. Hi, how can i make a vec2, vec3 and vec4 to work with SDL, I know there is vec in openGL, but i want my 2d games to only run using SDL, and i want this vec to be pass in other classes
  2. markblank

    Problem with SDL

      ohh. about the _ in variable, i was watching this tutorial in youtube and he is using _ in private variable. and im not quite familiar with passing reference, can you show me the code on on both your suggestion? thanks
  3. I have a problem creating this second class in my game, this is a class for player but when I call the texturemanager to draw the play, it's not working, but when i directly call the texturemanager to draw the player it was working. this is my class.   Game.h #pragma once #include <SDL/SDL.h> #include "TextureManager.h" #include "Player.h" class Game { public: Game(void); ~Game(void); void startGame(); void init(); void gameLoop(); void eventHandler(); void render(); void exitGame(); private: bool _isRunning; SDL_Window* _window; SDL_Renderer* _renderer; SDL_Rect _spriteClips[2]; TextureManager _textureManager; Player _player; }; Game.cpp #include "Game.h" #include "Error.h" Game::Game(void) { _window = nullptr; _isRunning = true; } Game::~Game(void) { } void Game::startGame() { init(); gameLoop(); } void Game::init() { if (SDL_Init(SDL_INIT_EVERYTHING) == 0) { _window = SDL_CreateWindow("Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN); if (_window != nullptr) { _renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if(_renderer!= nullptr) { SDL_SetRenderDrawColor(_renderer, 255, 255, 255, 255); } else fatalError("Failed to create renderer"); } else fatalError("Failed to create window!"); } else fatalError("Failed to initialize SDL!"); // temp image load _textureManager.loadFromFile("assets/tiles.png", _renderer); _spriteClips[0].x = 0; _spriteClips[0].y = 160; _spriteClips[0].w = 80; _spriteClips[0].h = 80; _spriteClips[1].x = 0; _spriteClips[1].y = 80; _spriteClips[1].w = 80; _spriteClips[1].h = 80; } void Game::gameLoop() { while (_isRunning != false) { eventHandler(); render(); } exitGame(); } void Game::eventHandler() { SDL_Event evnt; while (SDL_PollEvent(&evnt)) { switch (evnt.type) { case SDL_QUIT: _isRunning = false; break; } } } void Game::render() { SDL_RenderClear(_renderer); _textureManager.draw(0, 0, &_spriteClips[0], _renderer); _player.draw(200, 200, &_spriteClips[1], _renderer); // when i used this, it is working //_textureManager.draw(200, 200, &_spriteClips[1], _renderer); SDL_RenderPresent(_renderer); } void Game::exitGame() { SDL_DestroyRenderer(_renderer); SDL_DestroyWindow(_window); _window = nullptr; _renderer = nullptr; SDL_Quit(); } TextureManager.h #pragma once #include <SDL/SDL.h> #include <SDL/SDL_image.h> #include <string> class TextureManager { public: TextureManager(void); ~TextureManager(void); bool loadFromFile(std::string filePath, SDL_Renderer* renderer); void free(); void draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer); int getWidth() { return _width; } int getHeight() { return _height; } private: SDL_Texture* _texture; int _width; int _height; }; TextureManager.cpp #include "TextureManager.h" #include "Error.h" TextureManager::TextureManager(void) { _texture = nullptr; _width = 0; _height = 0; } TextureManager::~TextureManager(void) { free(); } bool TextureManager::loadFromFile(std::string filePath , SDL_Renderer* renderer) { free(); SDL_Texture* newTexture = nullptr; SDL_Surface* loadedSurface = IMG_Load(filePath.c_str()); if(loadedSurface != nullptr) { SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF)); newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface); if(newTexture != nullptr) { _width = loadedSurface->w; _height = loadedSurface->h; } else fatalError("unable to create texture from surface!"); SDL_FreeSurface(loadedSurface); } else fatalError("unable to load image path " + filePath); _texture = newTexture; return _texture != nullptr; } void TextureManager::draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer) { SDL_Rect renderQuad = { x, y, _width, _height }; if (clip != nullptr) { renderQuad.w = clip->w; renderQuad.h = clip->h; } SDL_RenderCopy(renderer, _texture, clip, &renderQuad); } void TextureManager::free() { if (_texture != nullptr) { SDL_DestroyTexture(_texture); _texture = nullptr; _width = 0; _height = 0; } } Player.h #pragma once #include "TextureManager.h" class Player { public: Player(void); ~Player(void); void draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer); private: TextureManager _textureManager; }; Player.cpp #include "Player.h" Player::Player(void) { } Player::~Player(void) { } void Player::draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer) { _textureManager.draw(x, y, clip, renderer); }
  4. hi, I just wondering if there is an open source/resources SDL spritebatch?
  5. Hi, I'm trying to install sdl2 in visual studio 2015, and I'm having errors that I don't have in visual studio 2010.   1>------ Build started: Project: Mario Clone, Configuration: Debug Win32 ------ 1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError 1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external symbol __imp____iob_func referenced in function _ShowError 1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\OLDNAMES.lib : warning LNK4272: library machine type 'UNKNOWN' conflicts with target machine type 'X86' 1>C:\Users\Acer Aspire\Documents\Visual Studio 2015\Projects\Mario Clone\Debug\Mario Clone.exe : fatal error LNK1120: 2 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========   I'm trying to refactor my game but I this error while testing this simple code.   #include <SDL\SDL.h> int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_EVERYTHING); return 0; } I include the x86 sdl lib, and target x86 machine, i also used Multi-threaded DLL (/MD) to remove this error: ?warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!