15 #include "dynamicTextGlyph.h" 19 #include "dynamicTextFont.h" 20 #include "dynamicTextPage.h" 21 #include "geomTextGlyph.h" 22 #include "geomVertexData.h" 23 #include "geomVertexFormat.h" 24 #include "geomTriangles.h" 25 #include "geomVertexWriter.h" 26 #include "textureAttrib.h" 27 #include "transparencyAttrib.h" 28 #include "colorAttrib.h" 29 #include "renderState.h" 30 #include "config_gobj.h" 51 unsigned char *DynamicTextGlyph::
53 nassertr(y >= 0 && y < _y_size - _margin * 2, (
unsigned char *)NULL);
54 nassertr(_page != (DynamicTextPage *)NULL, (
unsigned char *)NULL);
62 y = _page->get_y_size() - 1 - y;
64 int offset = (y * _page->get_x_size()) + x;
65 int pixel_width = _page->get_num_components() * _page->get_component_width();
67 return _page->modify_ram_image() + offset * pixel_width;
75 void DynamicTextGlyph::
76 erase(DynamicTextFont *font) {
77 nassertv(_page != (DynamicTextPage *)NULL);
78 nassertv(_page->has_ram_image());
84 _page->fill_region(_x + _margin,
85 _page->get_y_size() - (_y + _y_size - _margin),
86 _x_size - _margin * 2, _y_size - _margin * 2,
100 void DynamicTextGlyph::
101 make_geom(
int bitmap_top,
int bitmap_left, PN_stdfloat advance, PN_stdfloat poly_margin,
102 PN_stdfloat tex_x_size, PN_stdfloat tex_y_size,
103 PN_stdfloat font_pixels_per_unit, PN_stdfloat tex_pixels_per_unit) {
104 nassertv(_page != (DynamicTextPage *)NULL);
107 nassertv(_geom_count == 0);
109 tex_x_size += _margin * 2;
110 tex_y_size += _margin * 2;
113 PN_stdfloat tex_poly_margin = poly_margin / tex_pixels_per_unit;
114 PN_stdfloat origin_y = bitmap_top / font_pixels_per_unit;
115 PN_stdfloat origin_x = bitmap_left / font_pixels_per_unit;
116 _top = origin_y + tex_poly_margin;
117 _left = origin_x - tex_poly_margin;
118 _bottom = origin_y - tex_y_size / tex_pixels_per_unit - tex_poly_margin;
119 _right = origin_x + tex_x_size / tex_pixels_per_unit + tex_poly_margin;
124 _uv_top = 1.0f - ((PN_stdfloat)(_y - poly_margin) + 0.5f) / _page->get_y_size();
125 _uv_left = ((PN_stdfloat)(_x - poly_margin) + 0.5f) / _page->get_x_size();
126 _uv_bottom = 1.0f - ((PN_stdfloat)(_y + poly_margin + tex_y_size) + 0.5f) / _page->get_y_size();
127 _uv_right = ((PN_stdfloat)(_x + poly_margin + tex_x_size) + 0.5f) / _page->get_x_size();
133 (
string(), GeomVertexFormat::get_v3t2(),
140 vertex.add_data3(_left, 0, _top);
141 vertex.add_data3(_left, 0, _bottom);
142 vertex.add_data3(_right, 0, _top);
143 vertex.add_data3(_right, 0, _bottom);
145 texcoord.add_data2(_uv_left, _uv_top);
146 texcoord.add_data2(_uv_left, _uv_bottom);
147 texcoord.add_data2(_uv_right, _uv_top);
148 texcoord.add_data2(_uv_right, _uv_bottom);
151 tris->reserve_num_vertices(6);
155 tris->close_primitive();
159 tris->close_primitive();
162 geom->add_primitive(tris);
167 nassertv(_geom_count == 1);
170 _state = RenderState::make(TextureAttrib::make(_page),
171 TransparencyAttrib::make(TransparencyAttrib::M_alpha));
172 _state = _state->add_attrib(ColorAttrib::make_flat(
LColor(1.0f, 1.0f, 1.0f, 1.0f)), -1);
174 _advance = advance / font_pixels_per_unit;
182 void DynamicTextGlyph::
187 nassertv(_geom_count == 1);
191 geom->add_primitive(prim);
196 nassertv(_geom_count == 1);
209 bool DynamicTextGlyph::
210 is_whitespace()
const {
211 return (_page == (DynamicTextPage *)NULL);
214 #endif // HAVE_FREETYPE This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
bool unclean_set_num_rows(int n)
This method behaves like set_num_rows(), except the new data is not initialized.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
This is the base class for all three-component vectors and points.
Defines a series of disconnected triangles.
TypeHandle is the identifier used to differentiate C++ class types.