#ifndef OPENGLHANDLER_H #define OPENGLHANDLER_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include FT_FREETYPE_H struct VertexData { QVector2D position; QVector2D texCoord; }; struct Character { unsigned int TextureID; //ID handle of the glyph texture glm::ivec2 Size; //Size of glyph glm::ivec2 Bearing; //Offset from baseline to left/top of glyph long Advance; //Offset to advance to next glyph }; class OpenGLHandler { public: OpenGLHandler(); ~OpenGLHandler(); void run(); void processImage(const QImage& image, const QString& vertexShader, const QString& fragmentShader, const QString& textureVar, const QString& vertexPosVar, const QString& textureCoordVar); private: QOpenGLFunctions_3_3_Core* fun; QOpenGLContext _context; QOffscreenSurface _surface; QOpenGLFramebufferObject* _fbo; QImage* _image; QOpenGLShaderProgram* _shader; QOpenGLTexture _texture; FT_Library _ft; FT_Face _face; QMap _characters; QString vertexShader = "attribute vec4 aPosition;\n" "attribute vec2 aTexCoord;\n" "varying vec2 vTexCoord;\n" "void main()\n" "{\n" " gl_Position = aPosition;\n" " vTexCoord = aTexCoord;\n" "}"; QString fragmentShader = "uniform sampler2D texture;\n" "varying vec2 vTexCoord;\n" "void main()\n" "{\n" " gl_FragColor = texture2D(texture, vTexCoord);\n" "}"; unsigned int chVAO, chVBO; bool prepareShader(QString vertexShader, QString fragmentShader); bool prepareTexture(const QImage& image); bool prepareCoords(QOpenGLBuffer vertexBuf, QOpenGLBuffer indexBuf); void loadChars(); void processText(); void RenderText(std::string text, float x, float y, float scale, glm::vec3 color); bool prepareCoords2(QOpenGLBuffer vertexBuf, QOpenGLBuffer indexBuf); void flipImage(); QString getImage(QImage img); }; #endif //OPENGLHANDLER_H