Lephisto/src/opengl.h

68 lines
2.0 KiB
C

#pragma once
#include <SDL.h>
#include <SDL_opengl.h>
#include "physics.h"
// Recommended for compatibility bullshit.
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
# define RMASK 0xff000000
# define GMASK 0x00ff0000
# define BMASK 0x0000ff00
# define AMASK 0x000000ff
#else
# define RMASK 0x000000ff
# define GMASK 0x0000ff00
# define BMASK 0x00ff0000
# define AMASK 0xff000000
#endif
#define RGBMASK RMASK,GMASK,BMASK,AMASK
// Info about opengl screen.
typedef struct {
int w, h; // Window dimensions.
int depth; // Depth in bpp.
int fullscreen; // 1 = fullscreen, 0 = windowed.
int r, g, b, a; // Framebuffer values in bits.
int doublebuf; // Double buffer.
} gl_info;
extern gl_info gl_screen; // Local structure set with gl_init etc.
// Spritesheet info.
typedef struct {
double w, h; // Real size of the image (excluding POT buffer.
double rw, rh; // Size of POT surface.
double sx, sy; // Number of sprites on x and y axes.
double sw, sh; // Size of each sprite.
GLuint texture; // The opengl texture itself.
} gl_texture;
// Font info.
typedef struct {
float h; // Height.
GLuint* textures;
GLuint list_base;
} gl_font;
// gl_font loading/freeing.
// If font is NULL it uses the internal default font, same with gl_print
void gl_fontInit(gl_font* font, const char* fname, unsigned int h);
void gl_freeFont(gl_font* font);
// gl_texute loading/freeing.
gl_texture* gl_loadImage(SDL_Surface* surface); // Frees the surface.
gl_texture* gl_newImage(const char* path);
gl_texture* gl_newSprite(const char* path, const int sx, const int sy);
void gl_freeTexture(gl_texture* texture);
// Rendering.
void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, const int sy);
void gl_blitStatic(const gl_texture* texture, const Vec2* pos);
void gl_bindCamera(const Vec2* pos);
void gl_print(const gl_font* ft_font, const Vec2* pos, const char* fmt, ...);
// Initialize/cleanup.
int gl_init(void);
void gl_exit(void);