naev 0.11.5
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 "log.h"
#include "render.h"

Go to the source code of this file.

Macros

#define OPENGL_REQ_MULTITEX   2
 

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 it's default parameters.
 
static int gl_setupScaling (void)
 Sets up dimensions in gl_screen, including scaling as needed.
 
void gl_screenshot (const char *filename)
 Takes a screenshot.
 
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 (void)
 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.
 
GLint gl_stringToFilter (const char *s)
 Gets the associated min/mag filter from a string.
 
GLint gl_stringToClamp (const char *s)
 Gets the associated min/mag filter from a string.
 
void gl_colourblind (int enable)
 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 colourblind_pp = 0
 
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.

Macro Definition Documentation

◆ OPENGL_REQ_MULTITEX

#define OPENGL_REQ_MULTITEX   2

2 is minimum OpenGL 1.2 must have

Definition at line 49 of file opengl.c.

Function Documentation

◆ gl_colourblind()

void gl_colourblind ( int enable)

Enables or disables the colourblind shader.

Parameters
enableWhether or not to enable or disable the colourblind shader.

Definition at line 674 of file opengl.c.

◆ gl_createWindow()

static int gl_createWindow ( unsigned int flags)
static

Creates the OpenGL window.

Returns
0 on success.

Definition at line 305 of file opengl.c.

◆ gl_defState()

static int gl_defState ( void )
static

Sets the opengl state to it's default parameters.

Returns
0 on success.

Definition at line 406 of file opengl.c.

◆ gl_defViewport()

void gl_defViewport ( void )

Resets viewport to default.

Definition at line 608 of file opengl.c.

◆ gl_exit()

void gl_exit ( void )

Cleans up OpenGL, the works.

Definition at line 696 of file opengl.c.

◆ gl_getFullscreenMode()

static int gl_getFullscreenMode ( void )
static

Returns the fullscreen configuration as SDL2 flags.

Returns
Appropriate combination of SDL_WINDOW_FULLSCREEN* flags.

Definition at line 293 of file opengl.c.

◆ gl_getGLInfo()

static int gl_getGLInfo ( void )
static

Gets some information about the OpenGL window.

Returns
0 on success.

Definition at line 360 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 133 of file opengl.c.

◆ gl_init()

int gl_init ( void )

Initializes SDL/OpenGL and the works.

Returns
0 on success.

Definition at line 475 of file opengl.c.

◆ gl_resize()

void gl_resize ( void )

Handles a window resize and resets gl_screen parameters.

Definition at line 547 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 86 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 628 of file opengl.c.

◆ gl_setDefViewport()

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

Sets the default viewport.

Definition at line 597 of file opengl.c.

◆ gl_setupAttributes()

static int gl_setupAttributes ( int fallback)
static

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

Returns
0 on success.

Definition at line 236 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 260 of file opengl.c.

◆ gl_setupScaling()

static int gl_setupScaling ( void )
static

Sets up dimensions in gl_screen, including scaling as needed.

Returns
0 on success.

Definition at line 429 of file opengl.c.

◆ gl_stringToClamp()

GLint 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 658 of file opengl.c.

◆ gl_stringToFilter()

GLint 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 643 of file opengl.c.

◆ gl_viewport()

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

Sets the opengl viewport.

Definition at line 569 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 616 of file opengl.c.

Variable Documentation

◆ colourblind_pp

unsigned int colourblind_pp = 0
static

Colourblind post-process shader id.

Definition at line 54 of file opengl.c.

◆ gl_activated

int gl_activated = 0
static

Whether or not a window is activated.

Definition at line 52 of file opengl.c.

◆ gl_screen

glInfo gl_screen

Gives data of current opengl settings.

Definition at line 51 of file opengl.c.

◆ gl_view_h

int gl_view_h = 0
static

Definition at line 62 of file opengl.c.

◆ gl_view_matrix

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

Definition at line 63 of file opengl.c.

◆ gl_view_w

int gl_view_w = 0
static

Definition at line 61 of file opengl.c.

◆ gl_view_x

int gl_view_x = 0
static

Definition at line 59 of file opengl.c.

◆ gl_view_y

int gl_view_y = 0
static

Definition at line 60 of file opengl.c.