naev 0.10.4
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 3
26/*
27 * Contains info about the opengl screen
28 */
29#define OPENGL_DOUBLEBUF (1<<1)
30#define OPENGL_VSYNC (1<<2)
31#define OPENGL_SUBROUTINES (1<<3)
32#define gl_has(f) (gl_screen.flags & (f))
36typedef struct glInfo_ {
37 int x;
38 int y;
39 /* Viewport considers x/y offset. */
40 int w;
41 int h;
42 /* Scaled window is the effective window resolution without considering offsets. */
43 int nw;
44 int nh;
45 /* Real window resolution is the real window resolution, unscaled and without offsets. */
46 int rw;
47 int rh;
48 double scale;
49 double wscale;
50 double hscale;
51 double dwscale;
52 double dhscale;
53 double mxscale;
54 double myscale;
55 int depth;
56 int r;
57 int g;
58 int b;
59 int a;
60 unsigned int flags;
61 int tex_max;
63 int fsaa;
64 SDL_Window *window;
65 SDL_GLContext context;
66 GLuint current_fbo;
67 GLuint fbo[OPENGL_NUM_FBOS];
68 GLuint fbo_tex[OPENGL_NUM_FBOS];
69} glInfo;
70extern glInfo gl_screen; /* local structure set with gl_init and co */
71
72extern mat4 gl_view_matrix;
73
74#define SCREEN_X gl_screen.x
75#define SCREEN_Y gl_screen.y
76#define SCREEN_W gl_screen.w
77#define SCREEN_H gl_screen.h
79/*
80 * used with colour.h
81 */
82#define COLOUR(x) glColor4d((x).r,(x).g,(x).b,(x).a)
83#define ACOLOUR(x,a) glColor4d((x).r,(x).g,(x).b,a)
85/*
86 * initialization / cleanup
87 */
88int gl_init (void);
89void gl_exit (void);
90void gl_resize (void);
91
92/*
93 * Extensions and version.
94 */
95GLboolean gl_hasVersion( int major, int minor );
96
97/*
98 * Viewport.
99 */
100void gl_windowToScreenPos( int *sx, int *sy, int wx, int wy );
101void gl_screenToWindowPos( int *wx, int *wy, int sx, int sy );
102void gl_viewport( int x, int y, int w, int h );
103void gl_defViewport (void);
104void gl_setDefViewport( int x, int y, int w, int h );
105int gl_setupFullscreen (void);
106
107/*
108 * misc
109 */
110void gl_colorblind( int enable );
111GLint gl_stringToFilter( const char *s );
112GLint gl_stringToClamp( const char *s );
113void gl_screenshot( const char *filename );
114#ifdef DEBUGGING
115#define gl_checkErr() gl_checkHandleError( __func__, __LINE__ )
116void gl_checkHandleError( const char *func, int line );
117#else /* DEBUGGING */
118#define gl_checkErr()
119#endif /* DEBUGGING */
void gl_colorblind(int enable)
Enables or disables the colorblind shader.
Definition: opengl.c:674
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_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:36
double dwscale
Definition: opengl.h:51
int depth
Definition: opengl.h:55
double scale
Definition: opengl.h:48
int y
Definition: opengl.h:38
int b
Definition: opengl.h:58
int g
Definition: opengl.h:57
double wscale
Definition: opengl.h:49
int x
Definition: opengl.h:37
double myscale
Definition: opengl.h:54
int w
Definition: opengl.h:40
double dhscale
Definition: opengl.h:52
int rh
Definition: opengl.h:47
int fsaa
Definition: opengl.h:63
int r
Definition: opengl.h:56
double mxscale
Definition: opengl.h:53
SDL_Window * window
Definition: opengl.h:64
int a
Definition: opengl.h:59
double hscale
Definition: opengl.h:50
int tex_max
Definition: opengl.h:61
SDL_GLContext context
Definition: opengl.h:65
int rw
Definition: opengl.h:46
int h
Definition: opengl.h:41
unsigned int flags
Definition: opengl.h:60
int nw
Definition: opengl.h:43
int multitex_max
Definition: opengl.h:62
int nh
Definition: opengl.h:44
GLuint current_fbo
Definition: opengl.h:66
Definition: mat4.h:10