42 create(std::move(fontFilename));
67 create(std::move(fontFilename));
88 SLstring msg =
"SLTexFont::create: File not found: " + fontFilename;
93 img.
load(fontFilename,
false);
103 for (y = 0; y < bmpH; ++y)
105 if (bmp[y * bmpW] == 0)
107 if ((hh <= 0 && h <= 0) || (h != hh && h > 0 && hh > 0))
108 SL_EXIT_MSG(
"Cannot determine font height (check first pixel column)");
121 SLint x0[224], y0[224], x1[224], y1[224];
124 for (r = 0; r < NbRow; ++r)
127 for (x = 1; x < bmpW; ++x)
129 if (bmp[(r * (h + 1) + h) * bmpW + x] == 0 || x == bmpW - 1)
131 if (x == start)
break;
136 y0[ch - 32] = r * (h + 1);
137 y1[ch - 32] = r * (h + 1) + h - 1;
145 for (x = ch - 32; x < 224; ++x)
155 for (r = 0; r < 14; ++r)
158 for (x = 0; x < 16; ++x)
159 l += x1[x + r * 16] - x0[x + r * 16] + 1;
160 if (l > lmax) lmax = l;
164 const SLint MARGIN_X = 2;
165 const SLint MARGIN_Y = 2;
166 lmax += 16 * MARGIN_X;
175 memset(bits, 0, texWidth * texHeight);
180 for (r = 0; r < 14; ++r)
182 for (
SLint xx = 0, ch = r * 16; ch < (r + 1) * 16; ++ch)
184 if (y1[ch] - y0[ch] == h - 1)
186 for (y = 0; y < h; ++y)
188 for (x = x0[ch]; x <= x1[ch]; ++x)
190 SLfloat alpha = ((
SLfloat)(bmp[x + (y0[ch] + y) * bmpW])) / 256.0f;
192 bits[(
SLuint)(xx + x - x0[ch]) +
193 (
SLuint)(r * (h + MARGIN_Y) + y) * texWidth] = (
SLuchar)(alpha * 256.0f);
197 xx += x1[ch] - x0[ch] + 1;
229 for (ch = 0; ch < 32; ++ch)
253 for (
const auto& line : lines)
256 if (sizeLine.
x > maxX) maxX = sizeLine.
x;
289 for (
SLuint i = 0; i < len; ++i)
293 if (c ==
'\\' && i < len - 1 && text[i + 1] ==
'n')
296 if (curX > maxX) maxX = curX;
297 lines.push_back(text.substr(iLineStart, i - iLineStart - 1) +
" ");
318 if (xBlank > maxX) maxX = xBlank;
320 lines.push_back(text.substr(iLineStart, iBlank - iLineStart + 1));
321 iLineStart = iBlank + 1;
327 lines.push_back(text.substr(iLineStart, i - iLineStart));
334 SLstring newLine = text.substr(iLineStart, len - iLineStart);
335 lines.push_back(newLine);
364 for (
auto& line : lines)
366 numP += line.length();
375 lines.push_back(text);
376 numP = text.length() * 4;
377 numI = text.length() * 2 * 3;
390 for (
auto& line : lines)
409 P[iV + 1].set(x + w, y);
410 P[iV + 2].set(x + w, y + h);
411 P[iV + 3].set(x, y + h);
CVPixelFormatGL
Pixel format according to OpenGL pixel format defines.
vector< SLstring > SLVstring
#define SL_EXIT_MSG(message)
vector< SLushort > SLVushort
@ AT_position
Vertex position as a 2, 3 or 4 component vectors.
@ AT_uv1
Vertex 1st texture coordinate as 2 component vector.
vector< SLVec2f > SLVVec2f
vector< SLVec3f > SLVVec3f
OpenCV image class with the same interface as the former SLImage class.
void load(const string &filename, bool flipVertical=true, bool loadGrayscaleIntoAlpha=false)
Loads the image with the appropriate image loader.
Generic Shader Program class inherited from SLGLProgram.
Encapsulation of an OpenGL shader program object.
Singleton class holding all OpenGL states.
static SLGLState * instance()
Public static instance getter for singleton pattern.
SLbool pixelFormatIsSupported(SLint pixelFormat)
Returns true if the according GL pixel format is valid in the GL context.
SLint _width
Texture image width in pixels (images exist either in _images or on the GPU or on both)
SLint _wrap_t
Wrapping in t direction.
SLint _min_filter
Minification filter.
SLint _wrap_s
Wrapping in s direction.
SLint _height
Texture image height in pixels (images exist either in _images or on the GPU or on both)
SLTextureType _texType
See SLTextureType.
CVVImage _images
Vector of CVImage pointers.
SLint _depth
3D Texture image depth (images exist either in _images or on the GPU or on both)
SLint _mag_filter
Magnification filter.
SLGLVertexArray encapsulates the core OpenGL drawing.
void setAttrib(SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
Adds a vertex attribute with data pointer and an element size.
void setIndices(SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
Adds the index array for indexed element drawing.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0)
Generates the VA & VB objects for a NO. of vertices.
void buildTextBuffers(SLGLVertexArray &vao, const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeight=1.5f)
void create(SLstring fontFilename)
SLGLProgram * _fontTexProgram
SLGLProgram * fontTexProgram()
SLVstring wrapTextToLines(SLstring text, SLfloat maxW)
SLVec2f calcTextSize(const SLstring &text, SLfloat maxWidth=0.0f, SLfloat lineHeightFactor=1.5f)
SLTexFont(SLstring fontFilename, SLGLProgram *fontTexProgram)
bool exists(std::string path, SLIOStreamKind kind)
Checks whether a given file exists.
unsigned nextPowerOf2(unsigned num)
Returns the next power of 2 to a passed number.
SLfloat width
Width of char. in tex-coord.
SLfloat ty1
Max. Texture y-coord.
SLfloat ty2
Min. Texture y-coord.
SLfloat tx1
Min. Texture x-coord.
SLfloat tx2
Max. Texture x-coord.