![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
Functions | |
| void | lg_init_textures_module () |
| LG_Texture * | lg_texture_new_from_data (lg_tc_format tc_format, int tex_type, const char *path, void *data, void **cubemap_data, size_t size, int w, int h, int n_mipmaps) |
| LG_Texture * | lg_texture_new_from_file (int tex_type, const char *path) |
| SDL_Surface * | lg_sdl_surf_from_file (const char *path, int scale_x, int scale_y) |
| void * | lg_compressed_texdata_from_file (const char *path, lg_tc_format *tc_format, size_t *size, int *w, int *h, int *n_mipmaps) |
| zboolean | lg_test_file_extension (const char *path, const char *ext) |
| int | lg_get_png_dims (const char *path, int *w, int *h) |
| zboolean | is_lg_tex (LG_Texture *node) |
| void | lg_texture_remove (LG_Texture *node) |
| void | lg_texture_remove_all () |
| LG_Texture * | lg_texture_first (LG_Texture *node) |
| LG_Texture * | lg_texture_last (LG_Texture *node) |
| LG_Texture * | lg_texture_find_by_id (uint32_t id) |
| int | lg_texture_count_nodes () |
| int | lg_texture_count_gl_tex () |
| void | lg_texture_info (const LG_Texture *tex) |
| void | lg_texture_info_all () |
| void | lg_texture_list_all () |
| zboolean | lg_read_pixels_from_screen (void *pixels, Rec2Di r) |
| zboolean | lg_write_pixels_to_screen (void *pixels, const Rec2Di *dest) |
| void | lg_texture_unbind (LG_Texture *tex) |
| void | lg_tex_units_info () |
| unsigned int | lg_get_active_tex () |
| void | lg_active_tex_info () |
| void | lg_free_sdl_surf (SDL_Surface *surf) |
| int | lg_surf_depth (SDL_Surface *surf) |
| void | lg_info_out_read_framebuffer () |
=== Handle all texture related stuff ===
We're using a global doubly-linked list.
Vars storing the texture list and the assigned tex units:
These vars are for all libgame and app textures, and are updated by all funcs creating or removing textures.
They are 'private', there is no public API, apart from lg_texture_get_node0().
So, you can/should only use this func to create new textures:
LG_Texture *lg_texture_new_from_file(int tex_type, const char *path)
and you can/should only use this func when done with a texture:
void lg_texture_remove(LG_Texture *node)
and just ignore the details.
(Use everything here only if you know what you're doing).
*** WARNING: Rendering of DXT1/3 textures with mipmaps is still f**ked up at the moment, so avoid them until it's fixed ***
| void lg_init_textures_module | ( | ) |
Must be called at init time in libgame.c
| LG_Texture* lg_texture_new_from_data | ( | lg_tc_format | tc_format, |
| int | tex_type, | ||
| const char * | path, | ||
| void * | data, | ||
| void ** | cubemap_data, | ||
| size_t | size, | ||
| int | w, | ||
| int | h, | ||
| int | n_mipmaps | ||
| ) |
Create a new LG_Texture node from data (either a SDL_Surface or compressed tex data), and ADD IT to the global doubly-linked list
(Completely replace SDL_CreateTextureFromSurface())
Now also reading compressed textures - see lg_dds_loader.c/h
About mipmaps:
| tc_format | If tc_format == LG_TC_UNCOMPRESSED, data is a SDL_Surface, otherwise data is compressed texture data |
| tex_type | GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
| path | Path to image file, only used at this point to store info |
| data | A pointer to compressed texture data or a SDL_Surface - ignored if tex_type == GL_TEXTURE_CUBE_MAP |
| cubemap_data | Array of 6 compressed tex data or 6 SDL_Surface's - ignored if tex_type == GL_TEXTURE_2D |
| size | Size - ignored if texture is not compressed |
| w | Width |
| h | Height |
| n_mipmaps | Number of generated mipmaps - WARNING: original image is considered mipmap level 0, so n_mipmaps must be at least 1 |
| LG_Texture* lg_texture_new_from_file | ( | int | tex_type, |
| const char * | path | ||
| ) |
Create a new LG_Texture node from a file and ADD IT to the global doubly-linked list
=== You should use this func when creating new textures ===
*** WARNING #1: Rendering of DXT1/3 textures with mipmaps is still f**ked up at the moment, so avoid them until it's fixed ***
*** WARNING #2: stbi_info() doesn't work on Android - used (only) to get jpg file dims, so avoid them until (?) ***
(Seems stb_image is f**ked up on Android and pretty useless, should probably get rid of it)
| tex_type | GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
| path | Path to image file |
| SDL_Surface* lg_sdl_surf_from_file | ( | const char * | path, |
| int | scale_x, | ||
| int | scale_y | ||
| ) |
For image and NON-compressed tex files
NO scaling is applied if scale_x == 0 or scale_y == 0
Otherwise, scale_x/y apply to env->top_win_logical_w/h, ie
| path | Path to image file |
| scale_x | |
| scale_y |
| void* lg_compressed_texdata_from_file | ( | const char * | path, |
| lg_tc_format * | tc_format, | ||
| size_t * | size, | ||
| int * | w, | ||
| int * | h, | ||
| int * | n_mipmaps | ||
| ) |
For compressed tex files
Supported file formats and texture compression formats:
Returned data must be freed afterwards
| path | Path to compressed tex file |
| tc_format | Pointer to lg_tc_format |
| size | Pointer to size |
| w | Pointer to width |
| h | Pointer to height |
| n_mipmaps | Pointer n_mipmaps |
| zboolean lg_test_file_extension | ( | const char * | path, |
| const char * | ext | ||
| ) |
Test path against file extension (case-insensitive strings comparaison)
NOTE: doesn't search backward for '.' but uses extension string length instead, so extension should include '.', ie ".png", not "png"
| path | Path |
| ext | File extension to test against (ie ".png", ".jpg", etc) |
| int lg_get_png_dims | ( | const char * | path, |
| int * | w, | ||
| int * | h | ||
| ) |
Get PNG image dimensions
| path | Path |
| w | Width |
| h | Height |
| zboolean is_lg_tex | ( | LG_Texture * | node | ) |
Check if a LG_Texture node is valid, ie non NULL and with a valid signature
| void lg_texture_remove | ( | LG_Texture * | node | ) |
Remove node from list AND free node and all associated resources (including the GL texture), if != <node0>
=== You should use this func when done with a texture ===
WARNING: must be a valid texture and need a valid GL context, or will segfault
Anyways, lg_texture_remove_all() is always called by lg_quit() so you shouldn't worry too much about memory leaks
| node | A LG_Texture node |
| void lg_texture_remove_all | ( | ) |
Remove all nodes (but <node0>) from list, freeing all resources (including GL textures)
WARNING:
| LG_Texture* lg_texture_first | ( | LG_Texture * | node | ) |
| LG_Texture* lg_texture_last | ( | LG_Texture * | node | ) |
| LG_Texture* lg_texture_find_by_id | ( | uint32_t | id | ) |
Return first found occurence
| id | A LG_Texture id |
| int lg_texture_count_nodes | ( | ) |
Count all nodes - doesn't check if node->id is a valid GL texture
Include <node0>
| int lg_texture_count_gl_tex | ( | ) |
Count all nodes - check if node->id is a valid GL texture
Doesn't include <node0>
| void lg_texture_info | ( | const LG_Texture * | tex | ) |
Print out texture info
| tex | A LG_Texture |
| void lg_texture_info_all | ( | ) |
Print out texture info for all nodes
| void lg_texture_list_all | ( | ) |
Print out a list of all textures (id and path)
| zboolean lg_read_pixels_from_screen | ( | void * | pixels, |
| Rec2Di | r | ||
| ) |
Store a v-flipped image (don't ask me why it's v-flipped)
From some doc somewhere: "Only two format/type parameter pairs are accepted. GL_RGBA/GL_UNSIGNED_BYTE is always accepted, and the other acceptable pair can be discovered by querying GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE."
| pixels | A pixel buffer |
| r | A Rec2Di |
| zboolean lg_write_pixels_to_screen | ( | void * | pixels, |
| const Rec2Di * | dest | ||
| ) |
'Un-flip' the image provided by lg_read_pixels_from_screen()
If NULL, dest is the entire rendering target
| pixels | A pixel buffer |
| dest | A Rec2Di |
| void lg_texture_unbind | ( | LG_Texture * | tex | ) |
Unbind texture
| void lg_tex_units_info | ( | ) |
Print out texture units info
| unsigned int lg_get_active_tex | ( | ) |
| void lg_active_tex_info | ( | ) |
Print out active texture unit info
| void lg_free_sdl_surf | ( | SDL_Surface * | surf | ) |
Free SDL_Surface if not NULL
| surf | Addr of SDL_Surface |
| int lg_surf_depth | ( | SDL_Surface * | surf | ) |
Surface depth of a SDL_Surface
| surf | Addr of SDL_Surface |
| void lg_info_out_read_framebuffer | ( | ) |
Print out current bound read framebuffer info