/** * Initialize FontStashAdapter, it will initialize necessary data structure for fonstate.h, * generate GL buffers, setting the matrix, etc */ void FontStashAdapter::init(int width, int height, int flags, Rect& viewport) { this->instance = this; this->viewportSize = viewport; this->orthogonalProjection = glm::ortho(0.0f, viewportSize.width, viewportSize.height, 0.0f, -1.0f, 1.0f ); glGenBuffers(3, this->bufferIDs); this->shaderLib = SHADERLIB_FONT_PASS->clone(); this->shaderLib->compileShader(); FONSparams params; memset(¶ms, 0, sizeof(params)); params.width = width; params.height = height; params.flags = (unsigned char)flags; params.userPtr = NULL; /* No user data is needed, we're going to refer to this instance's data member */ /* Function callback handlers */ params.renderCreate = FontStashAdapter::renderCreate; params.renderResize = FontStashAdapter::renderResize; params.renderUpdate = FontStashAdapter::renderUpdate; params.renderDraw = FontStashAdapter::renderDraw; params.renderDelete = FontStashAdapter::renderDelete; context = fonsCreateInternal(¶ms); initialized = true; }
void FontContext::initFontContext(int _atlasSize) { m_atlas = std::unique_ptr<Texture>(new Texture(_atlasSize, _atlasSize)); FONSparams params; params.width = _atlasSize; params.height = _atlasSize; params.flags = (unsigned char)FONS_ZERO_TOPLEFT; params.renderCreate = renderCreate; params.renderResize = nullptr; params.renderUpdate = renderUpdate; params.renderDraw = nullptr; params.renderDelete = nullptr; params.pushQuad = pushQuad; params.userPtr = (void*) this; m_fsContext = fonsCreateInternal(¶ms); fonsSetErrorCallback(m_fsContext, &fontstashError, (void*) this); }