-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderWindow.cpp
More file actions
45 lines (45 loc) · 1.59 KB
/
RenderWindow.cpp
File metadata and controls
45 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<SDL.h>
#include<SDL_image.h>
#include<iostream>
#include"Entity.h"
#include"RenderWindow.hpp"
using namespace std;
RenderWindow::RenderWindow(const char* p_title, int p_width, int p_height)
:window(NULL), renderer(NULL)
{
window = SDL_CreateWindow(p_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, p_width, p_height, SDL_WINDOW_SHOWN);
if(window == NULL) cout<<"Window failed to init"<<SDL_GetError()<<endl;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
}
SDL_Texture* RenderWindow::loadTexture(const char* p_filepath)
{
SDL_Texture* texture = NULL;
texture = IMG_LoadTexture(renderer, p_filepath);
if(texture == NULL) cout<<"Falied in LoadTexture"<<SDL_GetError()<<endl;
return texture;
}
void RenderWindow::cleanUp()
{
SDL_DestroyWindow(window);
}
void RenderWindow::clear(){
SDL_RenderClear(renderer);
}
void RenderWindow::render(Entity &p_entity){
SDL_Rect src, dst;
src.x=p_entity.getCurrentFrame().x;
src.y=p_entity.getCurrentFrame().y;
src.w=p_entity.getCurrentFrame().w;
src.h=p_entity.getCurrentFrame().h;
dst.x=p_entity.getX();
dst.y=p_entity.getY();
dst.w=p_entity.getCurrentFrame().w;
dst.h=p_entity.getCurrentFrame().h;
SDL_RenderCopy(renderer, p_entity.getTex(), &src, &dst);
}
void RenderWindow::Background(SDL_Texture* bg){
SDL_RenderCopy(renderer, bg, NULL, NULL);
}
void RenderWindow::display(){
SDL_RenderPresent(renderer);
}