All Projects → vallentin → glText

vallentin / glText

Licence: Zlib license
Cross-platform single header text rendering library for OpenGL

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to glText

Tinyrenderer
A brief computer graphics / rendering course
Stars: ✭ 11,776 (+12562.37%)
Mutual labels:  rendering, computer-graphics
D2dlib
A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
Stars: ✭ 84 (-9.68%)
Mutual labels:  drawing, rendering
Tinykaboom
A brief computer graphics / rendering course
Stars: ✭ 2,077 (+2133.33%)
Mutual labels:  rendering, computer-graphics
Tinyraycaster
486 lines of C++: old-school FPS in a weekend
Stars: ✭ 1,383 (+1387.1%)
Mutual labels:  rendering, computer-graphics
C-Raytracer
A CPU raytracer from scratch in C
Stars: ✭ 49 (-47.31%)
Mutual labels:  rendering, computer-graphics
Yocto Gl
Yocto/GL: Tiny C++ Libraries for Data-Driven Physically-based Graphics
Stars: ✭ 1,391 (+1395.7%)
Mutual labels:  rendering, computer-graphics
Usd Resources
A curated list of USD projects and resources
Stars: ✭ 250 (+168.82%)
Mutual labels:  rendering, computer-graphics
Easy3d
A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
Stars: ✭ 383 (+311.83%)
Mutual labels:  rendering, computer-graphics
Photon-v2
A program that takes photographs of a virtual world.
Stars: ✭ 75 (-19.35%)
Mutual labels:  rendering, computer-graphics
CompenNet
[CVPR'19] End-to-end Projector Photometric Compensation
Stars: ✭ 35 (-62.37%)
Mutual labels:  rendering, computer-graphics
Redner
Differentiable rendering without approximation.
Stars: ✭ 964 (+936.56%)
Mutual labels:  rendering, computer-graphics
FunMirrors
This is a fun project I created to motivate computer vision enthusiasts and to highlight the importance of understanding fundamental concepts related to image formation in a camera.
Stars: ✭ 43 (-53.76%)
Mutual labels:  rendering, computer-graphics
Opengraphic
Graphic Engine & Game Engine lists
Stars: ✭ 772 (+730.11%)
Mutual labels:  rendering, computer-graphics
Herebedragons
A basic 3D scene implemented with various engines, frameworks or APIs.
Stars: ✭ 1,616 (+1637.63%)
Mutual labels:  rendering, computer-graphics
Open3d
Open3D: A Modern Library for 3D Data Processing
Stars: ✭ 5,860 (+6201.08%)
Mutual labels:  rendering, computer-graphics
Blender
Official mirror of Blender
Stars: ✭ 4,175 (+4389.25%)
Mutual labels:  rendering, computer-graphics
CLUSEK-RT
Vulkan based C++ ray-tracing game engine.
Stars: ✭ 24 (-74.19%)
Mutual labels:  rendering, computer-graphics
Tinyraytracer
A brief computer graphics / rendering course
Stars: ✭ 3,971 (+4169.89%)
Mutual labels:  rendering, computer-graphics
Graphicsrenderer
A drop-in UIGraphicsRenderer port -- CrossPlatform, Swift 4, Image & PDF
Stars: ✭ 85 (-8.6%)
Mutual labels:  drawing, rendering
photon mapping
minimal but extensible header only implementation of photon mapping in C++
Stars: ✭ 65 (-30.11%)
Mutual labels:  rendering, computer-graphics

glText

Build Status Release Supported OpenGL 3.3 License

glText is a simple cross-platform single header text rendering library for OpenGL. glText requires no additional files (such as fonts or textures) for drawing text, everything comes pre-packed in the header.

simple example

The above screenshot is of the simple.c example.

Example

// Initialize glText
gltInit();

// Creating text
GLTtext *text = gltCreateText();
gltSetText(text, "Hello World!");

// Begin text drawing (this for instance calls glUseProgram)
gltBeginDraw();

// Draw any amount of text between begin and end
gltColor(1.0f, 1.0f, 1.0f, 1.0f);
gltDrawText2D(text, x, y, scale);

// Finish drawing text
gltEndDraw();

// Deleting text
gltDeleteText(text);

// Destroy glText
gltTerminate();

Implementation

In one C or C++ file, define GLT_IMPLEMENTATION prior to inclusion to create the implementation.

#define GLT_IMPLEMENTATION
#include "gltext.h"

Optimization

Each time gltDraw*() functions are called, glGetIntegerv(GL_VIEWPORT, ...) is called. To avoid this and optimize that call away, define GLT_MANUAL_VIEWPORT before including gltext.h.

#define GLT_MANUAL_VIEWPORT
#include "gltext.h"

Then when the viewport is resized manually call:

gltViewport(width, height)

Manual Model, View, Projection Matrix

The example uses LinearAlgebra.

GLfloat fontScale = 0.01f;

GLfloat x = 0.0f;
GLfloat y = 0.0f;

x -= gltGetTextWidth(text, fontScale) * 0.5f;
y -= gltGetTextHeight(text, fontScale) * 0.5f;

mat4 proj = mat4::perspective(70.0f, viewportWidth, viewportHeight, 0.1f, 10.0f);

mat4 view = ...;

mat4 model = mat4::identity;
model.translate(x, y + gltGetTextHeight(text, fontScale));
model.scale(fontScale, -fontScale);

mat4 mvp = proj * view * model;

gltDrawText(text, (GLfloat*)&mvp);

Aligned Text

// Where horizontal is either:
// - GLT_LEFT (default)
// - GLT_CENTER
// - GLT_RIGHT

// Where vertical is either:
// - GLT_TOP (default)
// - GLT_CENTER
// - GLT_BOTTOM

gltDrawText2DAligned(text, x, y, scale, horizontal, vertical);

No Dependencies

glText has no external dependencies besides OpenGL and the standard C libraries. By default glText uses stdlib.h, string.h and stdint.h.

If GLT_DEBUG is defined assert.h is needed. If GLT_DEBUG_PRINT is defined stdio.h is needed.

Reporting Bugs & Requests

Feel free to use the issue tracker, for reporting bugs, submitting patches or requesting features.

Before submitting bugs, make sure that you're using the latest version of glText.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].