mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Fixing test code
This commit is contained in:
parent
ae10d58142
commit
e6e9f017c0
1 changed files with 9 additions and 52 deletions
|
@ -8,7 +8,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "TextRenderer.h"
|
#include <gpu/GPUConfig.h>
|
||||||
|
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ class QTestWindow : public QWindow {
|
||||||
|
|
||||||
QOpenGLContext* _context{ nullptr };
|
QOpenGLContext* _context{ nullptr };
|
||||||
QSize _size;
|
QSize _size;
|
||||||
TextRenderer* _textRenderer[4];
|
//TextRenderer* _textRenderer[4];
|
||||||
RateCounter fps;
|
RateCounter fps;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -146,12 +147,12 @@ public:
|
||||||
glGetError();
|
glGetError();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false);
|
//_textRenderer[0] = TextRenderer::getInstance(SANS_FONT_FAMILY, 12, false);
|
||||||
_textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false,
|
//_textRenderer[1] = TextRenderer::getInstance(SERIF_FONT_FAMILY, 12, false,
|
||||||
TextRenderer::SHADOW_EFFECT);
|
// TextRenderer::SHADOW_EFFECT);
|
||||||
_textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1,
|
//_textRenderer[2] = TextRenderer::getInstance(MONO_FONT_FAMILY, 48, -1,
|
||||||
false, TextRenderer::OUTLINE_EFFECT);
|
// false, TextRenderer::OUTLINE_EFFECT);
|
||||||
_textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24);
|
//_textRenderer[3] = TextRenderer::getInstance(INCONSOLATA_FONT_FAMILY, 24);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
@ -190,48 +191,6 @@ static const glm::uvec2 QUAD_OFFSET(10, 10);
|
||||||
static const glm::vec3 COLORS[4] = { { 1.0, 1.0, 1.0 }, { 0.5, 1.0, 0.5 }, {
|
static const glm::vec3 COLORS[4] = { { 1.0, 1.0, 1.0 }, { 0.5, 1.0, 0.5 }, {
|
||||||
1.0, 0.5, 0.5 }, { 0.5, 0.5, 1.0 } };
|
1.0, 0.5, 0.5 }, { 0.5, 0.5, 1.0 } };
|
||||||
|
|
||||||
void QTestWindow::renderText() {
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
|
||||||
glLoadIdentity();
|
|
||||||
glOrtho(0, _size.width(), _size.height(), 0, 1, -1);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
const glm::uvec2 size = glm::uvec2(_size.width() / 2, _size.height() / 2);
|
|
||||||
|
|
||||||
const glm::uvec2 offsets[4] = {
|
|
||||||
{ QUAD_OFFSET.x, QUAD_OFFSET.y },
|
|
||||||
{ size.x + QUAD_OFFSET.x, QUAD_OFFSET.y },
|
|
||||||
{ size.x + QUAD_OFFSET.x, size.y + QUAD_OFFSET.y },
|
|
||||||
{ QUAD_OFFSET.x, size.y + QUAD_OFFSET.y },
|
|
||||||
};
|
|
||||||
|
|
||||||
QString str = QString::fromWCharArray(EXAMPLE_TEXT);
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
glm::vec2 bounds = _textRenderer[i]->computeExtent(str);
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glTranslatef(offsets[i].x, offsets[i].y, 0);
|
|
||||||
glColor3f(0, 0, 0);
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
{
|
|
||||||
glVertex2f(0, 0);
|
|
||||||
glVertex2f(0, bounds.y);
|
|
||||||
glVertex2f(bounds.x, bounds.y);
|
|
||||||
glVertex2f(bounds.x, 0);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
const int testCount = 100;
|
|
||||||
for (int j = 0; j < testCount; ++j) {
|
|
||||||
// Draw backgrounds around where the text will appear
|
|
||||||
// Draw the text itself
|
|
||||||
_textRenderer[i]->draw(offsets[i].x, offsets[i].y, str.toLocal8Bit().constData(),
|
|
||||||
glm::vec4(COLORS[i], 1.0f));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QTestWindow::draw() {
|
void QTestWindow::draw() {
|
||||||
if (!isVisible()) {
|
if (!isVisible()) {
|
||||||
|
@ -242,8 +201,6 @@ void QTestWindow::draw() {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio());
|
glViewport(0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio());
|
||||||
|
|
||||||
renderText();
|
|
||||||
|
|
||||||
_context->swapBuffers(this);
|
_context->swapBuffers(this);
|
||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue