52*
void draw()
override { }
53*
void animate(
double t)
override { }
55*
int main(){ MyApp().run(); }
69 GLApp(uint32_t w=640, uint32_t h=480, uint32_t s=4,
70 const std::string& title =
"My OpenGL App",
71 bool fpsCounter=
true,
bool sync=
true);
114 const Vec3& bl=
Vec3{-1.0f,-1.0f,0.0f},
115 const Vec3& br=
Vec3{1.0f,-1.0f,0.0f},
116 const Vec3& tl=
Vec3{-1.0f,1.0f,0.0f},
117 const Vec3& tr=
Vec3{1.0f,1.0f,0.0f});
125 const Vec3& bl=
Vec3{-1.0f,-1.0f,0.0f},
126 const Vec3& br=
Vec3{1.0f,-1.0f,0.0f},
127 const Vec3& tl=
Vec3{-1.0f,1.0f,0.0f},
128 const Vec3& tr=
Vec3{1.0f,1.0f,0.0f});
131 const Vec3& bl=
Vec3{-1.0f,-1.0f,0.0f},
132 const Vec3& br=
Vec3{1.0f,-1.0f,0.0f},
133 const Vec3& tl=
Vec3{-1.0f,1.0f,0.0f},
134 const Vec3& tr=
Vec3{1.0f,1.0f,0.0f});
145 void drawPoints(
const std::vector<float>& data,
float pointSize=1.0f,
bool useTex=
false);
176 const Vec3& center=
Vec3{0.0f,0.0f,0.0f})
const;
180 const Vec3& center=
Vec3{0.0f,0.0f,0.0f})
const;
201 uint32_t y, uint8_t components);
218 virtual void resize(
int width,
int height);
222 virtual void keyboard(
int key,
int scancode,
int action,
int mods) {}
226 virtual void mouseMove(
double xPosition,
double yPosition) {}
228 virtual void mouseButton(
int button,
int state,
int mods,
double xPosition,
double yPosition) {}
230 virtual void mouseWheel(
double x_offset,
double y_offset,
double xPosition,
double yPosition) {}
261 bool animationActive;
263 GLsizei lastTrisCount;
272 static void mainLoopWrapper(
void* arg) {
278 static bool sizeCallback(
int eventType,
const EmscriptenUiEvent *uiEvent,
void *userData);
280 static bool keyCallback(
int eventType,
const EmscriptenKeyboardEvent* keyEvent,
void* userData);
282 static bool cursorPositionCallback(
int eventType,
const EmscriptenMouseEvent *mouseEvent,
void *userData);
284 static bool mouseButtonUpCallback(
int eventType,
const EmscriptenMouseEvent *mouseEvent,
void *userData);
286 static bool mouseButtonDownCallback(
int eventType,
const EmscriptenMouseEvent *mouseEvent,
void *userData);
288 static bool mouseButtonCallback(
int eventType,
const EmscriptenMouseEvent *mouseEvent,
void *userData);
290 static bool scrollCallback(
int eventType,
const EmscriptenWheelEvent *wheelEvent,
void *userData);
293 static GLApp* staticAppPtr;
295 static void sizeCallback(GLFWwindow* window,
int width,
int height);
297 static void keyCallback(GLFWwindow* window,
int key,
int scancode,
int action,
int mods);
299 static void keyCharCallback(GLFWwindow* window,
unsigned int codepoint);
301 static void cursorPositionCallback(GLFWwindow* window,
double xPosition,
double yPosition);
303 static void mouseButtonCallback(GLFWwindow* window,
int button,
int state,
int mods);
305 static void scrollCallback(GLFWwindow* window,
double x_offset,
double y_offset);
319 void triangulate(
const Vec3& p0,
324 std::vector<float>& trisData);
LineDrawType
Line primitive topology for drawLines().
Definition GLApp.h:30
@ LIST
Disconnected line segments (GL_LINES)
Definition GLApp.h:31
@ STRIP
Connected polyline (GL_LINE_STRIP)
Definition GLApp.h:32
@ LOOP
Closed polyline (GL_LINE_LOOP)
Definition GLApp.h:33
TrisDrawType
Triangle primitive topology for drawTriangles().
Definition GLApp.h:39
@ FAN
Triangle fan (GL_TRIANGLE_FAN)
Definition GLApp.h:42
Cross‑platform key/mouse translation layer for GLFW vs. Emscripten.
RAII wrapper for an OpenGL Vertex Array Object (VAO).
Thin RAII wrapper for an OpenGL buffer object with upload/binding helpers.
Cross‑platform OpenGL window/context helper for desktop and Emscripten.
RAII wrapper around an OpenGL shader program with rich uniform/texture setters.
RAII wrapper for an OpenGL 2D texture with byte/half/float upload helpers.
Lightweight image container with basic processing utilities.
Mat4t< float > Mat4
Single-precision 4×4 matrix.
Definition Mat4.h:567
Vec2t< float > Vec2
Float vector (x,y).
Definition Vec2.h:258
Vec2t< uint32_t > Vec2ui
32-bit unsigned integer vector (x,y).
Definition Vec2.h:262
Vec3t< float > Vec3
3D float vector (x,y,z).
Definition Vec3.h:424
Vec4t< float > Vec4
4D float vector (x,y,z,w).
Definition Vec4.h:337
Simple app runner with a GL context, stock shaders, and draw helpers.
Definition GLApp.h:58
virtual void animate(double animationTime)
Per‑frame animation/update hook; parameter is seconds since start.
Definition GLApp.h:216
void drawPoints(const std::vector< float > &data, float pointSize=1.0f, bool useTex=false)
Draw an array of colored points.
Definition GLApp.cpp:511
GLProgram simpleTexProg
Textured quad shader (pos+uv).
Definition GLApp.h:241
void setPointTexture(const std::vector< uint8_t > &shape, uint32_t x, uint32_t y, uint8_t components)
Set the point sprite from raw bytes.
Definition GLApp.cpp:302
virtual void keyboard(int key, int scancode, int action, int mods)
Keyboard event; parameters mirror backend callbacks.
Definition GLApp.h:222
float getAspect() const
Current window aspect ratio (width/height).
GLTexture2D pointSprite
Point‑sprite base texture.
Definition GLApp.h:246
Mat4 mvi
Inverse of mv (for lighting helpers).
Definition GLApp.h:236
void drawRect(const Vec4 &color, const Vec2 &bl, const Vec2 &tr)
Draw a solid‑color rectangle given 2D corners.
Definition GLApp.cpp:824
GLTexture2D pointSpriteHighlight
Optional highlight overlay sprite.
Definition GLApp.h:247
Mat4 computeImageTransform(const Vec2ui &imageSize) const
Compute a uniform image scale so the longer side fits the window.
Definition GLApp.cpp:837
void redrawTriangles(bool wireframe)
Re‑issue the last triangle draw using cached settings.
Definition GLApp.cpp:556
Mat4 getDrawTransform() const
Current model‑view matrix.
Definition GLApp.cpp:737
Mat4 p
Projection matrix used by stock shaders.
Definition GLApp.h:234
void setAnimation(bool animationActive)
Enable/disable the animation step inside the main loop.
void setPointHighlightTexture(const Image &shape)
Set an optional highlight overlay sprite from an Image.
Definition GLApp.cpp:298
virtual void draw()
Per‑frame draw hook.
Definition GLApp.h:214
void setDrawTransform(const Mat4 &mat)
Set the model‑view matrix used by the stock shaders.
Definition GLApp.cpp:741
GLProgram simpleSpriteProg
Point sprite shader (pos+color+texture).
Definition GLApp.h:239
GLProgram simpleProg
Solid color shader (pos+color).
Definition GLApp.h:237
void drawImage(const GLTexture2D &image, const Vec2 &bl, const Vec2 &tr)
Draw a textured quad from a texture handle using 2D corners.
Definition GLApp.cpp:772
void setImageFilter(GLint magFilter, GLint minFilter)
Update filtering for images drawn by drawImage().
Definition GLApp.cpp:768
void resetAnimation()
Reset the animation timer and invoke animate(0).
GLArray simpleArray
VAO used by helpers.
Definition GLApp.h:243
Mat4 mv
Model‑view matrix used by stock shaders.
Definition GLApp.h:235
void setDrawProjection(const Mat4 &mat)
Set the projection matrix used by the stock shaders.
Definition GLApp.cpp:729
void shaderUpdate()
Update stock shader uniforms (MVP/MV/MVit) to current transforms.
Definition GLApp.cpp:746
GLProgram simplePointProg
Point shader (pos+color), desktop uses glPointSize.
Definition GLApp.h:238
void drawLines(const std::vector< float > &data, LineDrawType t, float lineThickness=1.0f)
Draw colored lines using the given topology.
Definition GLApp.cpp:411
Mat4 getDrawProjection() const
Current projection matrix.
Definition GLApp.cpp:733
void run()
Create the context/window and enter the render loop.
Definition GLApp.cpp:346
GLEnv glEnv
Window/context + platform utilities.
Definition GLApp.h:233
virtual void mouseWheel(double x_offset, double y_offset, double xPosition, double yPosition)
Mouse wheel/trackpad scroll event with cursor position.
Definition GLApp.h:230
GLProgram simpleLightProg
Lit shader (pos+color+normal).
Definition GLApp.h:242
void resetPointTexture(uint32_t resolution=64)
Create a default circular mask texture of given resolution.
Definition GLApp.cpp:307
void closeWindow()
Request closing the window.
Definition GLApp.h:258
bool getAnimation() const
Query whether animation is currently active.
Mat4 computeImageTransformFixedWidth(const Vec2ui &imageSize, float width=1.0f, const Vec3 ¢er=Vec3{0.0f, 0.0f, 0.0f}) const
Compute a transform that fits an image to a given width.
Definition GLApp.cpp:854
virtual ~GLApp()
Virtual destructor.
Definition GLApp.cpp:291
virtual void keyboardChar(unsigned int key)
Unicode character input.
Definition GLApp.h:224
GLApp(uint32_t w=640, uint32_t h=480, uint32_t s=4, const std::string &title="My OpenGL App", bool fpsCounter=true, bool sync=true)
Construct the environment and boot the stock shaders/buffers.
Definition GLApp.cpp:7
virtual void resize(int width, int height)
Resize notification; override to update projection, etc.
Definition GLApp.cpp:359
virtual void mouseButton(int button, int state, int mods, double xPosition, double yPosition)
Mouse button event with cursor position.
Definition GLApp.h:228
virtual void init()
One‑time initialization hook (resources, buffers, etc.).
Definition GLApp.h:212
GLBuffer simpleVb
VBO used by helpers.
Definition GLApp.h:244
double resumeTime
Timestamp used to keep animation time continuous on resume.
Definition GLApp.h:248
Mat4 computeImageTransformFixedHeight(const Vec2ui &imageSize, float height=1.0f, const Vec3 ¢er=Vec3{0.0f, 0.0f, 0.0f}) const
Compute a transform that fits an image to a given height.
Definition GLApp.cpp:845
GLTexture2D raster
Temporary texture for drawImage(Image).
Definition GLApp.h:245
virtual void mouseMove(double xPosition, double yPosition)
Mouse move event (window coordinates).
Definition GLApp.h:226
void resetPointHighlightTexture()
Clear the highlight overlay sprite.
Definition GLApp.cpp:323
void drawTriangles(const std::vector< float > &data, TrisDrawType t, bool wireframe, bool lighting)
Upload triangle data and draw immediately (or as wireframe edges).
Definition GLApp.cpp:698
GLProgram simpleHLSpriteProg
Point sprite + highlight overlay.
Definition GLApp.h:240
Window/context manager for OpenGL (GLFW+GLEW) or WebGL (Emscripten).
Definition GLEnv.h:63
OpenGL shader program with helpers for creation and data binding.
Definition GLProgram.h:59
Definition GLTexture2D.h:19