Added render functions, now moving everything to use rect and render functions

This commit is contained in:
Ben
2018-10-08 13:32:20 +01:00
parent 5e5f4b5d0f
commit 91cc2343e4
3 changed files with 47 additions and 8 deletions

View File

@@ -45,8 +45,8 @@ public:
virtual ~Entity();
protected:
// std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine";
std::string PATH = "E:/Games/crumpet-engine";
std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine";
// std::string PATH = "E:/Games/crumpet-engine";
private:
std::string m_name;

View File

@@ -35,11 +35,45 @@ void Renderer::RenderSprite(Sprite* sprite) {
}
void Renderer::SetRendererColour(Vec4* col) {
SDL_SetRenderDrawColor(SDLRenderer, col->x, col->y, col->z, col->w);
}
void Renderer::RenderEmptyRect() {
void Renderer::RenderEmptyRect(Rect* rect) {
SDL_RenderDrawRect(SDLRenderer, rect->ToSDLRect);
}
void Renderer::RenderFilledRect(Rect* rect) {
SDL_RenderFillRect(SDLRenderer, rect->ToSDLRect);
}
void Renderer::RenderLines(std::vector<Vec4*> points) {
for (unsigned int i = 0; i < points.size(); i++) {
SDL_RenderDrawLine(SDLRenderer, points[i]->x, points[i]->y, points[i]->z, points[i]->w);
}
}
void Renderer::RenderTexture(Rect* fromRect, Rect* toRect, SDL_Texture* texture) {
SDL_RenderCopy(SDLRenderer, texture, fromRect->ToSDLRect(), toRect->ToSDLRect());
}
void Renderer::RenderTexture(Rect* fromRect, Rect* toRect, SDL_Surface* surface) {
SDL_Texture* texture = SDL_CreateTextureFromSurface(SDLRenderer, surface);
SDL_RenderCopy(SDLRenderer, texture, fromRect->ToSDLRect(), toRect->ToSDLRect());
SDL_DestroyTexture(texture);
}
void Renderer::RenderTexture(Rect* fromRect, Rect* toRect, SDL_Texture* texture, const double angle, Vec2* rotationCenter) {
SDL_Point temp = { rotationCenter->x, rotationCenter->y };
SDL_Point* center = new SDL_Point(temp);
SDL_RenderCopyEx(SDLRenderer, texture, fromRect->ToSDLRect(), toRect->ToSDLRect(), angle, center, SDL_FLIP_NONE);
}
void Renderer::RenderTexture(Rect* fromRect, Rect* toRect, SDL_Surface* surface, const double angle, Vec2* rotationCenter) {
SDL_Point temp = { rotationCenter->x, rotationCenter->y };
SDL_Point* center = new SDL_Point(temp);
SDL_Texture* texture = SDL_CreateTextureFromSurface(SDLRenderer, surface);
SDL_RenderCopyEx(SDLRenderer, texture, fromRect->ToSDLRect(), toRect->ToSDLRect(), angle, center, SDL_FLIP_NONE);
SDL_DestroyTexture(texture);
}
void Renderer::RenderUpdate() {

View File

@@ -2,9 +2,11 @@
#include <iostream>
#include <string>
#include <vector>
#include <SDL.h>
#include "entity.h"
#include "sprite.h"
#include "rect.h"
class Renderer {
public:
@@ -19,10 +21,13 @@ public:
void SetRendererColour(Vec4* col);
void RenderEmptyRect();
void RenderFilledRect();
void RenderLines();
void RenderTexture();
void RenderEmptyRect(Rect* rect);
void RenderFilledRect(Rect* rect);
void RenderLines(std::vector<Vec4*> points);
void RenderTexture(Rect* fromRect, Rect* toRect, SDL_Texture* texture);
void RenderTexture(Rect* fromRect, Rect* toRect, SDL_Surface* surface);
void RenderTexture(Rect* fromRect, Rect* toRect, SDL_Texture* surface, const double angle, Vec2* rotationCenter);
void RenderTexture(Rect* fromRect, Rect* toRect, SDL_Surface* surface, const double angle, Vec2* rotationCenter);
void RenderUpdate();
void RenderClear();