libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Functions
lacf_gl_pic.h File Reference
#include "core.h"
#include "geom.h"
#include "glew.h"
#include <cglm/cglm.h>
Include dependency graph for lacf_gl_pic.h:

Go to the source code of this file.

Functions

lacf_gl_pic_t * lacf_gl_pic_new (const char *path)
 
lacf_gl_pic_t * lacf_gl_pic_new_from_dir (const char *dirpath, const char *filename)
 
void lacf_gl_pic_destroy (lacf_gl_pic_t *pic)
 
bool_t lacf_gl_pic_load (lacf_gl_pic_t *pic)
 
void lacf_gl_pic_unload (lacf_gl_pic_t *pic)
 
int lacf_gl_pic_get_width (lacf_gl_pic_t *pic)
 
int lacf_gl_pic_get_height (lacf_gl_pic_t *pic)
 
GLuint lacf_gl_pic_get_tex (lacf_gl_pic_t *pic)
 
void lacf_gl_pic_draw (lacf_gl_pic_t *pic, vect2_t pos, vect2_t size, float alpha)
 
void lacf_gl_pic_draw_custom (lacf_gl_pic_t *pic, vect2_t pos, vect2_t size, GLuint prog)
 

Detailed Description

A simple subsystem that provides the ability to load and draw PNG images in an OpenGL context.

Use lacf_gl_pic_new() or lacf_gl_pic_new_from_dir() to load a gl_pic object from disk. When done with the image, use lacf_gl_pic_destroy() to free all resources associated with the pic.

To draw the image, use lacf_gl_pic_draw() or lacf_gl_pic_draw_custom().

Definition in file lacf_gl_pic.h.

Function Documentation

◆ lacf_gl_pic_destroy()

void lacf_gl_pic_destroy ( lacf_gl_pic_t *  pic)

Destroys and frees the memory associated with a gl_pic_t which was previously returned by lacf_gl_pic_new() or lacf_gl_pic_new_from_dir().

Definition at line 139 of file lacf_gl_pic.c.

◆ lacf_gl_pic_draw()

void lacf_gl_pic_draw ( lacf_gl_pic_t *  pic,
vect2_t  pos,
vect2_t  size,
float  alpha 
)

Draws the image using the current X-Plane projection and modelview matrices. This makes it possible to use to draw either gauges into the panel texture, or windows during a window draw callback.

Parameters
posPosition of the lower left corner of the image relative to the coordinate system origin.
sizeThe size of the image for drawing. You can pass NULL_VECT2 here to make the image draw using its native size.
alphaFloating point value 0-1 for partial alpha compositing. This is passed to the fragment shader in a uniform, to let the fragment shader perform partial alpha blending.

Definition at line 251 of file lacf_gl_pic.c.

◆ lacf_gl_pic_draw_custom()

void lacf_gl_pic_draw_custom ( lacf_gl_pic_t *  pic,
vect2_t  pos,
vect2_t  size,
GLuint  prog 
)

Draws the image using a custom OpenGL program. You can use this function to perform custom image compositing using your own shaders.

Parameters
posPosition of the lower left corner of the image relative to the coordinate system origin.
sizeThe size of the image for drawing. You can pass NULL_VECT2 here to make the image draw using its native size.
progThe OpenGL program to use for drawing. You must bind this program before calling this function using glUseProgram(). The program must take the same inputs as glutils_draw_quads() for vertex positions.

Definition at line 293 of file lacf_gl_pic.c.

◆ lacf_gl_pic_get_height()

int lacf_gl_pic_get_height ( lacf_gl_pic_t *  pic)
Returns
The pixel height of the image. This may need to perform disk I/O to load the image and determine its dimensions. If loading the image failed, returns 0.

Definition at line 214 of file lacf_gl_pic.c.

◆ lacf_gl_pic_get_tex()

GLuint lacf_gl_pic_get_tex ( lacf_gl_pic_t *  pic)
Returns
The texture holding the image data on the GPU. This may need to perform disk I/O to load the image and upload it to the GPU. If loading the image failed, returns 0.

Definition at line 228 of file lacf_gl_pic.c.

◆ lacf_gl_pic_get_width()

int lacf_gl_pic_get_width ( lacf_gl_pic_t *  pic)
Returns
The pixel width of the image. This may need to perform disk I/O to load the image and determine its dimensions. If loading the image failed, returns 0.

Definition at line 200 of file lacf_gl_pic.c.

◆ lacf_gl_pic_load()

bool_t lacf_gl_pic_load ( lacf_gl_pic_t *  pic)

A newly initialized gl_pic_t is normally lazy-loaded and no disk I/O is performed until the image is to be drawn. This function allows you to pre-load the image into VRAM before it is needed.

Returns
B_TRUE if loading the image was successful (or the image was loaded already). B_FALSE if loading the image failed, either due to disk I/O or an issue with the image format on disk.

Definition at line 157 of file lacf_gl_pic.c.

◆ lacf_gl_pic_new()

lacf_gl_pic_t * lacf_gl_pic_new ( const char *  path)

Initializes a new gl_pic_t with a PNG image file on disk.

Note
This doesn't perform any disk I/O. gl_pic_t's are lazy-loaded on the first attempt to draw. If you want to pre-load a gl_pic_t ahead of time, use lacf_gl_pic_load().
Returns
A newly allocated gl_pic_t ready for drawing. Use gl_pic_destroy() to free the image after you are done with it.

Definition at line 99 of file lacf_gl_pic.c.

◆ lacf_gl_pic_new_from_dir()

lacf_gl_pic_t * lacf_gl_pic_new_from_dir ( const char *  dirpath,
const char *  filename 
)

This is a convenience front-end function to lacf_gl_pic_new(), which lets you provide a containing directory and image filename separately. This can be useful when the directory is subject to change, but the filename isn't. The function concatenates the path components before passing them on to lacf_gl_pic_new().

See also
lacf_gl_pic_new()

Definition at line 120 of file lacf_gl_pic.c.

◆ lacf_gl_pic_unload()

void lacf_gl_pic_unload ( lacf_gl_pic_t *  pic)

If the image was loaded, unloads the image and frees GPU-side VRAM buffers. This can be used to reduce the memory footprint of images you don't plan to use for a longer time. Do not call this function just between each frame. If you plan on drawing the image repeatedly, just keep it loaded. If you do not plan to draw the image for a long time, unloading it can save on VRAM usage.

If the image was unloaded already, this function does nothing.

Definition at line 176 of file lacf_gl_pic.c.