naev 0.12.6
opengl.c File Reference

This file handles most of the more generic opengl functions. More...

#include "opengl.h"
#include "conf.h"
#include "debug.h"
#include "gltf.h"
#include "log.h"
#include "render.h"
Include dependency graph for opengl.c:

Go to the source code of this file.

Functions

static int gl_setupAttributes (int fallback)
 Tries to set up the OpenGL attributes for the OpenGL context.
static int gl_createWindow (unsigned int flags)
 Creates the OpenGL window.
static int gl_getFullscreenMode (void)
 Returns the fullscreen configuration as SDL2 flags.
static int gl_getGLInfo (void)
 Gets some information about the OpenGL window.
static int gl_defState (void)
 Sets the opengl state to its default parameters.
static int gl_setupScaling (void)
 Sets up dimensions in gl_screen, including scaling as needed.
static void gl_applyFixes (void)
 Applies driver-specific fixes and workarounds before initializing OpenGL.
void gl_screenshot (const char *filename)
 Takes a screenshot.
void gl_saveFboDepth (GLuint fbo, const char *filename)
GLboolean gl_hasVersion (int major, int minor)
 Checks to see if opengl version is at least major.minor.
int gl_setupFullscreen (void)
 Tries to apply the configured display mode to the window.
int gl_init (unsigned int extra_flags)
 Initializes SDL/OpenGL and the works.
void gl_resize (void)
 Handles a window resize and resets gl_screen parameters.
void gl_viewport (int x, int y, int w, int h)
 Sets the opengl viewport.
void gl_setDefViewport (int x, int y, int w, int h)
 Sets the default viewport.
void gl_defViewport (void)
 Resets viewport to default.
void gl_windowToScreenPos (int *sx, int *sy, int wx, int wy)
 Translates the window position to screen position.
void gl_screenToWindowPos (int *wx, int *wy, int sx, int sy)
 Translates the screen position to windos position.
GLenum gl_stringToFilter (const char *s)
 Gets the associated min/mag filter from a string.
GLenum gl_stringToClamp (const char *s)
 Gets the associated min/mag filter from a string.
GLenum gl_stringToBlendFunc (const char *s)
 Gets a blend function from a string.
GLenum gl_stringToBlendFactor (const char *s)
 Gets a blend factor from a string.
void gl_colourblind (void)
 Enables or disables the colourblind shader.
void gl_exit (void)
 Cleans up OpenGL, the works.

Variables

glInfo gl_screen
static int gl_activated = 0
static unsigned int cb_correct_pp
static unsigned int cb_simulate_pp
static int gl_view_x = 0
static int gl_view_y = 0
static int gl_view_w = 0
static int gl_view_h = 0
mat4 gl_view_matrix = { { { { 0 } } } }

Detailed Description

This file handles most of the more generic opengl functions.

The main way to work with opengl in naev is to create glTextures and then use the blit functions to draw them on the screen. This system will handle relative and absolute positions.

There are two coordinate systems: relative and absolute.

Relative:

  • Everything is drawn relative to the player, if it doesn't fit on screen it is clipped.
  • Origin (0., 0.) would be ontop of the player.

Absolute:

  • Everything is drawn in "screen coordinates".
  • (0., 0.) is bottom left.
  • (SCREEN_W, SCREEN_H) is top right.

Note that the game actually uses a third type of coordinates for when using raw commands. In this third type, the (0.,0.) is actually in middle of the screen. (-SCREEN_W/2.,-SCREEN_H/2.) is bottom left and (+SCREEN_W/2.,+SCREEN_H/2.) is top right.

Definition in file opengl.c.

Function Documentation

◆ gl_applyFixes()

void gl_applyFixes ( void )
static

Applies driver-specific fixes and workarounds before initializing OpenGL.

Definition at line 82 of file opengl.c.

◆ gl_colourblind()

void gl_colourblind ( void )

Enables or disables the colourblind shader.

Definition at line 878 of file opengl.c.

◆ gl_createWindow()

int gl_createWindow ( unsigned int flags)
static

Creates the OpenGL window.

Returns
0 on success.

Definition at line 388 of file opengl.c.

◆ gl_defState()

int gl_defState ( void )
static

Sets the opengl state to its default parameters.

Returns
0 on success.

Definition at line 524 of file opengl.c.

◆ gl_defViewport()

void gl_defViewport ( void )

Resets viewport to default.

Definition at line 754 of file opengl.c.

◆ gl_exit()

void gl_exit ( void )

Cleans up OpenGL, the works.

Definition at line 931 of file opengl.c.

◆ gl_getFullscreenMode()

int gl_getFullscreenMode ( void )
static

Returns the fullscreen configuration as SDL2 flags.

Returns
Appropriate combination of SDL_WINDOW_FULLSCREEN* flags.

Definition at line 375 of file opengl.c.

◆ gl_getGLInfo()

int gl_getGLInfo ( void )
static

Gets some information about the OpenGL window.

Returns
0 on success.

Definition at line 478 of file opengl.c.

◆ gl_hasVersion()

GLboolean gl_hasVersion ( int major,
int minor )

Checks to see if opengl version is at least major.minor.

Parameters
majorMajor version to check.
minorMinor version to check.
Returns
True if major and minor version are met.

Definition at line 205 of file opengl.c.

◆ gl_init()

int gl_init ( unsigned int extra_flags)

Initializes SDL/OpenGL and the works.

Returns
0 on success.

Definition at line 600 of file opengl.c.

◆ gl_resize()

void gl_resize ( void )

Handles a window resize and resets gl_screen parameters.

Definition at line 689 of file opengl.c.

◆ gl_saveFboDepth()

void gl_saveFboDepth ( GLuint fbo,
const char * filename )

Definition at line 142 of file opengl.c.

◆ gl_screenshot()

void gl_screenshot ( const char * filename)

Takes a screenshot.

Parameters
filenamePhysicsFS path (e.g., "screenshots/screenshot042.png") of the file to save screenshot as.

Definition at line 106 of file opengl.c.

◆ gl_screenToWindowPos()

void gl_screenToWindowPos ( int * wx,
int * wy,
int sx,
int sy )

Translates the screen position to windos position.

Definition at line 775 of file opengl.c.

◆ gl_setDefViewport()

void gl_setDefViewport ( int x,
int y,
int w,
int h )

Sets the default viewport.

Definition at line 743 of file opengl.c.

◆ gl_setupAttributes()

int gl_setupAttributes ( int fallback)
static

Tries to set up the OpenGL attributes for the OpenGL context.

Returns
0 on success.

Definition at line 314 of file opengl.c.

◆ gl_setupFullscreen()

int gl_setupFullscreen ( void )

Tries to apply the configured display mode to the window.

Note
Caller is responsible for calling gl_resize/naev_resize afterward.
Returns
0 on success.

Definition at line 340 of file opengl.c.

◆ gl_setupScaling()

int gl_setupScaling ( void )
static

Sets up dimensions in gl_screen, including scaling as needed.

Returns
0 on success.

Definition at line 553 of file opengl.c.

◆ gl_stringToBlendFactor()

GLenum gl_stringToBlendFactor ( const char * s)

Gets a blend factor from a string.

Parameters
sString to get blend factor from.
Returns
The blend factor corresponding to the string.

Definition at line 847 of file opengl.c.

◆ gl_stringToBlendFunc()

GLenum gl_stringToBlendFunc ( const char * s)

Gets a blend function from a string.

Parameters
sString to get blend function from.
Returns
The blend function corresponding to the string.

Definition at line 825 of file opengl.c.

◆ gl_stringToClamp()

GLenum gl_stringToClamp ( const char * s)

Gets the associated min/mag filter from a string.

Parameters
sString to get filter from.
Returns
Filter.

Definition at line 807 of file opengl.c.

◆ gl_stringToFilter()

GLenum gl_stringToFilter ( const char * s)

Gets the associated min/mag filter from a string.

Parameters
sString to get filter from.
Returns
Filter.

Definition at line 791 of file opengl.c.

◆ gl_viewport()

void gl_viewport ( int x,
int y,
int w,
int h )

Sets the opengl viewport.

Definition at line 715 of file opengl.c.

◆ gl_windowToScreenPos()

void gl_windowToScreenPos ( int * sx,
int * sy,
int wx,
int wy )

Translates the window position to screen position.

Definition at line 762 of file opengl.c.

Variable Documentation

◆ cb_correct_pp

unsigned int cb_correct_pp
static
Initial value:
=
0

Colourblind post-process shader id for correction.

Definition at line 53 of file opengl.c.

◆ cb_simulate_pp

unsigned int cb_simulate_pp
static
Initial value:
=
0

Colourblind post-process shader id for simulation.

Definition at line 55 of file opengl.c.

◆ gl_activated

int gl_activated = 0
static

Whether or not a window is activated.

Definition at line 51 of file opengl.c.

◆ gl_screen

glInfo gl_screen
Initial value:
= {
.window = NULL,
}

Gives data of current opengl settings.

Definition at line 47 of file opengl.c.

◆ gl_view_h

int gl_view_h = 0
static

Definition at line 64 of file opengl.c.

◆ gl_view_matrix

mat4 gl_view_matrix = { { { { 0 } } } }

Definition at line 65 of file opengl.c.

◆ gl_view_w

int gl_view_w = 0
static

Definition at line 63 of file opengl.c.

◆ gl_view_x

int gl_view_x = 0
static

Definition at line 61 of file opengl.c.

◆ gl_view_y

int gl_view_y = 0
static

Definition at line 62 of file opengl.c.