naev 0.10.4
Macros | Functions | Variables
opengl_render.c File Reference

This file handles the opengl rendering routines. More...

#include "opengl_render.h"
#include "camera.h"
#include "conf.h"
#include "gui.h"
#include "log.h"
#include "ndata.h"
#include "nstring.h"
#include "opengl.h"

Go to the source code of this file.

Macros

#define OPENGL_RENDER_VBO_SIZE   256
 

Functions

void gl_beginSolidProgram (mat4 projection, const glColour *c)
 
void gl_endSolidProgram (void)
 
void gl_beginSmoothProgram (mat4 projection)
 
void gl_endSmoothProgram ()
 
void gl_renderRect (double x, double y, double w, double h, const glColour *c)
 Renders a rectangle. More...
 
void gl_renderRectEmpty (double x, double y, double w, double h, const glColour *c)
 Renders a rectangle. More...
 
void gl_renderRectH (const mat4 *H, const glColour *c, int filled)
 Renders a rectangle. More...
 
void gl_renderCross (double x, double y, double r, const glColour *c)
 Renders a cross at a given position. More...
 
void gl_renderTriangleEmpty (double x, double y, double a, double s, double length, const glColour *c)
 Renders a triangle at a given position. More...
 
void gl_renderTextureRaw (GLuint texture, uint8_t flags, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c, double angle)
 Texture blitting backend. More...
 
void gl_renderTexture (const glTexture *texture, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c, double angle)
 Texture blitting backend. More...
 
void gl_renderTextureInterpolate (const glTexture *ta, const glTexture *tb, double inter, double x, double y, double w, double h, double tx, double ty, double tw, double th, const glColour *c)
 Texture blitting backend for interpolated texture. More...
 
void gl_gameToScreenCoords (double *nx, double *ny, double bx, double by)
 Converts in-game coordinates to screen coordinates. More...
 
mat4 gl_gameToScreenMatrix (mat4 lhs)
 Return a transformation which converts in-game coordinates to screen coordinates. More...
 
void gl_screenToGameCoords (double *nx, double *ny, int bx, int by)
 Converts screen coordinates to in-game coordinates. More...
 
void gl_renderSprite (const glTexture *sprite, double bx, double by, int sx, int sy, const glColour *c)
 Blits a sprite, position is relative to the player. More...
 
void gl_renderSpriteScale (const glTexture *sprite, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
 Blits a sprite, position is relative to the player. More...
 
void gl_renderSpriteRotate (const glTexture *sprite, double bx, double by, double angle, int sx, int sy, const glColour *c)
 Blits a sprite, position is relative to the player with rotation. More...
 
void gl_renderSpriteScaleRotate (const glTexture *sprite, double bx, double by, double scalew, double scaleh, double angle, int sx, int sy, const glColour *c)
 Blits a sprite, position is relative to the player with scaling and rotation. More...
 
void gl_renderSpriteInterpolate (const glTexture *sa, const glTexture *sb, double inter, double bx, double by, int sx, int sy, const glColour *c)
 Blits a sprite interpolating, position is relative to the player. More...
 
void gl_renderSpriteInterpolateScale (const glTexture *sa, const glTexture *sb, double inter, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
 Blits a sprite interpolating, position is relative to the player. More...
 
void gl_renderStaticSprite (const glTexture *sprite, double bx, double by, int sx, int sy, const glColour *c)
 Blits a sprite, position is in absolute screen coordinates. More...
 
void gl_renderStaticSpriteInterpolate (const glTexture *sa, const glTexture *sb, double inter, double bx, double by, int sx, int sy, const glColour *c)
 Blits a sprite interpolating, position is relative to the player. More...
 
void gl_renderStaticSpriteInterpolateScale (const glTexture *sa, const glTexture *sb, double inter, double bx, double by, double scalew, double scaleh, int sx, int sy, const glColour *c)
 Blits a sprite interpolating, position is relative to the player. More...
 
void gl_renderScaleSprite (const glTexture *sprite, double bx, double by, int sx, int sy, double bw, double bh, const glColour *c)
 Blits a scaled sprite, position is in absolute screen coordinates. More...
 
void gl_renderScale (const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
 Blits a texture scaling it. More...
 
void gl_renderScaleAspect (const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
 Blits a texture scaling it to fit a rectangle, but conserves aspect ratio. More...
 
void gl_renderStatic (const glTexture *texture, double bx, double by, const glColour *c)
 Blits a texture to a position. More...
 
void gl_renderShader (double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center)
 Renders a simple shader. More...
 
void gl_renderShaderH (const SimpleShader *shd, const mat4 *H, const glColour *c, int center)
 Renders a simple shader with a transformation. More...
 
void gl_renderCircle (double cx, double cy, double r, const glColour *c, int filled)
 Draws a circle. More...
 
void gl_renderCircleH (const mat4 *H, const glColour *c, int filled)
 Draws a circle. More...
 
void gl_renderLine (double x1, double y1, double x2, double y2, const glColour *c)
 Draws a line. More...
 
void gl_clipRect (int x, int y, int w, int h)
 Sets up 2d clipping planes around a rectangle. More...
 
void gl_unclipRect (void)
 Clears the 2d clipping planes. More...
 
int gl_initRender (void)
 Initializes the OpenGL rendering routines. More...
 
void gl_exitRender (void)
 Cleans up the OpenGL rendering routines. More...
 

Variables

static gl_vbo * gl_renderVBO = 0
 
gl_vbo * gl_squareVBO = 0
 
static gl_vbo * gl_squareEmptyVBO = 0
 
gl_vbo * gl_circleVBO = 0
 
static gl_vbo * gl_lineVBO = 0
 
static gl_vbo * gl_triangleVBO = 0
 
static int gl_renderVBOtexOffset = 0
 
static int gl_renderVBOcolOffset = 0
 

Detailed Description

This file handles the opengl rendering routines.

There are two coordinate systems: relative and absolute.

Relative:

Absolute:

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_render.c.

Macro Definition Documentation

◆ OPENGL_RENDER_VBO_SIZE

#define OPENGL_RENDER_VBO_SIZE   256

Size of VBO.

Definition at line 40 of file opengl_render.c.

Function Documentation

◆ gl_beginSmoothProgram()

void gl_beginSmoothProgram ( mat4  projection)

Definition at line 66 of file opengl_render.c.

◆ gl_beginSolidProgram()

void gl_beginSolidProgram ( mat4  projection,
const glColour *  c 
)

Definition at line 51 of file opengl_render.c.

◆ gl_clipRect()

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

Sets up 2d clipping planes around a rectangle.

Parameters
xX position of the rectangle.
yY position of the rectangle.
wWidth of the rectangle.
hHeight of the rectangle.

Definition at line 986 of file opengl_render.c.

◆ gl_endSmoothProgram()

void gl_endSmoothProgram ( void  )

Definition at line 74 of file opengl_render.c.

◆ gl_endSolidProgram()

void gl_endSolidProgram ( void  )

Definition at line 59 of file opengl_render.c.

◆ gl_exitRender()

void gl_exitRender ( void  )

Cleans up the OpenGL rendering routines.

Definition at line 1077 of file opengl_render.c.

◆ gl_gameToScreenCoords()

void gl_gameToScreenCoords ( double *  nx,
double *  ny,
double  bx,
double  by 
)

Converts in-game coordinates to screen coordinates.

Parameters
[out]nxNew screen X coord.
[out]nyNew screen Y coord.
bxGame X coord to translate.
byGame Y coord to translate.

Definition at line 370 of file opengl_render.c.

◆ gl_gameToScreenMatrix()

mat4 gl_gameToScreenMatrix ( mat4  lhs)

Return a transformation which converts in-game coordinates to screen coordinates.

Parameters
lhsMatrix to multiply by the conversion matrix.

Definition at line 389 of file opengl_render.c.

◆ gl_initRender()

int gl_initRender ( void  )

Initializes the OpenGL rendering routines.

Returns
0 on success.

Definition at line 1011 of file opengl_render.c.

◆ gl_renderCircle()

void gl_renderCircle ( double  cx,
double  cy,
double  r,
const glColour *  c,
int  filled 
)

Draws a circle.

Parameters
cxX position of the center in screen coordinates.
cyY position of the center in screen coordinates.
rRadius of the circle.
cColour to use.
filledWhether or not it should be filled.

Definition at line 928 of file opengl_render.c.

◆ gl_renderCircleH()

void gl_renderCircleH ( const mat4 H,
const glColour *  c,
int  filled 
)

Draws a circle.

Parameters
HTransformation matrix to draw the circle.
cColour to use.
filledWhether or not it should be filled.

Definition at line 947 of file opengl_render.c.

◆ gl_renderCross()

void gl_renderCross ( double  x,
double  y,
double  r,
const glColour *  c 
)

Renders a cross at a given position.

Parameters
xX position to center at.
yY position to center at.
rRadius of cross.
cColour to use.

Definition at line 147 of file opengl_render.c.

◆ gl_renderLine()

void gl_renderLine ( double  x1,
double  y1,
double  x2,
double  y2,
const glColour *  c 
)

Draws a line.

Parameters
x1X position of the first point in screen coordinates.
y1Y position of the first point in screen coordinates.
x2X position of the second point in screen coordinates.
y2Y position of the second point in screen coordinates.
cColour to use.

Definition at line 967 of file opengl_render.c.

◆ gl_renderRect()

void gl_renderRect ( double  x,
double  y,
double  w,
double  h,
const glColour *  c 
)

Renders a rectangle.

Parameters
xX position to render rectangle at.
yY position to render rectangle at.
wRectangle width.
hRectangle height.
cRectangle colour.

Definition at line 90 of file opengl_render.c.

◆ gl_renderRectEmpty()

void gl_renderRectEmpty ( double  x,
double  y,
double  w,
double  h,
const glColour *  c 
)

Renders a rectangle.

Parameters
xX position to render rectangle at.
yY position to render rectangle at.
wRectangle width.
hRectangle height.
cRectangle colour.

Definition at line 109 of file opengl_render.c.

◆ gl_renderRectH()

void gl_renderRectH ( const mat4 H,
const glColour *  c,
int  filled 
)

Renders a rectangle.

Parameters
HTransformation matrix to apply.
filledWhether or not to fill.
cRectangle colour.

Definition at line 125 of file opengl_render.c.

◆ gl_renderScale()

void gl_renderScale ( const glTexture texture,
double  bx,
double  by,
double  bw,
double  bh,
const glColour *  c 
)

Blits a texture scaling it.

Parameters
textureTexture to blit.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
bwWidth to scale to.
bhHeight to scale to.
cColour to use (modifies texture colour).

Definition at line 802 of file opengl_render.c.

◆ gl_renderScaleAspect()

void gl_renderScaleAspect ( const glTexture texture,
double  bx,
double  by,
double  bw,
double  bh,
const glColour *  c 
)

Blits a texture scaling it to fit a rectangle, but conserves aspect ratio.

Parameters
textureTexture to blit.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
bwWidth to scale to.
bhHeight to scale to.
cColour to use (modifies texture colour).

Definition at line 831 of file opengl_render.c.

◆ gl_renderScaleSprite()

void gl_renderScaleSprite ( const glTexture sprite,
double  bx,
double  by,
int  sx,
int  sy,
double  bw,
double  bh,
const glColour *  c 
)

Blits a scaled sprite, position is in absolute screen coordinates.

Parameters
spriteSprite to blit.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
sxX position of the sprite to use.
syY position of the sprite to use.
bwWidth of sprite to render at.
bhHeight of sprite to render at.
cColour to use (modifies texture colour).

Definition at line 773 of file opengl_render.c.

◆ gl_renderShader()

void gl_renderShader ( double  x,
double  y,
double  w,
double  h,
double  r,
const SimpleShader *  shd,
const glColour *  c,
int  center 
)

Renders a simple shader.

Parameters
xX position.
yY position.
wWidth.
hHeight.
rRotation or 0. to disable.
shdShader to render.
cColour to use or NULL if not necessary.
centerWhether or not to center the shader on the position and use [-1,1] coordinates or set bottom-left and use [0,1] coordinates.

Definition at line 883 of file opengl_render.c.

◆ gl_renderShaderH()

void gl_renderShaderH ( const SimpleShader *  shd,
const mat4 H,
const glColour *  c,
int  center 
)

Renders a simple shader with a transformation.

Parameters
shdShader to render.
HTransformation matrix.
cColour to use or NULL if not necessary.
centerWhether or not to center the shader on the position and use [-1,1] coordinates or set bottom-left and use [0,1] coordinates.

Definition at line 902 of file opengl_render.c.

◆ gl_renderSprite()

void gl_renderSprite ( const glTexture sprite,
double  bx,
double  by,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Parameters
spriteSprite to blit.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 440 of file opengl_render.c.

◆ gl_renderSpriteInterpolate()

void gl_renderSpriteInterpolate ( const glTexture sa,
const glTexture sb,
double  inter,
double  bx,
double  by,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite interpolating, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Interpolation is: sa*inter + sb*1.-inter)

Parameters
saSprite A to blit.
sbSprite B to blit.
interAmount to interpolate.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 610 of file opengl_render.c.

◆ gl_renderSpriteInterpolateScale()

void gl_renderSpriteInterpolateScale ( const glTexture sa,
const glTexture sb,
double  inter,
double  bx,
double  by,
double  scalew,
double  scaleh,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite interpolating, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Interpolation is: sa*inter + sb*1.-inter)

Parameters
saSprite A to blit.
sbSprite B to blit.
interAmount to interpolate.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
scalewX scale factor.
scalehY scale factor.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 636 of file opengl_render.c.

◆ gl_renderSpriteRotate()

void gl_renderSpriteRotate ( const glTexture sprite,
double  bx,
double  by,
double  angle,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite, position is relative to the player with rotation.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Parameters
spriteSprite to blit.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
angleAngle to rotate when rendering.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 522 of file opengl_render.c.

◆ gl_renderSpriteScale()

void gl_renderSpriteScale ( const glTexture sprite,
double  bx,
double  by,
double  scalew,
double  scaleh,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Parameters
spriteSprite to blit.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
scalewScaling of width.
scalehScaling of height.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 481 of file opengl_render.c.

◆ gl_renderSpriteScaleRotate()

void gl_renderSpriteScaleRotate ( const glTexture sprite,
double  bx,
double  by,
double  scalew,
double  scaleh,
double  angle,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite, position is relative to the player with scaling and rotation.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Parameters
spriteSprite to blit.
bxX position of the texture relative to the player.
byY position of the texture relative to the player.
scalewScaling of width.
scalehScaling of height.
angleAngle to rotate when rendering.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 565 of file opengl_render.c.

◆ gl_renderStatic()

void gl_renderStatic ( const glTexture texture,
double  bx,
double  by,
const glColour *  c 
)

Blits a texture to a position.

Parameters
textureTexture to blit.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
cColour to use (modifies texture colour).

Definition at line 857 of file opengl_render.c.

◆ gl_renderStaticSprite()

void gl_renderStaticSprite ( const glTexture sprite,
double  bx,
double  by,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite, position is in absolute screen coordinates.

Parameters
spriteSprite to blit.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 674 of file opengl_render.c.

◆ gl_renderStaticSpriteInterpolate()

void gl_renderStaticSpriteInterpolate ( const glTexture sa,
const glTexture sb,
double  inter,
double  bx,
double  by,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite interpolating, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Interpolation is: sa*inter + sb*1.-inter)

Parameters
saSprite A to blit.
sbSprite B to blit.
interAmount to interpolate.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 708 of file opengl_render.c.

◆ gl_renderStaticSpriteInterpolateScale()

void gl_renderStaticSpriteInterpolateScale ( const glTexture sa,
const glTexture sb,
double  inter,
double  bx,
double  by,
double  scalew,
double  scaleh,
int  sx,
int  sy,
const glColour *  c 
)

Blits a sprite interpolating, position is relative to the player.

Since position is in "game coordinates" it is subject to all sorts of position transformations.

Interpolation is: sa*inter + sb*1.-inter)

Parameters
saSprite A to blit.
sbSprite B to blit.
interAmount to interpolate.
bxX position of the texture in screen coordinates.
byY position of the texture in screen coordinates.
scalewX scale factor.
scalehY scale factor.
sxX position of the sprite to use.
syY position of the sprite to use.
cColour to use (modifies texture colour).

Definition at line 734 of file opengl_render.c.

◆ gl_renderTexture()

void gl_renderTexture ( const glTexture texture,
double  x,
double  y,
double  w,
double  h,
double  tx,
double  ty,
double  tw,
double  th,
const glColour *  c,
double  angle 
)

Texture blitting backend.

Parameters
textureTexture to blit.
xX position of the texture on the screen. (units pixels)
yY position of the texture on the screen. (units pixels)
wWidth on the screen. (units pixels)
hHeight on the screen. (units pixels)
txX position within the texture. [0:1]
tyY position within the texture. [0:1]
twTexture width. [0:1]
thTexture height. [0:1]
cColour to use (modifies texture colour).
angleRotation to apply (radians ccw around the center).

Definition at line 268 of file opengl_render.c.

◆ gl_renderTextureInterpolate()

void gl_renderTextureInterpolate ( const glTexture ta,
const glTexture tb,
double  inter,
double  x,
double  y,
double  w,
double  h,
double  tx,
double  ty,
double  tw,
double  th,
const glColour *  c 
)

Texture blitting backend for interpolated texture.

Value blitted is ta*inter + tb*(1.-inter).

Parameters
taTexture A to blit.
tbTexture B to blit.
interAmount of interpolation to do.
xX position of the texture on the screen.
yY position of the texture on the screen.
wWidth on the screen. (units pixels)
hHeight on the screen. (units pixels)
txX position within the texture.
tyY position within the texture.
twTexture width.
thTexture height.
cColour to use (modifies texture colour).

Definition at line 294 of file opengl_render.c.

◆ gl_renderTextureRaw()

void gl_renderTextureRaw ( GLuint  texture,
uint8_t  flags,
double  x,
double  y,
double  w,
double  h,
double  tx,
double  ty,
double  tw,
double  th,
const glColour *  c,
double  angle 
)

Texture blitting backend.

Parameters
textureTexture to blit.
flagsTexture flags,.
xX position of the texture on the screen. (units pixels)
yY position of the texture on the screen. (units pixels)
wWidth on the screen. (units pixels)
hHeight on the screen. (units pixels)
txX position within the texture. [0:1]
tyY position within the texture. [0:1]
twTexture width. [0:1]
thTexture height. [0:1]
cColour to use (modifies texture colour).
angleRotation to apply (radians ccw around the center).

Definition at line 194 of file opengl_render.c.

◆ gl_renderTriangleEmpty()

void gl_renderTriangleEmpty ( double  x,
double  y,
double  a,
double  s,
double  length,
const glColour *  c 
)

Renders a triangle at a given position.

Parameters
xX position to center at.
yY position to center at.
aAngle the triangle should "face" (right is 0.)
sScaling of the triangle.
lengthLength deforming factor. Setting it to a value of other than 1. moves away from an equilateral triangle.
cColour to use.

Definition at line 164 of file opengl_render.c.

◆ gl_screenToGameCoords()

void gl_screenToGameCoords ( double *  nx,
double *  ny,
int  bx,
int  by 
)

Converts screen coordinates to in-game coordinates.

Parameters
[out]nxNew in-game X coord.
[out]nyNew in-game Y coord.
bxScreen X coord to translate.
byScreen Y coord to translate.

Definition at line 413 of file opengl_render.c.

◆ gl_unclipRect()

void gl_unclipRect ( void  )

Clears the 2d clipping planes.

Definition at line 1000 of file opengl_render.c.

Variable Documentation

◆ gl_circleVBO

gl_vbo* gl_circleVBO = 0

Definition at line 45 of file opengl_render.c.

◆ gl_lineVBO

gl_vbo* gl_lineVBO = 0
static

Definition at line 46 of file opengl_render.c.

◆ gl_renderVBO

gl_vbo* gl_renderVBO = 0
static

VBO for rendering stuff.

Definition at line 42 of file opengl_render.c.

◆ gl_renderVBOcolOffset

int gl_renderVBOcolOffset = 0
static

VBO colour offset.

Definition at line 49 of file opengl_render.c.

◆ gl_renderVBOtexOffset

int gl_renderVBOtexOffset = 0
static

VBO texture offset.

Definition at line 48 of file opengl_render.c.

◆ gl_squareEmptyVBO

gl_vbo* gl_squareEmptyVBO = 0
static

Definition at line 44 of file opengl_render.c.

◆ gl_squareVBO

gl_vbo* gl_squareVBO = 0

Definition at line 43 of file opengl_render.c.

◆ gl_triangleVBO

gl_vbo* gl_triangleVBO = 0
static

Definition at line 47 of file opengl_render.c.