This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <vector> | |
class Bike{ | |
public: | |
void Peddle(){ | |
moving = true; | |
} | |
virtual void Move(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//New rendering methods | |
//Now we use an SDL_Texture to use hardware accelerated rendering | |
//create window at 100, 100 with width 640 and height 480 and show it | |
SDL_Window *win = SDL_CreateWindow("Window", 100, 100, 640, 480, SDL_WINDOW_SHOWN); | |
//create a renderer that draws to win with hardware acceleration and vsync | |
SDL_Renderer *rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); | |
//Load our image and convert to texture | |
SDL_Surface *img = SDL_LoadBMP("image.bmp"); | |
//Create the texture, requires the rendering context so it knows what formatting we desire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDL_Texture* LoadImage(std::string file){ | |
SDL_Texture* tex = nullptr; | |
tex = IMG_LoadTexture(renderer, file.c_str()); | |
if (tex == nullptr) | |
throw std::runtime_error("Failed to load image: " + file); | |
return tex; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SDL.h" | |
int main(int argc, char** argv){ | |
SDL_Init(SDL_INIT_EVERYTHING); | |
SDL_Quit(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(int argc, char** argv){ | |
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){ | |
std::cout << SDL_GetError() << std::endl; | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SDL.h" | |
#include <string> | |
const int SCREEN_WIDTH = 640; | |
const int SCREEN_HEIGHT = 480; | |
SDL_Window *window = nullptr; | |
SDL_Renderer *renderer = nullptr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SDL.h" | |
#include "SDL_image.h" | |
#include <stdexcept> | |
#include <string> | |
#include <iostream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In main... | |
SDL_Texture *image = nullptr; | |
try { | |
image = LoadImage("../res/Lesson4/image.png"); | |
} | |
catch (const std::runtime_error &e){ | |
std::cout << e.what() << std::endl; | |
return 4; | |
} | |
int iW, iH; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Variable declaration in the class | |
static std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> mWindow; | |
//Assignment of a value to the variable | |
//I create a unique pointer of the same type with the data I want and then swap it with the member variable | |
std::unique_ptr<SDL_Window, void (*)(SDL_Window*)> win(SDL_CreateWindow(title.c_str(), 100, 100, | |
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE), SDL_DestroyWindow); | |
std::swap(win, mWindow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDL_RenderCopy(rend, tex, NULL, &pos); |
OlderNewer