1 | typedef struct { |
1 | typedef struct { |
2 | GLenum mode; |
2 | GLenum mode; |
3 | GLenum format; // GL_T2F_V3F, GL_V2F |
3 | GLenum format; // 0, GL_T2F_V3F, GL_V2F |
4 | GLint texname; |
4 | GLuint texname; |
5 | unsigned char r, g, b, a; |
5 | unsigned char r, g, b, a; |
6 | } rc_key_t; |
6 | } rc_key_t; |
7 | |
7 | |
8 | typedef struct { |
8 | typedef struct { |
9 | HV *hv; |
9 | HV *hv; |
10 | } rc_t; |
10 | } rc_t; |
11 | |
11 | |
12 | typedef SV rc_array_t; |
12 | typedef SV rc_array_t; |
13 | |
13 | |
14 | static rc_t * |
14 | static rc_t * |
15 | rc_alloc () |
15 | rc_alloc (void) |
16 | { |
16 | { |
17 | rc_t *rc = g_slice_new0 (rc_t); |
17 | rc_t *rc = g_slice_new0 (rc_t); |
18 | rc->hv = newHV (); |
18 | rc->hv = newHV (); |
19 | |
19 | |
20 | return rc; |
20 | return rc; |
… | |
… | |
74 | |
74 | |
75 | SvCUR_set (arr, len); |
75 | SvCUR_set (arr, len); |
76 | } |
76 | } |
77 | |
77 | |
78 | static void |
78 | static void |
|
|
79 | rc_glyph (rc_array_t *arr, int u, int v, int w, int h, int x, int y) |
|
|
80 | { |
|
|
81 | if (w && h) |
|
|
82 | { |
|
|
83 | U8 *c; |
|
|
84 | STRLEN len = SvCUR (arr); |
|
|
85 | SvGROW (arr, len + 2 * 2 + 1 * 4); |
|
|
86 | c = (U8 *)SvEND (arr); |
|
|
87 | |
|
|
88 | x += w; |
|
|
89 | y += h; |
|
|
90 | |
|
|
91 | *c++ = u; |
|
|
92 | *c++ = v; |
|
|
93 | *c++ = w; |
|
|
94 | *c++ = h; |
|
|
95 | |
|
|
96 | // use ber-encoding for up to 14 bits (16k) |
|
|
97 | *c = 0x80 | (x >> 7); c += (x >> 7) ? 1 : 0; *c++ = x & 0x7f; |
|
|
98 | *c = 0x80 | (y >> 7); c += (y >> 7) ? 1 : 0; *c++ = y & 0x7f; |
|
|
99 | |
|
|
100 | SvCUR_set (arr, c - (U8 *)SvPVX (arr)); |
|
|
101 | } |
|
|
102 | } |
|
|
103 | |
|
|
104 | static void |
79 | rc_draw (rc_t *rc) |
105 | rc_draw (rc_t *rc) |
80 | { |
106 | { |
81 | HE *he; |
107 | HE *he; |
82 | |
108 | |
83 | hv_iterinit (rc->hv); |
109 | hv_iterinit (rc->hv); |
… | |
… | |
87 | rc_array_t *arr = HeVAL (he); |
113 | rc_array_t *arr = HeVAL (he); |
88 | STRLEN len; |
114 | STRLEN len; |
89 | char *arr_pv = SvPV (arr, len); |
115 | char *arr_pv = SvPV (arr, len); |
90 | GLsizei stride; |
116 | GLsizei stride; |
91 | |
117 | |
92 | stride = key->format == GL_T2F_V3F ? sizeof (float) * 5 |
|
|
93 | : key->format == GL_V2F ? sizeof (float) * 2 |
|
|
94 | : 65536; |
|
|
95 | |
|
|
96 | if (key->texname) |
118 | if (key->texname) |
97 | { |
119 | { |
98 | glBindTexture (GL_TEXTURE_2D, key->texname); |
120 | glBindTexture (GL_TEXTURE_2D, key->texname); |
99 | glEnable (GL_TEXTURE_2D); |
121 | glEnable (GL_TEXTURE_2D); |
100 | } |
122 | } |
101 | else |
123 | else |
102 | glDisable (GL_TEXTURE_2D); |
124 | glDisable (GL_TEXTURE_2D); |
103 | |
125 | |
104 | glColor4ub (key->r, key->g, key->b, key->a); |
126 | glColor4ub (key->r, key->g, key->b, key->a); |
|
|
127 | |
|
|
128 | if (key->format) |
|
|
129 | { |
|
|
130 | stride = key->format == GL_T2F_V3F ? sizeof (float) * 5 |
|
|
131 | : key->format == GL_V2F ? sizeof (float) * 2 |
|
|
132 | : 65536; |
|
|
133 | |
105 | glInterleavedArrays (key->format, 0, (void *)arr_pv); |
134 | glInterleavedArrays (key->format, 0, (void *)arr_pv); |
|
|
135 | //glLockArraysEXT (0, len / stride); |
106 | glDrawArrays (key->mode, 0, len / stride); |
136 | glDrawArrays (key->mode, 0, len / stride); |
|
|
137 | //glUnlockArraysEXT (); |
|
|
138 | } |
|
|
139 | else |
|
|
140 | { |
|
|
141 | // optimised character quad storage. slower but nice on memory. |
|
|
142 | // reduces storage requirements from 80 bytes/char to 6-8 |
|
|
143 | U8 *c = (U8 *)arr_pv; |
|
|
144 | U8 *e = c + len; |
|
|
145 | |
|
|
146 | glBegin (key->mode); // practically must be quads |
|
|
147 | |
|
|
148 | while (c < e) |
|
|
149 | { |
|
|
150 | int u, v, x, y, w, h; |
|
|
151 | |
|
|
152 | u = *c++; |
|
|
153 | v = *c++; |
|
|
154 | w = *c++; |
|
|
155 | h = *c++; |
|
|
156 | |
|
|
157 | x = *c++; if (x > 0x7f) x = ((x & 0x7f) << 7) | *c++; |
|
|
158 | y = *c++; if (y > 0x7f) y = ((y & 0x7f) << 7) | *c++; |
|
|
159 | |
|
|
160 | x -= w; |
|
|
161 | y -= h; |
|
|
162 | |
|
|
163 | glTexCoord2f ( u * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x , y ); |
|
|
164 | glTexCoord2f ((u + w) * (1.f / TC_WIDTH), v * (1.f / TC_HEIGHT)); glVertex2i (x + w, y ); |
|
|
165 | glTexCoord2f ((u + w) * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x + w, y + h); |
|
|
166 | glTexCoord2f ( u * (1.f / TC_WIDTH), (v + h) * (1.f / TC_HEIGHT)); glVertex2i (x , y + h); |
|
|
167 | } |
|
|
168 | |
|
|
169 | glEnd (); |
|
|
170 | } |
107 | } |
171 | } |
108 | |
172 | |
109 | glDisable (GL_TEXTURE_2D); |
173 | glDisable (GL_TEXTURE_2D); |
110 | } |
174 | } |
111 | |
175 | |