naev 0.11.5
opengl.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <stdint.h>
8
9/* Include header generated by glad */
10#include "glad.h"
11
12#include "SDL.h"
15#include "colour.h"
16/* We put all the other opengl stuff here to only have to include one header. */
17#include "opengl_render.h"
18#include "opengl_shader.h"
19#include "opengl_tex.h"
20#include "opengl_vbo.h"
21#include "mat4.h"
22#include "shaders.gen.h"
23
24#define OPENGL_NUM_FBOS 4
30/*
31 * Contains info about the opengl screen
32 */
33#define OPENGL_DOUBLEBUF (1<<1)
34#define OPENGL_VSYNC (1<<2)
35#define OPENGL_SUBROUTINES (1<<3)
36#define gl_has(f) (gl_screen.flags & (f))
40typedef struct glInfo_ {
41 int x;
42 int y;
43 /* Viewport considers x/y offset. */
44 int w;
45 int h;
46 /* Scaled window is the effective window resolution without considering offsets. */
47 int nw;
48 int nh;
49 /* Real window resolution is the real window resolution, unscaled and without offsets. */
50 int rw;
51 int rh;
52 double scale;
53 double wscale;
54 double hscale;
55 double dwscale;
56 double dhscale;
57 double mxscale;
58 double myscale;
59 int depth;
60 int r;
61 int g;
62 int b;
63 int a;
64 unsigned int flags;
65 int tex_max;
67 int fsaa;
68 SDL_Window *window;
69 SDL_GLContext context;
70 GLuint current_fbo;
71 GLuint fbo[OPENGL_NUM_FBOS];
72 GLuint fbo_tex[OPENGL_NUM_FBOS];
73} glInfo;
74extern glInfo gl_screen; /* local structure set with gl_init and co */
75
76extern mat4 gl_view_matrix;
77
78#define SCREEN_X gl_screen.x
79#define SCREEN_Y gl_screen.y
80#define SCREEN_W gl_screen.w
81#define SCREEN_H gl_screen.h
83/*
84 * used with colour.h
85 */
86#define COLOUR(x) glColour4d((x).r,(x).g,(x).b,(x).a)
87#define ACOLOUR(x,a) glColour4d((x).r,(x).g,(x).b,a)
89/*
90 * initialization / cleanup
91 */
92int gl_init (void);
93void gl_exit (void);
94void gl_resize (void);
95
96/*
97 * Extensions and version.
98 */
99GLboolean gl_hasVersion( int major, int minor );
100
101/*
102 * Viewport.
103 */
104void gl_windowToScreenPos( int *sx, int *sy, int wx, int wy );
105void gl_screenToWindowPos( int *wx, int *wy, int sx, int sy );
106void gl_viewport( int x, int y, int w, int h );
107void gl_defViewport (void);
108void gl_setDefViewport( int x, int y, int w, int h );
109int gl_setupFullscreen (void);
110
111/*
112 * misc
113 */
114void gl_colourblind( int enable );
115GLint gl_stringToFilter( const char *s );
116GLint gl_stringToClamp( const char *s );
117void gl_screenshot( const char *filename );
118#ifdef DEBUGGING
119#define gl_checkErr() gl_checkHandleError( __func__, __LINE__ )
120void gl_checkHandleError( const char *func, int line );
121#else /* DEBUGGING */
122#define gl_checkErr()
123#endif /* DEBUGGING */
void gl_setDefViewport(int x, int y, int w, int h)
Sets the default viewport.
Definition opengl.c:597
void gl_screenshot(const char *filename)
Takes a screenshot.
Definition opengl.c:86
void gl_defViewport(void)
Resets viewport to default.
Definition opengl.c:608
void gl_colourblind(int enable)
Enables or disables the colourblind shader.
Definition opengl.c:674
void gl_resize(void)
Handles a window resize and resets gl_screen parameters.
Definition opengl.c:547
void gl_screenToWindowPos(int *wx, int *wy, int sx, int sy)
Translates the screen position to windos position.
Definition opengl.c:628
GLint gl_stringToFilter(const char *s)
Gets the associated min/mag filter from a string.
Definition opengl.c:643
void gl_exit(void)
Cleans up OpenGL, the works.
Definition opengl.c:696
void gl_viewport(int x, int y, int w, int h)
Sets the opengl viewport.
Definition opengl.c:569
void gl_windowToScreenPos(int *sx, int *sy, int wx, int wy)
Translates the window position to screen position.
Definition opengl.c:616
int gl_init(void)
Initializes SDL/OpenGL and the works.
Definition opengl.c:475
GLboolean gl_hasVersion(int major, int minor)
Checks to see if opengl version is at least major.minor.
Definition opengl.c:133
glInfo gl_screen
Definition opengl.c:51
GLint gl_stringToClamp(const char *s)
Gets the associated min/mag filter from a string.
Definition opengl.c:658
int gl_setupFullscreen(void)
Tries to apply the configured display mode to the window.
Definition opengl.c:260
Stores data about the current opengl environment.
Definition opengl.h:40
double dwscale
Definition opengl.h:55
int depth
Definition opengl.h:59
double scale
Definition opengl.h:52
int y
Definition opengl.h:42
int b
Definition opengl.h:62
int g
Definition opengl.h:61
double wscale
Definition opengl.h:53
int x
Definition opengl.h:41
double myscale
Definition opengl.h:58
int w
Definition opengl.h:44
double dhscale
Definition opengl.h:56
int rh
Definition opengl.h:51
int fsaa
Definition opengl.h:67
int r
Definition opengl.h:60
double mxscale
Definition opengl.h:57
SDL_Window * window
Definition opengl.h:68
int a
Definition opengl.h:63
double hscale
Definition opengl.h:54
int tex_max
Definition opengl.h:65
SDL_GLContext context
Definition opengl.h:69
int rw
Definition opengl.h:50
int h
Definition opengl.h:45
unsigned int flags
Definition opengl.h:64
int nw
Definition opengl.h:47
int multitex_max
Definition opengl.h:66
int nh
Definition opengl.h:48
GLuint current_fbo
Definition opengl.h:70
Definition mat4.h:10