29#include <emscripten/emscripten.h>
31#include<emscripten/html5.h>
33#include "gtc/type_ptr.hpp"
37#include <glm/gtc/matrix_transform.hpp>
38#include <glm/gtc/type_ptr.hpp>
68 std::shared_ptr<SharedState>
state;
100 void setName(const std::
string &n);
114 bool loadProgram(const std::
string &v, const std::
string &f);
129 void setUniform(const std::
string &name,
int value);
136 void setUniform(const std::
string &name,
float value);
143 void setUniform(const std::
string &name, const glm::vec2 &value);
150 void setUniform(const std::
string &name, const glm::vec3 &value);
157 void setUniform(const std::
string &name, const glm::vec4 &value);
164 void setUniform(const std::
string &name, const glm::mat4 &value);
203 GLuint createText(
const std::string &text, TTF_Font *font, SDL_Color
color,
int &textWidth,
int &textHeight,
bool solid =
true);
215 void renderText(
GLuint texture,
float x,
float y,
int textWidth,
int textHeight,
int screenWidth,
int screenHeight);
242 SDL_Color
color = {255,255,255,255};
281 void setName(
const std::string &name);
288 template<
typename ShaderT>
303 template<
typename ShaderT>
319 template<
typename ShaderT>
320 void loadTexture(ShaderT *shader,
const std::string &tex,
float x,
float y,
int textWidth,
int textHeight) {
333 template<
typename ShaderT>
334 void loadTexture(ShaderT *shader,
const std::string &tex,
float x,
float y) {
347 void draw(
int x,
int y);
356 void draw(
int x,
int y,
int w,
int h);
366 void draw(
GLuint texture_id,
float x,
float y,
int w,
int h);
386 void loadTextureImpl(
const std::string &tex,
float x,
float y,
int textWidth,
int textHeight);
416 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE webglContext = 0;
417 void restoreContext();
454 void initGL(
const std::string &title,
int width,
int height,
bool resize_ =
true);
461 void initGL(
int width,
int height);
513 void setWindowTitle(
const std::string &title);
520 void setWindowSize(
int w,
int h);
526 void setWindowIcon(SDL_Surface *ico);
532 void setFullScreen(
bool full);
540 void activateConsole(
const std::string &fnt,
int size,
const SDL_Color &color);
549 void activateConsole(
const SDL_Rect &rc,
const std::string &fnt,
int size,
const SDL_Color &color);
558 void showConsole(
bool show);
OpenGL-rendered overlay console built on top of Console.
Abstract interface for scene objects managed by a GLWindow.
virtual void resize(gl::GLWindow *win, int w, int h)
Called when the window is resized (optional).
virtual void event(GLWindow *window, SDL_Event &e)=0
Handle an SDL event.
virtual void draw(GLWindow *win)=0
Render the scene for the current frame.
virtual ~GLObject()=default
virtual void load(GLWindow *win)=0
Load GPU resources (textures, shaders, geometry).
void setShader(ShaderT *program)
Bind a shader program by extracting its GL ID.
void loadTexture(ShaderT *shader, const std::string &tex, float x, float y, int textWidth, int textHeight)
Load a texture from a file and set the sprite geometry.
void loadTexture(ShaderT *shader, const std::string &tex, float x, float y)
Load a texture from a file (natural dimensions).
int height
Texture pixel height.
void initWithTexture(ShaderT *program, GLuint texture, float x, float y, int textWidth, int textHeight)
Initialise the sprite from an existing GL texture.
GLSprite & operator=(GLSprite &&)=delete
std::vector< float > vertices
GLSprite()
Default constructor.
GLSprite(GLSprite &&)=delete
void setName(const std::string &name)
Assign a debug name (used in log messages).
void initSize(float w, float h)
Set the native display size of the sprite.
GLSprite(const GLSprite &)=delete
GLSprite & operator=(const GLSprite &)=delete
int width
Texture pixel width.
void loadTextureImpl(const std::string &tex, float x, float y, int textWidth, int textHeight)
void release()
Free all GL resources associated with this sprite.
void initWithTextureImpl(GLuint texture, float x, float y, int textWidth, int textHeight)
Render SDL_ttf text into an OpenGL texture and display it on screen.
void setColor(SDL_Color col)
Set the colour used for subsequent printText calls.
void printText_Solid(const mx::Font &f, float x, float y, const std::string &text)
Convenience: create and immediately draw solid text.
SDL_Color color
Current text colour.
int h
Viewport dimensions.
void init(int w, int h)
Initialise internal state with the viewport dimensions.
ShaderProgram textShader
Internal text quad shader.
GLText()
Default constructor.
void printText_Blended(const mx::Font &f, float x, float y, const std::string &text)
Convenience: create and immediately draw blended (anti-aliased) text.
void renderText(GLuint texture, float x, float y, int textWidth, int textHeight, int screenWidth, int screenHeight)
Draw a pre-created text texture at a given position.
GLuint createText(const std::string &text, TTF_Font *font, SDL_Color color, int &textWidth, int &textHeight, bool solid=true)
Rasterise a string to an OpenGL texture.
SDL2 + OpenGL/ES window with event loop and console support.
int w
Current window width.
int h
Current window height.
std::unique_ptr< gl::GLObject > object
Optional attached scene object.
virtual void resize(int w, int h)
Called when the window is resized (optional override).
virtual void event(SDL_Event &e)=0
Process a single SDL event (pure virtual).
GLWindow & operator=(GLWindow &&)=delete
GLWindow(GLWindow &&)=delete
void swap()
Swap front and back buffers to display the rendered frame.
void setPath(const std::string &path)
Set the asset search path.
virtual void draw()=0
Render the current frame (pure virtual).
void initGL(const std::string &title, int width, int height, bool resize_=true)
Initialise the GL context and SDL window.
GLWindow & operator=(const GLWindow &)=delete
mx::mxUtil util
Asset path and utility helpers.
void updateViewport()
Update the GL viewport to match the current window size.
GLWindow(const GLWindow &)=delete
GLWindow(const std::string &text, int width, int height, bool resize_=true, GLMode mode=GLMode::DESKTOP)
Construct and open an SDL2 + OpenGL window.
GLSL shader program wrapper (shared-ownership).
std::shared_ptr< SharedState > state
void setSilent(bool s)
Suppress compilation/link error output.
void release()
Release the underlying GL program (decrements shared count).
void setUniform(const std::string &name, int value)
Upload an integer uniform variable.
ShaderProgram(ShaderProgram &&) noexcept=default
ShaderProgram()
Default constructor — allocates shared state, no program compiled yet.
bool loadProgram(const std::string &v, const std::string &f)
Compile and link shaders from file paths.
GLuint createProgramFromFile(const std::string &vert, const std::string &frag)
ShaderProgram(const ShaderProgram &)=default
GLuint createProgram(const char *vshaderSource, const char *fshaderSource)
void setName(const std::string &n)
Assign a human-readable name used in error messages.
bool loadProgramFromText(const std::string &v, const std::string &f)
Compile and link shaders from source-code strings.
void useProgram()
Bind this shader program for subsequent draw calls.
ShaderProgram & operator=(const ShaderProgram &)=default
int printShaderLog(GLuint shader)
void printProgramLog(int p)
RAII wrapper around a TTF_Font handle.
SDL_mixer–based audio manager.
Utility bag for SDL-based applications.
Compile-time feature flags and version macros for libmx.
OpenGL-backed in-game terminal console for libmx2.
Central SDL2 application window class and related includes.
const char * vSource
Default vertex shader source.
GLuint createTexture(SDL_Surface *surface, bool flip)
Create a new GL texture from an SDL_Surface.
GLMode
OpenGL mode: desktop GL or OpenGL ES.
GLuint loadTexture(const std::string &filename)
Load a GL texture from a file.
SDL_Surface * createSurface(int w, int h)
Allocate a blank RGBA SDL_Surface.
const char * fSource
Default fragment shader source.
void updateTexture(GLuint texture, SDL_Surface *surface, bool flip)
Replace a GL texture's contents from an SDL_Surface.