NGL  6.5
The NCCA Graphics Library
Texture.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 //----------------------------------------------------------------------------------------------------------------------
20 //----------------------------------------------------------------------------------------------------------------------
21 #include "NGLassert.h"
22 #include "Texture.h"
23 #include <iostream>
24 #include "Util.h"
25 
26 namespace ngl
27 {
28 
29 //----------------------------------------------------------------------------------------------------------------------
30 Texture::Texture( const std::string &_fname )
31 {
32  m_image.load(_fname);
38 }
39 
40 
41 bool Texture::loadImage( const std::string &_fname )
42 {
43  bool status=m_image.load(_fname);
44  if(status)
45  {
51  }
52  return status;
53 }
54 
55 
56 
57 //----------------------------------------------------------------------------------------------------------------------
58 
63 
64 GLuint Texture::setTextureGL() const noexcept
65 {
66  GLuint textureName;
67  glGenTextures(1,&textureName);
69  glBindTexture(GL_TEXTURE_2D,textureName);
72 
74 
75  std::cout<<"texture GL set "<<textureName<<" Active Texture "<<m_multiTextureID<<"\n";
77  return textureName;
78 }
79 //----------------------------------------------------------------------------------------------------------------------
80 
81 void Texture::setMultiTexture( const GLint _id ) noexcept
82 {
83  m_multiTextureID=_id;
84 }
85 
86 
87 
88 } // end namespace ngl;
89 
90 //----------------------------------------------------------------------------------------------------------------------
91 
a simple texture loader / GL texture object
some useful definitions and functions
unsigned int GLuint
Definition: glew.h:280
#define GL_TEXTURE0
Definition: glew.h:1292
GLuint m_format
the image format (i.e rgb or rgba)
Definition: Texture.h:129
GLAPI void GLAPIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
GLuint setTextureGL() const noexcept
set the image as an OpenGL texture object
Definition: Texture.cpp:64
#define GL_UNSIGNED_BYTE
Definition: glew.h:637
#define GL_LINEAR
Definition: glew.h:718
implementation files for RibExport class
Definition: AABB.cpp:22
void setMultiTexture(const GLint _id) noexcept
set the texture object to be different texture in multitexture
Definition: Texture.cpp:81
GLuint format() const noexcept
Get the pixel format.
Definition: Image.h:90
GLuint channels() const noexcept
gets the number of channels
Definition: Image.h:95
GLuint width() const noexcept
Get the width of the texture.
Definition: Image.h:80
GLAPI void GLAPIENTRY glBindTexture(GLenum target, GLuint texture)
#define glGenerateMipmap
Definition: glew.h:4579
GLint m_multiTextureID
the MultiTexture ID for the current texture Object
Definition: Texture.h:125
Image m_image
the actual image data loaded packed in r,g,b,a format in contiguous memory stored in a smart_pointer ...
Definition: Texture.h:109
Texture()=default
Constructor using no parameters.
GLuint m_width
the size of the image in the X direction
Definition: Texture.h:113
GLAPI void GLAPIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
#define GL_TEXTURE_MIN_FILTER
Definition: glew.h:724
unsigned char * getPixels() const noexcept
raw access to unsigned char pixel data
Definition: Image.h:64
#define GL_TEXTURE_MAG_FILTER
Definition: glew.h:723
GLAPI void GLAPIENTRY glGenTextures(GLsizei n, GLuint *textures)
bool loadImage(const std::string &_fname)
method to load the image file into the texture class
Definition: Texture.cpp:41
GLuint m_channels
A pointer to the start of the image data.
Definition: Texture.h:121
GLuint m_height
the size of the image in the Y direction
Definition: Texture.h:117
int GLint
Definition: glew.h:281
bool load(const std::string &_fname) noexcept
load the image data, this will clear the previous data and attempt to load the new image data ...
re impliment asserts so we don&#39;t exit on failure
#define GL_TEXTURE_2D
Definition: glew.h:10194
GLsizei const GLchar *const * string
Definition: glew.h:1847
GLuint height() const noexcept
Get the height of the texture.
Definition: Image.h:85
#define glActiveTexture
Definition: glew.h:1427