39 #include "GL/freeglut.h"
52 static unsigned char kFontData[] = {
71 static std::unique_ptr<GlobalState> s_global_state;
82 static const char kFontName[] =
"ExampleFont";
83 static const size_t kFontSizeInPixels = 64U;
84 static const size_t kSdfPadding = 8U;
86 kFontName, kFontSizeInPixels, kSdfPadding, kFontData,
sizeof(kFontData)));
98 font_image->GetFont()->BuildLayout(
"Hello,\nWorld!", options);
104 outline_builder->SetTextColor(ion::math::Vector4f(1.f, 1.f, .4f, 1.f));
105 outline_builder->SetOutlineColor(ion::math::Vector4f(.1f, .1f, .1f, 1.f));
106 outline_builder->SetHalfSmoothWidth(2.f);
107 outline_builder->SetOutlineWidth(6.f);
108 return outline_builder->GetNode();
119 font_image->GetFont()->BuildLayout(
"Screen-Aligned text", options);
125 outline_builder->SetTextColor(ion::math::Vector4f(1.f, .8f, .8f, 1.f));
126 outline_builder->SetOutlineColor(ion::math::Vector4f(.2f, .2f, .2f, 1.f));
127 outline_builder->SetHalfSmoothWidth(2.f);
128 outline_builder->SetOutlineWidth(6.f);
129 return outline_builder->GetNode();
135 const ion::math::Vector2i window_size(window_width, window_height);
139 state_table->SetViewport(
140 ion::math::Range2i::BuildWithSize(ion::math::Point2i(0, 0), window_size));
141 state_table->SetClearColor(ion::math::Vector4f(0.3f, 0.3f, 0.5f, 1.0f));
142 state_table->SetClearDepthValue(1.f);
145 root->SetStateTable(state_table);
151 "uViewportSize", window_size));
154 static const size_t kFontImageSize = 256U;
166 ion::math::Point3f::Zero(),
167 ion::math::Vector3f::AxisY())));
168 root->AddChild(text_node);
176 root->AddChild(aligned_text_node);
189 static void Resize(
int w,
int h) {
190 s_global_state->window_width = w;
191 s_global_state->window_height = h;
195 static void Render() {
196 if (s_global_state.get())
197 s_global_state->renderer->DrawScene(s_global_state->scene_root);
201 static void Update() {
205 static void Keyboard(
unsigned char key,
int x,
int y) {
209 static void KeyboardUp(
unsigned char key,
int x,
int y) {
212 s_global_state.reset(NULL);
229 int main(
int argc,
char* argv[]) {
230 glutInit(&argc, argv);
232 s_global_state.reset(
new GlobalState);
233 s_global_state->window_width = s_global_state->window_height = 800;
234 s_global_state->scene_root = BuildGraph(s_global_state->window_width,
235 s_global_state->window_height);
237 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
238 glutSetOption(GLUT_MULTISAMPLE, 16);
239 glutInitWindowSize(s_global_state->window_width,
240 s_global_state->window_height);
242 glutCreateWindow(
"Ion rectangle example");
243 glutDisplayFunc(Render);
244 glutReshapeFunc(Resize);
245 glutKeyboardFunc(Keyboard);
246 glutKeyboardUpFunc(KeyboardUp);
247 glutIdleFunc(Update);
GraphicsManager manages the graphics library for an application.
This derived Font class represents a FreeType2 font.
math::Point2f target_point
Location of the text rectangle. (Default: origin)
This struct defines parameters affecting layout of a single text string when passed to BuildLayout()...
ION_API const Matrix< 4, T > LookAtMatrixFromCenter(const Point< 3, T > &eye, const Point< 3, T > ¢er, const Vector< 3, T > &up)
View matrices.
static Matrix Identity()
Returns an identity Matrix.
ION_API const Matrix< 4, T > PerspectiveMatrixFromView(const Angle< T > &fovy, T aspect, T z_near, T z_far)
Returns a 4x4 perspective projection matrix based on the given parameters, which follow the conventio...
math::Vector2f target_size
Target width and height of the text rectangle. (Default: 0 in x, 1 in y)
A Layout instance specifies how glyphs are arranged to form text.
int main(int argc, char *argv[])
Mainline.
OutlineBuilder is a derived Builder class that can render text with outlines.
HorizontalAlignment horizontal_alignment
Text alignment in the horizontal direction. (Default: kAlignLeft)
ION_API const Matrix< 4, T > OrthographicMatrixFromFrustum(T x_left, T x_right, T y_bottom, T y_top, T z_near, T z_far)
Projection matrices.
VerticalAlignment vertical_alignment
Text alignment in the vertical direction. (Default: kAlignBaseline)
float line_spacing
Spacing between baselines of lines of multi-line text, expressed as a fraction of the font's FontMetr...
A StateTable represents a collection of graphical state items that affect OpenGL rendering.
A Node instance represents a node in a scene graph.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
The Renderer class handles rendering ION scene graphs using OpenGL.
DynamicFontImage is a derived FontImage that may contain any number of ImageData instances.