-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjustet .gitignore added Texture wrapper class
- Loading branch information
Finn Krein
committed
Mar 21, 2017
1 parent
96a88ca
commit 686fa3f
Showing
4 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,9 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
# vim buffers | ||
*.swp | ||
*.un~ | ||
*.h~ | ||
*.cc~ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "lTexture.h" | ||
|
||
void lTexture::free() | ||
{ | ||
if (mTexture != NULL) | ||
{ | ||
SDL_DestroyTexture(mTexture); | ||
mTexture=NULL; | ||
mHeight=0; | ||
mWidth=0; | ||
} | ||
} | ||
lTexture::lTexture(SDL_Renderer* Renderer) | ||
{ | ||
mRenderer=Renderer; | ||
mTexture = NULL; | ||
mWidth = 0; | ||
mHeight = 0; | ||
} | ||
|
||
lTexture::~lTexture() | ||
{ | ||
free(); | ||
mRenderer=NULL; | ||
} | ||
|
||
bool lTexture::setFont(TTF_Font* Font) | ||
{ | ||
mFont=NULL; | ||
mFont=Font; | ||
return (mFont != NULL); | ||
|
||
} | ||
|
||
bool lTexture::setRenderer(SDL_Renderer* Renderer) | ||
{ | ||
mRenderer=NULL; | ||
mRenderer=Renderer; | ||
return (mRenderer != NULL); | ||
} | ||
bool lTexture::loadfromFile(std::string path) | ||
{ | ||
SDL_Texture* newTexture = NULL; | ||
SDL_Surface* loadedSurface = IMG_Load(path.c_str()); | ||
if (loadedSurface == NULL) | ||
{ | ||
printf("Bild konnte nicht geladen werden. IMG_Error: %s\n",IMG_GetError()); | ||
} | ||
else | ||
{ | ||
newTexture = SDL_CreateTextureFromSurface(mRenderer,loadedSurface); | ||
if (newTexture == NULL) | ||
{ | ||
printf("Konnte keine Textur aus %s erstellen. SDL_Error: %s\n",path.c_str(),SDL_GetError()); | ||
} | ||
else | ||
{ | ||
mHeight = loadedSurface->h; | ||
mWidth = loadedSurface->w; | ||
} | ||
} | ||
SDL_FreeSurface(loadedSurface); | ||
mTexture=newTexture; | ||
return (mTexture != NULL); | ||
} | ||
// #ifdef _SLD_TTF_H | ||
bool lTexture::loadfromText(std::string text,SDL_Color textcolor, TTF_Font* font) | ||
{ | ||
free(); | ||
if (font != NULL) | ||
{mFont=font; | ||
} | ||
if (mFont != NULL) | ||
{ | ||
SDL_Surface* textSurface= TTF_RenderText_Solid(mFont,text.c_str(),textcolor); | ||
if (textSurface==NULL) | ||
{ | ||
printf("Text konnte nicht gerendert werden. TTF_Error= %s\n",TTF_GetError()); | ||
} | ||
else | ||
{ | ||
mTexture = SDL_CreateTextureFromSurface(mRenderer,textSurface); | ||
if (mTexture==NULL) | ||
{ | ||
printf("Konnte keine Textur aus gerendertem Text erstellen. SDL_Error: %s\n",SDL_GetError()); | ||
} | ||
else | ||
{ | ||
mHeight=textSurface->h; | ||
mWidth=textSurface->w; | ||
} | ||
SDL_FreeSurface(textSurface); | ||
} | ||
} | ||
else | ||
{printf("Keine Schriftart angegeben!"); | ||
} | ||
return (mTexture != NULL); | ||
} | ||
// #endif | ||
lTexture::lTexture(std::string path,SDL_Renderer* Renderer) | ||
{ | ||
mRenderer=Renderer; | ||
loadfromFile(path); | ||
} | ||
|
||
int lTexture::getWidth() | ||
{ | ||
return mWidth; | ||
} | ||
int lTexture::getHeight() | ||
{ | ||
return mHeight; | ||
} | ||
|
||
void lTexture::render(SDL_Rect* space, SDL_Rect* clip,double angle,SDL_Point* center,SDL_RendererFlip flip) | ||
{ | ||
SDL_RenderCopyEx(mRenderer,mTexture,clip,space,angle,center,flip); | ||
} | ||
|
||
void lTexture::render(int x, int y, SDL_Rect* clip,double angle,SDL_Point* center,SDL_RendererFlip flip) | ||
{ | ||
SDL_Rect renderRect = {x,y,mWidth,mHeight}; | ||
if (clip != NULL) | ||
{ | ||
renderRect.w=clip->w; | ||
renderRect.h=clip->h; | ||
} | ||
render(&renderRect,clip,angle,center,flip); | ||
} | ||
void lTexture::setColor(Uint8 red,Uint8 green,Uint8 blue) | ||
{ | ||
SDL_SetTextureColorMod(mTexture,red, green, blue); | ||
} | ||
void lTexture::setAlpha(Uint8 alpha) | ||
{ | ||
SDL_SetTextureAlphaMod(mTexture,alpha); | ||
} | ||
|
||
void lTexture::setBlendMode(SDL_BlendMode blending) | ||
{ | ||
SDL_SetTextureBlendMode(mTexture,blending); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef lTEXTURE | ||
#define lTEXTURE | ||
#include <SDL2/SDL.h> | ||
#include <SDL2/SDL_image.h> | ||
#include <stdio.h> | ||
#include <string> | ||
#include <SDL2/SDL_ttf.h> | ||
class lTexture | ||
{ | ||
public: | ||
lTexture(SDL_Renderer* Renderer=NULL); | ||
lTexture(std::string path,SDL_Renderer* Renderer=NULL); //Initialization constructor | ||
~lTexture(); | ||
bool setRenderer(SDL_Renderer* Renderer); | ||
bool loadfromFile(std::string path); | ||
// #ifdef _SDL_TTF_H | ||
bool loadfromText(std::string text,SDL_Color textcolor = {0,0,0},TTF_Font* Font=NULL); | ||
// #endif | ||
void free(); | ||
int getHeight(); | ||
int getWidth(); | ||
void render(int x, int y, SDL_Rect* clip=NULL,double angle=0,SDL_Point* center=NULL,SDL_RendererFlip flip=SDL_FLIP_NONE); | ||
void render(SDL_Rect* space, SDL_Rect* clip=NULL,double angle=0,SDL_Point* center=NULL,SDL_RendererFlip flip=SDL_FLIP_NONE); | ||
bool setFont(TTF_Font* Font); | ||
void setColor(Uint8 red,Uint8 green,Uint8 blue); | ||
void setAlpha(Uint8 alpha); | ||
void setBlendMode(SDL_BlendMode blending); | ||
private: | ||
SDL_Renderer* mRenderer; | ||
int mWidth; | ||
int mHeight; | ||
TTF_Font* mFont; | ||
SDL_Texture* mTexture; | ||
}; | ||
#endif |