[go: up one dir, main page]

Menu

[ea6c30]: / media / Texture_Image.h  Maximize  Restore  History

Download this file

112 lines (94 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
// Texture_Image.cc - 2D textures from PNG images.
//
// Vamos Automotive Simulator
// Copyright (C) 2001--2005 Sam Varner
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef _TEXTURE_IMAGE_H_
#define _TEXTURE_IMAGE_H_
#ifdef WIN32
# define WINDOWS_LEAN_AND_MEAN 1
# define NOMINMAX 1 // Do not define MS' min()/max() macros.
# include <windows.h>
#endif
#include <GL/gl.h>
#include <string>
#include <map>
namespace Vamos_Media
{
// Exception class for texture files that can't be found.
class Missing_Texture_File
{
std::string m_file;
public:
Missing_Texture_File (std::string file) : m_file (file) {};
std::string message () const { return m_file; }
};
class Texture_Image
{
std::string m_file_name;
int m_channels;
int m_width_pixels;
int m_height_pixels;
double m_width;
double m_height;
GLuint m_texture_name;
void initialize (bool smooth, bool mip_map, int texture_wrap);
unsigned char* read_png_file (std::string file_name);
void set_gl_parameters (unsigned char* data,
bool smooth,
bool mip_map,
int texture_wrap);
public:
Texture_Image (std::string file_name,
bool smooth = false,
bool mip_map = false,
double width = 1.0,
double height = 1.0,
int texture_wrap = GL_REPEAT);
Texture_Image (std::string file_name,
bool smooth,
bool mip_map,
int texture_wrap);
Texture_Image () {};
~Texture_Image ();
int width_pixels () const { return m_width_pixels; }
int height_pixels () const { return m_height_pixels; }
double aspect_ratio () const
{ return double (m_width_pixels) / m_height_pixels; }
void set_width (double width) { m_width = width; }
void set_height (double height) { m_height = height; }
double width () const { return m_width; }
double height () const { return m_height; }
void activate () const;
};
class Facade : public Texture_Image
{
bool m_draw_back;
double m_x_offset;
double m_y_offset;
double m_z_offset;
public:
Facade (std::string image_name, bool draw_back = false);
// If `draw_back' is true, draw a solid-color rectangle for the
// back of the image.
void set_radius (double radius);
void set_x_offset (double offset) { m_x_offset = offset; }
void set_y_offset (double offset) { m_y_offset = offset; }
void set_z_offset (double offset) { m_z_offset = offset; }
void draw () const;
};
}
#endif // not _TEXTURE_IMAGE_H_