source: Graphics/image2.h @ 14

Revision 14, 2.3 KB checked in by chris, 4 years ago (diff)

Graphics/Image? work

Line 
1/*
2 * Filename      : image2.h
3 * Author(s)     : Chris Thielen (chris@epiar.net)
4 * Date Created  : Saturday, January 31, 2009
5 * Purpose       : Image loading and display
6 * Notes         : You don't have to worry about OpenGL's power of 2 image dimension requirements.
7 *                 This class will scale for you while still displaying correctly.
8 *                 When editing this class, there are a number of curious variables and conventions to
9 *                 pay attention to. The real width/height of the image (rw, rh) is rarely used - it is
10 *                 the true width and height of the image according to OpenGL. However, as we often expand
11 *                 images whose dimensions weren't a power of two, but must be for proper OpenGL texture
12 *                 size requirements, we may internally expand the dimensions of the image (thus the rw,rh grow)
13 *                 but the w/h is still effectively (at least as far as we care on the outside) whatever non-
14 *                 power of two dimensions, and these effective, "fake" dimensions are called it's _virtual_
15 *                 dimensions, or virtual width/height, stored in w, h.
16 */
17
18#ifndef __H_IMAGE2__
19#define __H_IMAGE2__
20
21#include "includes.h"
22
23class Image2 {
24        public:
25                // Create instance by loading image from file
26                Image2( string filename );
27
28                // Load image from file
29                bool Load( string filename );
30                // Load image from buffer
31                bool Load( unsigned char *buf, int bufSize );
32
33                // Get information about image dimensions (always the virtual/effective size)
34                int GetWidth( void ) { return w; };
35                int GetHeight( void ) { return h; };
36                int GetHalfWidth( void ) { return w / 2; };
37                int GetHalfHeight( void ) { return h / 2; };
38
39                // Draw the image
40                void Draw( int x, int y, float angle = 0. );
41                // Draw the image centered on (x,y)
42                void DrawCentered( int x, int y, float angle = 0. );
43
44        private:
45                // Expands surface 's' to width/height of w/h, keeping the original image in the upper-left
46                SDL_Surface *ExpandCanvas( SDL_Surface *s, int w, int h );
47
48                int w, h; // virtual w/h (effective, same as original file)
49                int rw, rh; // real w/h, size of expanded canvas (image) should expansion be needed
50                            //   to meet power of two requirements
51                GLuint image; // OpenGL pointer to texture
52};
53
54#endif // __H_IMAGE2__
55
Note: See TracBrowser for help on using the repository browser.