MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
texture2d.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_TEXTURE2D_H_
15 #define SRC_TEXTURE2D_H_
16 
17 
18 #include "opengl_headers.h"
19 #include "color.h"
20 
21 #include <string>
22 
23 
24 namespace mingfx {
25 
42 class Texture2D {
43 public:
44 
47  Texture2D(GLenum wrapMode=GL_REPEAT, GLenum filterMode=GL_LINEAR);
48  virtual ~Texture2D();
49 
50 
55  bool InitFromFile(const std::string &filename);
56 
66  bool InitFromBytes(int width, int height, const unsigned char * data);
67 
77  bool InitFromFloats(int width, int height, const float * data);
78 
79 
83  bool UpdateFromBytes(const unsigned char * data);
84 
88  bool UpdateFromFloats(const float * data);
89 
90 
92  bool initialized() const;
93 
95  int width() const;
96 
98  int height() const;
99 
101  GLuint opengl_id() const;
102 
104  GLenum wrap_mode() const;
105 
107  GLenum filter_mode() const;
108 
110  void set_wrap_mode(GLenum wrapMode);
111 
113  void set_filter_mode(GLenum filterMode);
114 
117  Color Pixel(int x, int y) const;
118 
119 private:
120 
121  bool InitOpenGL();
122 
123  GLenum dataType_; // GL_UNSIGNED_BYTE or GL_FLOAT
124  const unsigned char * data_ubyte_;
125  const float * data_float_;
126 
127  int width_;
128  int height_;
129  bool handleMemInternally_;
130 
131  GLuint texID_;
132  GLenum wrapMode_;
133  GLenum filterMode_;
134 };
135 
136 
137 } // end namespace
138 
139 #endif
Represents a 4-component (R,G,B,A) color, stored internally in a float array to be compatable with Op...
Definition: color.h:41
A wrapper around a 2D texture that supports loading images from files or setting texture color data d...
Definition: texture2d.h:42
bool UpdateFromBytes(const unsigned char *data)
This function may be called to re-read the texture data from an array formated the same as in InitFro...
bool initialized() const
Returns true if the texture data has been successfully transferred to OpenGL.
GLenum wrap_mode() const
Returns an enumerated constant for the OpenGL wrap mode used by the texture.
Color Pixel(int x, int y) const
Returns the color at the specified pixel. The top left corner of the image is (0,0) and the bottom ri...
int height() const
Returns the height in pixels of the texture.
int width() const
Returns the width in pixels of the texture.
void set_filter_mode(GLenum filterMode)
Uses the OpenGL texture filter mode arguments.
bool InitFromFile(const std::string &filename)
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's int...
Texture2D(GLenum wrapMode=GL_REPEAT, GLenum filterMode=GL_LINEAR)
Creates an empty texture. Optional parameters can be provided to set the texture wrap mode and filter...
void set_wrap_mode(GLenum wrapMode)
Uses the OpenGL texture wrap mode arguments.
virtual ~Texture2D()
bool InitFromBytes(int width, int height, const unsigned char *data)
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's int...
GLuint opengl_id() const
Returns the unsigned int used as the texture handle by OpenGL.
bool UpdateFromFloats(const float *data)
This function may be called to re-read the texture data from an array formated the same as in InitFro...
bool InitFromFloats(int width, int height, const float *data)
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's int...
GLenum filter_mode() const
Returns an enumerated constant for the OpenGL filter mode used by the texture.
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21