Developer documentation
Version 3.0.3-105-gd3941f44
font.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __gui_opengl_font_h__
18#define __gui_opengl_font_h__
19
20#include "gui/opengl/shader.h"
21
22namespace MR
23{
24 namespace GUI
25 {
26 namespace GL
27 {
28
30 public:
31 Font (const QFont font) :
32 metric (font),
33 font (font) { }
34
35 void initGL (bool with_shadow = true);
36
37 const QFontMetrics metric;
38
39 void start (int width, int height, float red, float green, float blue) const {
40 assert (program);
41 gl::Disable (gl::DEPTH_TEST);
42 gl::DepthMask (gl::FALSE_);
43 gl::Enable (gl::BLEND);
44 gl::BlendEquation (gl::FUNC_ADD);
45 gl::BlendFunc (gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
46 program.start();
47 gl::Uniform1f (gl::GetUniformLocation (program, "scale_x"), 2.0 / width);
48 gl::Uniform1f (gl::GetUniformLocation (program, "scale_y"), 2.0 / height);
49 gl::Uniform1f (gl::GetUniformLocation (program, "red"), red);
50 gl::Uniform1f (gl::GetUniformLocation (program, "green"), green);
51 gl::Uniform1f (gl::GetUniformLocation (program, "blue"), blue);
52 }
53
54 void stop () const {
55 program.stop();
56 gl::DepthMask (gl::TRUE_);
57 gl::Disable (gl::BLEND);
58 }
59
60 void render (const std::string& text, int x, int y) const;
61
62 protected:
63 const QFont font;
69 float font_tex_pos[256], font_tex_width[256];
70 };
71
72
73 }
74 }
75}
76
77#endif
78
79
GL::VertexArrayObject vertex_array_object
Definition: font.h:66
Font(const QFont font)
Definition: font.h:31
void stop() const
Definition: font.h:54
GL::VertexBuffer vertex_buffer[2]
Definition: font.h:65
float font_tex_width[256]
Definition: font.h:69
int font_width[256]
Definition: font.h:68
void initGL(bool with_shadow=true)
void render(const std::string &text, int x, int y) const
void start(int width, int height, float red, float green, float blue) const
Definition: font.h:39
const QFont font
Definition: font.h:63
GL::Shader::Program program
Definition: font.h:67
const QFontMetrics metric
Definition: font.h:37
float font_tex_pos[256]
Definition: font.h:69
GL::Texture tex
Definition: font.h:64
int font_height
Definition: font.h:68
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24