Skip to content

Instantly share code, notes, and snippets.

View Twinklebear's full-sized avatar

Will Usher Twinklebear

View GitHub Profile
#include <string>
#include <iostream>
#include <vector>
class Bike{
public:
void Peddle(){
moving = true;
}
virtual void Move(){
@Twinklebear
Twinklebear / new.cpp
Created July 16, 2012 15:08
SDL Rendering methods
//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
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;
}
@Twinklebear
Twinklebear / lesson0.cpp
Created July 19, 2012 00:04
Testing SDL setup
#include "SDL.h"
int main(int argc, char** argv){
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
int main(int argc, char** argv){
if (SDL_Init(SDL_INIT_EVERYTHING) == -1){
std::cout << SDL_GetError() << std::endl;
return 1;
}
#include "SDL.h"
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Window *window = nullptr;
SDL_Renderer *renderer = nullptr;
#include "SDL.h"
#include "SDL_image.h"
#include <stdexcept>
#include <string>
#include <iostream>
//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;
//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);
SDL_RenderCopy(rend, tex, NULL, &pos);