You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
2.4 KiB

#ifndef OPENGLHANDLER_H
#define OPENGLHANDLER_H
#include <QtCore>
#include <QImage>
#include <QOpenGLContext>
#include <QOffscreenSurface>
#include <QOpenGLFramebufferObject>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLBuffer>
#include <ft2build.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <QtGui/QOpenGLFunctions_3_3_Core>
#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<char, Character> _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