spacebox/src/Texture.hpp

67 lines
1.8 KiB
C++

/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+--------------+
[Texture.hpp]
The Texture class abstracts the file opening, data loading and binding steps of Open GL
texture creation. Currently it only supports loading GL_TEXTURE_2D with GL_RGB8 pixels
and automatic GL_NEAREST mipmapping. Support may be added for users to pass in their own
pixel data, to customize mipmapping, and more.
*/
#ifndef Texture_h_
#define Texture_h_
#include <stdexcept>
#include "SDL.h"
#include "SDL_image.h"
#include "sdl2-gfx/SDL2_rotozoom.h"
#include "filesystem.hpp"
#include "GLObject.hpp"
#include "Game.hpp"
/* include Open GL */
#if defined(__EMSCRIPTEN__)
#include <GL/glew.h>
#else
#include "glew/glew.h"
#endif
class Texture : public GLObject
{
private:
fs::path path = "";
public:
Texture();
Texture(fs::path);
void associate(fs::path);
void generate() override;
void generate(glm::vec2);
void load();
void load(fs::path);
void load(SDL_RWops*);
void load(SDL_Surface*);
void load(void*, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
void load(void*, glm::vec2, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
void bind() const override;
glm::vec2 size() const;
bool operator==(const Texture&) const;
};
void texture_deleter(GLuint*);
#endif