 |
BARE2D
|
|
Go to the documentation of this file.
59 std::vector<unsigned char> fileData;
70 std::vector<unsigned char> textureData;
71 unsigned long width, height;
72 int errCode =
decodePNG(textureData, width, height, &(fileData[0]), fileData.size());
73 loadedTex->
width = width;
74 loadedTex->
height = height;
84 glGenTextures((GLsizei)1, &(loadedTex->
id));
90 glTexImage2D(GL_TEXTURE_2D, (GLint)0, GL_RGBA, (GLsizei)loadedTex->
width, (GLsizei)loadedTex->
height, (GLint)0,
91 GL_RGBA, GL_UNSIGNED_BYTE, &(textureData[0]));
94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
96 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
97 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
100 glGenerateTextureMipmap(loadedTex->
id);
113 GLenum minMagFilter ,
114 unsigned int channels ,
124 glGenTextures(1, &(tex->
id));
139 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE,
nullptr);
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, minMagFilter);
146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minMagFilter);
172 Mix_Chunk* chunk = Mix_LoadWAV(fullPath.c_str());
181 created->
chunk = chunk;
197 Mix_Music* musicChunk = Mix_LoadMUS(fullPath.c_str());
206 created->
music = musicChunk;
227 std::string scriptSource =
"";
238 script->
m_path = fullPath;
257 script->
m_path =
"NO_PATH";
static void setAssetsPathPrefix(std::string prefix)
Changes the prefix that will be prepended to all paths when resources are loaded.
Essentially just a wrapper for the SDL TTF_Font type.
static Cache< std::string, LuaScript > * m_scripts
static Logger * getInstance()
static Cache< std::string, Sound > * m_sounds
int decodePNG(std::vector< unsigned char > &out_image, unsigned long &image_width, unsigned long &image_height, const unsigned char *in_png, std::size_t in_size, bool convert_to_rgba32)
const char * vertShaderSource
void bindTexture(GLenum target, GLenum texture)
Binds a texture to target in the currently active texture slot.
static Cache< std::string, Texture > * m_textures
static std::string m_assetsPathPrefix
The texture struct holds very basic stuff - the filepath, width, height, and ID,.
static Sound loadSound(std::string &soundPath)
Loads a sound from the filepath given from the cache or from the file if the cache doesn't contain it...
static MutableTexture * createMutableTexture(std::string &textureName, unsigned int width, unsigned int height, GLenum minMagFilter=GL_LINEAR, unsigned int channels=4, GLenum format=GL_RGBA)
Creates a new mutable texture, or replaces one that exists with a new texture.
static ShaderProgram loadShadersFromSource(std::string &vertShaderSource, std::string &fragShaderSource)
Loads some shaders from their source. Does not cache.
void log(std::string message, bool important=false)
Logs a message to a file and the terminal.
static void clearCaches()
Clears the various caches. This is useful for debugging.
void compileShaders(const char *vertexShaderPath, const char *fragmentShaderPath)
Compiles the shaders. Does not link them.
static LuaScript loadScript(std::string &scriptPath)
Loads a script from the filepath given from the cache or from the file if it's not already in the cac...
A child of Texture which allows (and gives helpful functions for) mutation.
const char * fragShaderSource
static MutableTexture * loadMutableTexture(std::string &textureName)
Gets a texture from the cache, or creates a new, empty texture.
static Cache< std::string, MutableTexture > * m_mutableTextures
static ShaderProgram loadShaders(std::string &vertShaderPath, std::string &fragShaderPath)
Loads some shaders. Combines both to give a full shader program. Does not cache.
static bool readFileToBuffer(std::string &filepath, std::vector< T > &buf, std::ios_base::openmode mode=std::ios::binary)
Loads a file into a buffer.
static Cache< std::string, Music > * m_music
static Texture loadTexture(std::string &texturePath)
Loads a texture if it isn't already in the cache.
The ShaderProgram is a GLSL program which combines two shaders - the vertex shader and the fragment s...
static std::string getAssetsPathPrefix()
Returns the assets path prefix. Pretty simple.
static LuaScript loadScriptFromSource(std::string &scriptSource, std::string name)
Creates and caches a script from the given source code.
static Music loadMusic(std::string &musicPath)
Loads some music from the filepath given from the cache or from the file if the cache doesn't contain...
static GLContext * getContext()
static void setTexturePathPrefix(std::string prefix)
Changes the prefix that will be prepended to all texture paths when they're loaded.
static std::string m_texturePathPrefix
static Font loadFont(std::string &fontPath, int size)
Loads a font to the cache.
void init(const char *fontFile, int size)
Creates font resources.
void throwFatalError(BAREError err, std::string message)
Throws an error (fatal). Also calls displayErrors and exits the program.
void compileShadersFromSource(const char *vertexSource, const char *fragmentSource)
Similar to compileShaders, this just compiles the shaders.
static Cache< std::string, Font > * m_fonts