naev 0.11.5
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 "attributes.h"
12#include "colour.h"
13#include "physics.h"
14
15/* Recommended for compatibility and such */
16#define RMASK SDL_SwapLE32(0x000000ff)
17#define GMASK SDL_SwapLE32(0x0000ff00)
18#define BMASK SDL_SwapLE32(0x00ff0000)
19#define AMASK SDL_SwapLE32(0xff000000)
20#define RGBAMASK RMASK,GMASK,BMASK,AMASK
21
22/*
23 * Texture flags.
24 */
25#define OPENGL_TEX_MAPTRANS (1<<0)
26#define OPENGL_TEX_MIPMAPS (1<<1)
27#define OPENGL_TEX_VFLIP (1<<2)
28#define OPENGL_TEX_SKIPCACHE (1<<3)
29#define OPENGL_TEX_SDF (1<<4)
36typedef struct glTexture_ {
37 char *name;
39 /* dimensions */
40 double w;
41 double h;
43 /* sprites */
44 double sx;
45 double sy;
46 double sw;
47 double sh;
48 double srw;
49 double srh;
51 /* data */
52 GLuint texture;
53 uint8_t* trans;
54 double vmax;
56 /* properties */
57 uint8_t flags;
58} glTexture;
59
60/*
61 * Init/exit.
62 */
63int gl_initTextures (void);
64void gl_exitTextures (void);
65
66/*
67 * Creating.
68 */
69USE_RESULT glTexture* gl_loadImageData( float *data, int w, int h, int sx, int sy, const char* name );
70USE_RESULT glTexture* gl_loadImagePad( const char *name, SDL_Surface* surface,
71 unsigned int flags, int w, int h, int sx, int sy, int freesur );
72USE_RESULT glTexture* gl_loadImagePadTrans( const char *name, SDL_Surface* surface, SDL_RWops *rw,
73 unsigned int flags, int w, int h, int sx, int sy, int freesur );
74USE_RESULT glTexture* gl_loadImage( SDL_Surface* surface, const unsigned int flags ); /* Frees the surface. */
75USE_RESULT glTexture* gl_newImage( const char* path, const unsigned int flags );
76USE_RESULT glTexture* gl_newImageRWops( const char* path, SDL_RWops *rw, const unsigned int flags ); /* Does not close the RWops. */
77USE_RESULT glTexture* gl_newSprite( const char* path, const int sx, const int sy,
78 const unsigned int flags );
79USE_RESULT glTexture* gl_newSpriteRWops( const char* path, SDL_RWops *rw,
80 const int sx, const int sy, const unsigned int flags );
81USE_RESULT glTexture* gl_dupTexture( const glTexture *texture );
82
83/*
84 * Clean up.
85 */
86void gl_freeTexture( glTexture* texture );
87
88/*
89 * FBO stuff.
90 */
91int gl_fboCreate( GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height );
92
93/*
94 * Misc.
95 */
96void gl_contextSet (void);
97void gl_contextUnset (void);
98int gl_isTrans( const glTexture* t, const int x, const int y );
99void gl_getSpriteFromDir( int* x, int* y, const glTexture* t, const double dir );
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition opengl_tex.c:917
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:791
void gl_exitTextures(void)
Cleans up the opengl texture subsystem.
glTexture * gl_newImageRWops(const char *path, SDL_RWops *rw, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:700
int gl_fboCreate(GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
Creates a framebuffer and its associated texture.
Definition opengl_tex.c:252
glTexture * gl_loadImage(SDL_Surface *surface, unsigned int flags)
Loads the SDL_Surface to a glTexture.
Definition opengl_tex.c:599
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:829
glTexture ** gl_addTexArray(glTexture **tex, glTexture *t)
Adds an element to a texture array.
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:948
glTexture ** gl_copyTexArray(glTexture **tex)
Copy a texture array.
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:543
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:427
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:675
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:967
void gl_freeTexture(glTexture *texture)
Frees a texture.
Definition opengl_tex.c:862
int gl_initTextures(void)
Initializes the opengl texture subsystem.
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:36
double sw
Definition opengl_tex.h:46
double vmax
Definition opengl_tex.h:54
uint8_t * trans
Definition opengl_tex.h:53
double sh
Definition opengl_tex.h:47
double w
Definition opengl_tex.h:40
uint8_t flags
Definition opengl_tex.h:57
double sx
Definition opengl_tex.h:44
double srh
Definition opengl_tex.h:49
char * name
Definition opengl_tex.h:37
GLuint texture
Definition opengl_tex.h:52
double sy
Definition opengl_tex.h:45
double h
Definition opengl_tex.h:41
double srw
Definition opengl_tex.h:48