1 #pragma once 2 //******************************************************************************************** 3 //* 4 //* This file is part of the opengl extensions library. This library is 5 //* distributed with Egoboo. 6 //* 7 //* Egoboo is free software: you can redistribute it and/or modify it 8 //* under the terms of the GNU General Public License as published by 9 //* the Free Software Foundation, either version 3 of the License, or 10 //* (at your option) any later version. 11 //* 12 //* Egoboo is distributed in the hope that it will be useful, but 13 //* WITHOUT ANY WARRANTY; without even the implied warranty of 14 //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 //* General Public License for more details. 16 //* 17 //* You should have received a copy of the GNU General Public License 18 //* along with Egoboo. If not, see <http://www.gnu.org/licenses/>. 19 //* 20 //******************************************************************************************** 21 22 /// @defgroup _ogl_extensions_ Extensions to OpenGL 23 24 /// @file extensions/ogl_texture.h 25 /// @ingroup _ogl_extensions_ 26 /// @brief Definitions for OpenGL texture loading using SDL_image 27 /// @details 28 29 #include "ogl_include.h" 30 #include "ogl_debug.h" 31 #include "egoboo_typedef.h" 32 33 #include "ogl_extensions.h" 34 35 #include <SDL.h> 36 37 //-------------------------------------------------------------------------------------------- 38 //-------------------------------------------------------------------------------------------- 39 40 #define INVALID_KEY ( (Uint32) (~0) ) 41 42 #define VALID_BINDING( BIND ) ( (0 != (BIND)) && (INVALID_GL_ID != (BIND)) ) 43 #define ERROR_IMAGE_BINDING( BIND ) ( ErrorImage_get_binding() == (BIND) ) 44 45 /// OpenGL Texture filtering methods 46 typedef enum e_tx_filters 47 { 48 TX_UNFILTERED, 49 TX_LINEAR, 50 TX_MIPMAP, 51 TX_BILINEAR, 52 TX_TRILINEAR_1, 53 TX_TRILINEAR_2, 54 TX_ANISOTROPIC, 55 TX_FILTER_COUNT 56 } TX_FILTERS; 57 58 //-------------------------------------------------------------------------------------------- 59 //-------------------------------------------------------------------------------------------- 60 61 struct s_oglx_texture 62 { 63 GLboolean base_valid; 64 gl_texture_t base; 65 66 GLuint valid; ///< whether or not the texture has been initialized 67 char name[256]; ///< the name of the original file 68 int imgW, imgH; ///< the height & width of the texture data 69 70 SDL_Surface * surface; ///< the original texture data 71 SDL_bool has_alpha; ///< the alpha for the texture 72 }; 73 typedef struct s_oglx_texture oglx_texture_t; 74 75 GLuint oglx_texture_Convert( oglx_texture_t *texture, SDL_Surface * pimage, Uint32 key ); 76 GLuint oglx_texture_Load( oglx_texture_t *texture, const char *filename, Uint32 key ); 77 GLuint oglx_texture_GetTextureID( oglx_texture_t *texture ); 78 GLsizei oglx_texture_GetImageHeight( oglx_texture_t *texture ); 79 GLsizei oglx_texture_GetImageWidth( oglx_texture_t *texture ); 80 GLsizei oglx_texture_GetTextureWidth( oglx_texture_t *texture ); 81 GLsizei oglx_texture_GetTextureHeight( oglx_texture_t *texture ); 82 void oglx_texture_SetAlpha( oglx_texture_t *texture, GLfloat alpha ); 83 GLfloat oglx_texture_GetAlpha( oglx_texture_t *texture ); 84 void oglx_texture_Release( oglx_texture_t *texture ); 85 86 void oglx_texture_Bind( oglx_texture_t * texture ); 87 88 oglx_texture_t * oglx_texture_ctor( oglx_texture_t * texture ); 89 void oglx_texture_dtor( oglx_texture_t * texture ); 90 91 //-------------------------------------------------------------------------------------------- 92 //-------------------------------------------------------------------------------------------- 93 94 struct s_oglx_texture_parameters 95 { 96 TX_FILTERS texturefilter; 97 GLfloat userAnisotropy; 98 }; 99 typedef struct s_oglx_texture_parameters oglx_texture_parameters_t; 100 101 extern oglx_texture_parameters_t tex_params; 102 103 //-------------------------------------------------------------------------------------------- 104 //-------------------------------------------------------------------------------------------- 105 106 void oglx_grab_texture_state( GLenum target, GLint level, oglx_texture_t * texture ); 107 GLboolean oglx_texture_Valid( oglx_texture_t *ptex ); 108 109 GLuint oglx_bind_to_tex_params( GLuint binding, GLenum target, GLint wrap_s, GLint wrap_t ); 110 111 void ErrorImage_bind( GLenum target, GLuint id ); 112 GLuint ErrorImage_get_binding();