Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The simplest way is to load a font map from a image, such as those generated by the <a href="http://www.lmnopc.com/bitmapfontbuilder/" rel="nofollow noreferrer">bitmap font builder</a> (I know it's windows but I can't find one for linux), eg:</p> <p><img src="https://i.stack.imgur.com/VFKM2.gif" alt="bitmap font example"></p> <p>The example is a 256x256 gif, though you may what to convert it to a png/tga/bmp. It's full ASCII mapped gird, 16x16 characters. Load the texture and use glTexCoord2f to line it up on your quad, and you should be good to go.</p> <p>Here's an example using a bitmap of the above:</p> <pre><code>unsigned texture = 0; void LoadTexture() { // load 24-bit bitmap texture unsigned offset, width, height, size; char *buffer; FILE *file = fopen("text.bmp", "rb"); if (file == NULL) return; fseek(file, 10, SEEK_SET); fread(&amp;offset, 4, 1, file); fseek(file, 18, SEEK_SET); fread(&amp;width, 1, 4, file); fread(&amp;height, 1, 4, file); size = width * height * 3; buffer = new char[size]; fseek(file, offset, SEEK_SET); fread(buffer, 1, size, file); glEnable(GL_TEXTURE_2D); glGenTextures(1, &amp;texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer); fclose(file); printf("Loaded\n"); } void DrawCharacter(char c) { int column = c % 16, row = c / 16; float x, y, inc = 1.f / 16.f; x = column * inc; y = 1 - (row * inc) - inc; glBegin(GL_QUADS); glTexCoord2f( x, y); glVertex3f( 0.f, 0.f, 0.f); glTexCoord2f( x, y + inc); glVertex3f( 0.f, 1.f, 0.f); glTexCoord2f( x + inc, y + inc); glVertex3f( 1.f, 1.f, 0.f); glTexCoord2f( x + inc, y); glVertex3f( 1.f, 0.f, 0.f); glEnd(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload