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.

55 lines
1.6 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2020. All rights reserved.
* Description: Draw text
* Author:
* Create: 2019-08-23
*/
#ifndef OSD_TEXT_H
#define OSD_TEXT_H
#include <memory>
#include "FontAtlas.h"
#include "FontStyleAtlas.h"
#include "Common.h"
#include "ShaderProgram.h"
namespace dolgles {
constexpr EGL_U32 FONT_STANDARD_WIDTH = 30;
constexpr EGL_U32 FONT_STANDARD_HEIGHT = FONTSIZE_STANDARD + 10;
class OSDText {
public:
OSDText();
~OSDText();
EGL_S32 Init();
EGL_S32 DrawText(const FrameBuffObject &fbo, const GLTextInfo &textInfo, GLfloat x, GLfloat y);
EGL_S32 GetTextSize(const GLTextInfo &textInfo, EGL_U32 &width, EGL_U32 &height) const;
EGL_S32 LoadFont(const std::string &fontLibPath, EGL_U32 fontSize);
private:
bool IsDrawStandardFont(const GLTextInfo &textInfo) const;
void GLDrawText(const std::u16string &text, EGL_U32 textLen, GLfloat x, GLfloat y);
void RenderText(const std::u16string &text, EGL_U32 textLen, GLfloat x, GLfloat y);
EGL_S32 GetFontTex(const FrameBuffObject &fbo, const GLTextInfo &textInfo);
bool FindCharFromMap(EGL_CHAR16 ch) const;
std::unique_ptr<FontAtlas> fontAtlas = nullptr;
std::unique_ptr<FontStyleAtlas> fontStyleAtlas = nullptr;
std::unique_ptr<ShaderProgram> shaderProgram = nullptr;
GLuint program;
GLuint vbo;
GLuint fontTex;
GLuint texWidth;
GLuint texHeight;
GLint uniformTex;
GLint attribCoord;
GLint uniformColor;
GLfloat scaleX;
GLfloat scaleY;
std::map<unsigned long, GlyphInfo> glyphsMap;
};
}; // namespace dolgles
#endif // end OSD_TEXT_H