cat3d
A tiny OpenGL 3D engine library written in and for C++.
texture.hpp
1 #pragma once
2 
3 #include <GL/glew.h>
4 #include <stb/stb_image.h>
5 #include <string>
6 
7 #include "cat3d/color.hpp"
8 
9 namespace cat3d::gl {
10 
14 enum texture_wrap_mode {
15  REPEAT = GL_REPEAT,
16  MIRRORED_REPEAT = GL_MIRRORED_REPEAT,
17  CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
18  CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER
19 };
20 
21 enum texture_filter_mode {
22  NEAREST = GL_NEAREST,
23  LINEAR = GL_LINEAR
24 };
25 
29 class texture {
30 public:
31  texture();
32 
36  void del();
37 
43  void load_file(const std::string& path);
44 
52  void load_color(color col);
53 
59  void set_wrap_mode(texture_wrap_mode mode);
60 
68 
76  void set_filter_mode(texture_filter_mode mode);
77 
81  void bind();
82 
86  void unbind();
87 
88 private:
90  GLuint m_tex;
91 
93  bool m_loaded;
94 
96  void push_bind_state();
97  void pop_bind_state();
98  bool m_bind_state;
99 };
100 
101 }
cat3d::gl::texture::load_file
void load_file(const std::string &path)
Load a file from the given path.
cat3d::color
Base color class.
Definition: color.hpp:11
cat3d::gl::texture::bind
void bind()
Bind the texture to the opengl context.
cat3d::gl::texture::unbind
void unbind()
Unbind the texture.
cat3d::gl::texture::set_border_color
void set_border_color(color col)
When the texture's wrapping mode is set to CLAMP_TO_BORDER, there needs to be a configured border col...
cat3d::gl::texture::set_wrap_mode
void set_wrap_mode(texture_wrap_mode mode)
Set the texture's wrapping mode.
cat3d::gl::texture::set_filter_mode
void set_filter_mode(texture_filter_mode mode)
Sets the texture's filtering mode.
cat3d::gl::texture::del
void del()
Delete the internal opengl representation.
cat3d::gl::texture::load_color
void load_color(color col)
Load a 1x1 pixel texture of a given color.
cat3d::gl::texture
Internal opengl texture representation.
Definition: texture.hpp:29