Permalink
Browse files

Update Readme and remove unneeded rebinds.

  • Loading branch information...
1 parent a82b760 commit 3a11645171111d641d95ad597f0d07eed544e5f3 @Queatz committed Jan 9, 2012
Showing with 29 additions and 25 deletions.
  1. +25 −5 README.md
  2. +4 −20 Text.cpp
View
@@ -1,25 +1,45 @@
-Shikoba is a text library for OpenGL 3 and above using the FreeType 2 library.
+Shikoba is a C++ text library for OpenGL 3 and above using the FreeType 2 library.
--- Quickstart --
+Depends
+------
+FreeType 2
+http://freetype.org/
+
+UTF8-CPP
+http://utfcpp.sourceforge.net/
+
+Quickstart
+---------
+
+C++:
// Create a library
Shikoba::Library * fontlib = new Shikoba::Library();
// Create a face in the library
Shikoba::Font * fontface = new Shikoba::Face(fontlib, "fontfile.ttf");
// Create a sized font out of a face
- // id_of_gl_texture is a GLuint of a texture for the font to use created and parameterized by you
+ // id_of_gl_texture is a GLuint of a texture for the font to use, created and parameterized by you
// Don't be changing this textures size or anything
Shikoba::Font * font = new Shikoba::Font(fontface, id_of_gl_texture, 32.0);
// Create a string of text
- Shikoba::Font * string = new Shikoba::Font(font, "The UTF-8 String.");
+ Shikoba::Font * string = new Shikoba::Font(font, (const uint8_t *) "The UTF-8 String.");
// Create an adjusted string of text
- Shikoba::Font * adjusted_string = new Shikoba::Font(font, "The UTF-8 String.", character_spacing, line_spacing, alignment, page_width, tab_space_count);
+ // See Shikoba.hpp for more details.
+ Shikoba::Font * adjusted_string = new Shikoba::Font(font,
+ (const uint8_t *) "The UTF-8 String.",
+ 1.0, # Character spacing
+ 1.5, # Line spacing
+ Shikoba::CENTER, # Alignment
+ 120, # Page width (0 = no wrapping)
+ 4 # Number of spaces a tab makes up
+ );
// Draw the text
+ // You set the active texture and vertex array before calling
// 0 and 1 are the attributes to use for vertex positions and texcoords
// All strings are drawn starting from (0, 0)
string->draw(0, 1)
View
@@ -231,34 +231,18 @@ void Text::draw(GLuint vertexattribute, GLuint texcoordattribute) {
GLint lasti;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &lasti);
+ // TODO Multiple textures aren't working yet (not sure if they have to)
glBindTexture(GL_TEXTURE_2D, _font->_textures.back());
- // Buffers
-
- GLint last, last2;
- glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last);
- glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last2);
-
- // Pen
- if((GLuint)last != _buffers[0])
- glBindBuffer(GL_ARRAY_BUFFER, _buffers[0]);
-
// Vertex + Texcoord
-
+ // TODO Move this into Text::Text()
+ glBindBuffer(GL_ARRAY_BUFFER, _buffers[0]);
glVertexAttribPointer(vertexattribute, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (const GLvoid *)0);
glVertexAttribPointer(texcoordattribute, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (const GLvoid *)(sizeof(GLfloat) * 2));
- if((GLuint)last2 != _buffers[1])
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffers[1]);
-
// Draw
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffers[1]);
glDrawElements(GL_TRIANGLES, _characters * 6, GL_UNSIGNED_SHORT, (const GLvoid *)0);
- // Restore
- glBindBuffer(GL_ARRAY_BUFFER, last);
-
- if((GLuint)last2 != _buffers[1])
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last2);
-
glBindTexture(GL_TEXTURE_2D, lasti);
}

0 comments on commit 3a11645

Please sign in to comment.