Giter Club home page Giter Club logo

libgltext's Introduction

libgltext

A very simple c++ opengl text rendering library with python wrappers. Too simple even for a makefile. There's also a pure python implementation under pywrappers/gltext_pyopenglversion/.

Using

There's no python setup.py install support. Just copy the pywrappers/gltext/ directory containing the prebuilt libraries where it's needed and it'll work on windows/macosx/linux. OR if you're happy to sacrifice some speed, then copy the one-python-file version pywrappers/gltext_pyopenglversion/gltext.py.

For usage example look into pywrappers/example.py. Users of c++ are surely hardcore enough not to require any additional help (evil laugh).

import gltext

tx = gltext.GLText("../data/font_proggy_opti_small.txt")
# init your opengl window here. important to do it before tx.init()
tx.init()

# draw white text on half-transparent black background
tx.drawbr("anchored from bottom-right", 100, 100, fgcolor=(1.,1.,1.,1.), bgcolor=(0.,0.,0.,0.5), z=1000.)
tx.drawtl("anchored from top-left", 100, 100)
tx.drawtl("below previous line", 100, 100 + tx.height)

The whole API:

# variables about current font (read-only)

self.height    = 0
self.ascender  = 0
self.descender = 0

# variables about current state

self.z       = False
self.fgcolor = (1.0, 1.0, 1.0, 1.0)
self.bgcolor = (1.0, 1.0, 1.0, 0.0)

# methods

# * fgcolor, bgcolor and z retain values from previous use.
# * if z is false then opengl depth-testing is turned off.
# * if the bgcolor is completely transparent (bgcolor[3] == 0),
#   then text background rendering is turned off.

def init(self):
def width(self, text): """ return string width in pixels """
# top
def drawtl(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawtr(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawtm(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
# bottom
def drawbl(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawbr(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawbm(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
# middle
def drawml(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawmr(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawmm(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
# baseline
def drawbll(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawblr(self, text, x, y, fgcolor=None, bgcolor=None, z=None):
def drawblm(self, text, x, y, fgcolor=None, bgcolor=None, z=None):

Building python wrappers

Should not be necessary as because pywrappers/gltext/ should already contain compiled wrappers for windows/linux/macosx.

pip install cython

cd pywrapper
python setup.py build

And now copy the built shared library wherever it's needed.

Windows 8.1

Tested with Visual C++ 2012 Express, Python 2.7.3 64 bit

run cmd.exe
set VS90COMNTOOLS=%VS110COMNTOOLS%
call "C:\devtools\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64
python setup.py build

Mac OS X

Yosemite works without problems.

Mountain Lion - to prevent errors like this:

/usr/libexec/gcc/powerpc-apple-darwin10/4.0.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386

disable ppc support:

export ARCHFLAGS="-arch i386 -arch x86_64"; python setup.py build

Third-party libraries

Uses stb_image for image loading.
Uses the Fluid Studios FontGen tool to generate font textures (tools/Fluid_Studios_Font_Generation_Tool.zip).


Random notes

python setup.py build > log.txt 2>&1
python setup.py build -c mingw32 > log.txt 2>&1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.