naev 0.10.4
opengl_tex.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <stdint.h>
8#include "SDL.h"
11#include "colour.h"
12#include "physics.h"
13
14/* Recommended for compatibility and such */
15#define RMASK SDL_SwapLE32(0x000000ff)
16#define GMASK SDL_SwapLE32(0x0000ff00)
17#define BMASK SDL_SwapLE32(0x00ff0000)
18#define AMASK SDL_SwapLE32(0xff000000)
19#define RGBAMASK RMASK,GMASK,BMASK,AMASK
20
21/*
22 * Texture flags.
23 */
24#define OPENGL_TEX_MAPTRANS (1<<0)
25#define OPENGL_TEX_MIPMAPS (1<<1)
26#define OPENGL_TEX_VFLIP (1<<2)
27#define OPENGL_TEX_SKIPCACHE (1<<3)
34typedef struct glTexture_ {
35 char *name;
37 /* dimensions */
38 double w;
39 double h;
41 /* sprites */
42 double sx;
43 double sy;
44 double sw;
45 double sh;
46 double srw;
47 double srh;
49 /* data */
50 GLuint texture;
51 uint8_t* trans;
53 /* properties */
54 uint8_t flags;
55} glTexture;
56
57/*
58 * Init/exit.
59 */
60int gl_initTextures (void);
61void gl_exitTextures (void);
62
63/*
64 * Creating.
65 */
66glTexture* gl_loadImageData( float *data, int w, int h, int sx, int sy, const char* name );
67glTexture* gl_loadImagePad( const char *name, SDL_Surface* surface,
68 unsigned int flags, int w, int h, int sx, int sy, int freesur );
69glTexture* gl_loadImagePadTrans( const char *name, SDL_Surface* surface, SDL_RWops *rw,
70 unsigned int flags, int w, int h, int sx, int sy, int freesur );
71glTexture* gl_loadImage( SDL_Surface* surface, const unsigned int flags ); /* Frees the surface. */
72glTexture* gl_newImage( const char* path, const unsigned int flags );
73glTexture* gl_newImageRWops( const char* path, SDL_RWops *rw, const unsigned int flags ); /* Does not close the RWops. */
74glTexture* gl_newSprite( const char* path, const int sx, const int sy,
75 const unsigned int flags );
76glTexture* gl_newSpriteRWops( const char* path, SDL_RWops *rw,
77 const int sx, const int sy, const unsigned int flags );
78glTexture* gl_dupTexture( const glTexture *texture );
79
80/*
81 * Clean up.
82 */
83void gl_freeTexture( glTexture* texture );
84
85/*
86 * FBO stuff.
87 */
88int gl_fboCreate( GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height );
89
90/*
91 * Misc.
92 */
93int gl_isTrans( const glTexture* t, const int x, const int y );
94void gl_getSpriteFromDir( int* x, int* y, const glTexture* t, const double dir );
95glTexture** gl_copyTexArray( glTexture **tex, int *n );
96glTexture** gl_addTexArray( glTexture **tex, int *n, glTexture *t );
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition: opengl_tex.c:809
glTexture * gl_newSprite(const char *path, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition: opengl_tex.c:684
void gl_exitTextures(void)
Cleans up the opengl texture subsystem.
Definition: opengl_tex.c:921
glTexture * gl_newImageRWops(const char *path, SDL_RWops *rw, const unsigned int flags)
Loads an image as a texture.
Definition: opengl_tex.c:595
int gl_fboCreate(GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
Creates a framebuffer and its associated texture.
Definition: opengl_tex.c:203
glTexture * gl_loadImage(SDL_Surface *surface, unsigned int flags)
Loads the SDL_Surface to a glTexture.
Definition: opengl_tex.c:493
glTexture * gl_newSpriteRWops(const char *path, SDL_RWops *rw, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition: opengl_tex.c:722
glTexture ** gl_copyTexArray(glTexture **tex, int *n)
Copy a texture array.
Definition: opengl_tex.c:892
int gl_isTrans(const glTexture *t, const int x, const int y)
Checks to see if a pixel is transparent in a texture.
Definition: opengl_tex.c:838
glTexture ** gl_addTexArray(glTexture **tex, int *n, glTexture *t)
Adds an element to a texture array.
Definition: opengl_tex.c:934
glTexture * gl_loadImagePad(const char *name, SDL_Surface *surface, unsigned int flags, int w, int h, int sx, int sy, int freesur)
Loads the already padded SDL_Surface to a glTexture.
Definition: opengl_tex.c:444
glTexture * gl_loadImagePadTrans(const char *name, SDL_Surface *surface, SDL_RWops *rw, unsigned int flags, int w, int h, int sx, int sy, int freesur)
Wrapper for gl_loadImagePad that includes transparency mapping.
Definition: opengl_tex.c:331
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition: opengl_tex.c:570
void gl_getSpriteFromDir(int *x, int *y, const glTexture *t, const double dir)
Sets x and y to be the appropriate sprite for glTexture using dir.
Definition: opengl_tex.c:857
void gl_freeTexture(glTexture *texture)
Frees a texture.
Definition: opengl_tex.c:755
int gl_initTextures(void)
Initializes the opengl texture subsystem.
Definition: opengl_tex.c:913
Abstraction for rendering sprite sheets.
Definition: opengl_tex.h:34
double sw
Definition: opengl_tex.h:44
uint8_t * trans
Definition: opengl_tex.h:51
double sh
Definition: opengl_tex.h:45
double w
Definition: opengl_tex.h:38
uint8_t flags
Definition: opengl_tex.h:54
double sx
Definition: opengl_tex.h:42
double srh
Definition: opengl_tex.h:47
char * name
Definition: opengl_tex.h:35
GLuint texture
Definition: opengl_tex.h:50
double sy
Definition: opengl_tex.h:43
double h
Definition: opengl_tex.h:39
double srw
Definition: opengl_tex.h:46