libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
gl Namespace Reference

Classes

class  ShaderProgram
 GLSL shader program wrapper (shared-ownership). More...
class  GLText
 Render SDL_ttf text into an OpenGL texture and display it on screen. More...
class  GLSprite
 A textured screen-space quad drawn with an OpenGL shader. More...
class  GLWindow
 SDL2 + OpenGL/ES window with event loop and console support. More...
class  GLObject
 Abstract interface for scene objects managed by a GLWindow. More...

Enumerations

enum class  GLMode { DESKTOP , ES }
 OpenGL mode: desktop GL or OpenGL ES. More...

Functions

GLuint loadTexture (const std::string &filename)
 Load a GL texture from a file.
GLuint loadTexture (const std::string &filename, int &w, int &h)
 Load a GL texture from a file and retrieve its dimensions.
GLuint createTexture (SDL_Surface *surface, bool flip)
 Create a new GL texture from an SDL_Surface.
GLuint createTexture (void *buffer, int width, int height)
 Create a new GL texture from a raw pixel buffer.
void updateTexture (GLuint texture, SDL_Surface *surface, bool flip)
 Replace a GL texture's contents from an SDL_Surface.
SDL_Surface * createSurface (int w, int h)
 Allocate a blank RGBA SDL_Surface.

Variables

const char * vSource
 Default vertex shader source.
const char * fSource
 Default fragment shader source.
const char * ftSource

Enumeration Type Documentation

◆ GLMode

enum class gl::GLMode
strong

OpenGL mode: desktop GL or OpenGL ES.

Enumerator
DESKTOP 
ES 

Definition at line 398 of file gl.hpp.

Function Documentation

◆ createSurface()

SDL_Surface * gl::createSurface ( int w,
int h )

Allocate a blank RGBA SDL_Surface.

Parameters
wWidth in pixels.
hHeight in pixels.
Returns
Newly allocated surface (caller owns it).

Definition at line 811 of file gl.cpp.

◆ createTexture() [1/2]

GLuint gl::createTexture ( SDL_Surface * surface,
bool flip )

Create a new GL texture from an SDL_Surface.

Parameters
surfaceSource surface.
flipIf true, flip vertically.
Returns
New GL texture ID.

Definition at line 743 of file gl.cpp.

References mx::Texture::flipSurface().

Referenced by mx::MXCapture::createImage().

◆ createTexture() [2/2]

GLuint gl::createTexture ( void * buffer,
int width,
int height )

Create a new GL texture from a raw pixel buffer.

Parameters
bufferPointer to RGBA data.
widthImage width.
heightImage height.
Returns
New GL texture ID.

Definition at line 778 of file gl.cpp.

◆ loadTexture() [1/2]

GLuint gl::loadTexture ( const std::string & filename)

Load a GL texture from a file.

Parameters
filenameImage file path.
Returns
GL texture ID.

Definition at line 689 of file gl.cpp.

References mx::Texture::flipSurface(), and png::LoadPNG().

Referenced by gl::GLSprite::loadTextureImpl(), gl::GLSprite::loadTextureImpl(), mx::Model::setTextures(), and mx::Model::setTexturesFromMTL().

◆ loadTexture() [2/2]

GLuint gl::loadTexture ( const std::string & filename,
int & w,
int & h )

Load a GL texture from a file and retrieve its dimensions.

Parameters
filenameImage file path.
wOutput: width.
hOutput: height.
Returns
GL texture ID.

Definition at line 717 of file gl.cpp.

References mx::Texture::flipSurface(), and png::LoadPNG().

◆ updateTexture()

void gl::updateTexture ( GLuint texture,
SDL_Surface * surface,
bool flip )

Replace a GL texture's contents from an SDL_Surface.

Parameters
textureTarget GL texture ID.
surfaceSource surface.
flipIf true, flip vertically before uploading.

Definition at line 795 of file gl.cpp.

References mx::Texture::flipSurface().

Variable Documentation

◆ fSource

const char * gl::fSource
Initial value:
= R"(#version 330 core
in vec2 TexCoord;
out vec4 FragColor;
uniform sampler2D textTexture;
void main() {
FragColor = texture(textTexture, TexCoord);
}
)"

Default fragment shader source.

Definition at line 862 of file gl.cpp.

Referenced by console::GLConsole::load().

◆ ftSource

const char* gl::ftSource
Initial value:
= R"(#version 330 core
in vec2 TexCoord;
out vec4 FragColor;
uniform sampler2D textTexture;
void main() {
FragColor = texture(textTexture, TexCoord);
if(FragColor.a < 0.1)
discard;
}
)"

Definition at line 870 of file gl.cpp.

Referenced by gl::GLText::init().

◆ vSource

const char * gl::vSource
Initial value:
= R"(#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
out vec2 TexCoord;
void main() {
gl_Position = vec4(aPos, 1.0);
TexCoord = aTexCoord;
}
)"

Default vertex shader source.

Definition at line 853 of file gl.cpp.

Referenced by gl::GLText::init(), and console::GLConsole::load().