Repository navigation
Expand file tree
/
Copy pathgraphics.cpp
More file actions
78 lines (75 loc) · 2.36 KB
/
Copy pathgraphics.cpp
File metadata and controls
78 lines (75 loc) · 2.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <windows.h>
#include <SDL.h>
#include <SDL_image.h>
#include <managers.h>
int SCREEN_HEIGHT = 480;
int SCREEN_WIDTH = 640;
const int LEVEL_WIDTH = 1280;
const int LEVEL_HEIGHT = 960;
GraphicsManager* Graphics;
void GraphicsManager::setColor(int color){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
GraphicsManager::GraphicsManager(){
if (SDL_Init(SDL_INIT_VIDEO) < 0){
setColor(red);
std::cout << SDL_GetError() << "\n";
setColor();
}else{
window = SDL_CreateWindow( "cheto tam", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
ourRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
}
initTextures();
Graphics = this;
}
void GraphicsManager::render(void* pt, int type, color* Color){
switch(type){
case rectangleRender:
{
if (Color == NULL){
static color* defaultColor = new color;
defaultColor->r = 255;
Color = defaultColor;
}
SDL_Rect* rect = (SDL_Rect*)pt;
SDL_SetRenderDrawColor(ourRenderer, Color->r, Color->g, Color->b, Color->a);
SDL_RenderFillRect(ourRenderer, rect);
}
break;
case spriteRender:
SDL_RenderCopy(ourRenderer, ((Texture*)pt)->first, NULL, ((Texture*)pt)->second);
break;
}
}
/*void renderAll(const std::vector<entity*>& ents){
SDL_SetRenderDrawColor(ourRenderer, 255, 255, 255, 0);
SDL_RenderClear(ourRenderer);
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) ) { printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() ); }
for(int i = 0; i < ents.size(); ++i){
ents[i]->renderMe();
}
SDL_RenderPresent(renderer);
}*/
void GraphicsManager::entityRenderBegin(){
SDL_SetRenderDrawColor(ourRenderer, 255, 255, 255, 0);
SDL_RenderClear(ourRenderer);
}
void GraphicsManager::entityRenderFinish(){
SDL_RenderPresent(ourRenderer);
}
SDL_Texture* GraphicsManager::loadFromPath(std::string path){
SDL_Texture* a;
SDL_Surface* load = IMG_Load(path.c_str());
a = SDL_CreateTextureFromSurface(ourRenderer, load);
return a;
}
void GraphicsManager::initTextures(){
for(int i = 0; i < ALWAYS_LAST; ++i){
textures.push_back (loadFromPath("resources/" + textureFnames[i]));
}
}
SDL_Texture* GraphicsManager::getTexture(int type){
return textures[type];
}