14 #include "../aux_vis.hpp"
19 template<
typename TVtx>
23 "Invalid vertex type, requires at least TVtx::coord to be present.");
27 glClientActiveTexture(GL_TEXTURE0);
29 glClientActiveTexture(GL_TEXTURE1);
33 template<
typename TVtx>
39 glClientActiveTexture(GL_TEXTURE0);
41 glClientActiveTexture(GL_TEXTURE1);
45 template<
typename TVtx>
46 void FFGLDevice::bufferFFDeviceImpl(
const VertexBuffer<TVtx>& buf)
48 glNewList(disp_lists[buf.getHandle()].list, GL_COMPILE);
50 glDrawArrays(buf.getShape(), 0, buf.count());
52 clearFFVertexArray<TVtx>();
55 template<
typename TVtx>
56 void FFGLDevice::bufferFFDeviceImpl(
const IndexedVertexBuffer<TVtx>& buf)
58 glNewList(disp_lists[buf.getHandle()].list, GL_COMPILE);
60 glDrawElements(buf.getShape(), buf.getIndices().size(), GL_UNSIGNED_INT,
61 buf.getIndices().data());
63 clearFFVertexArray<TVtx>();
70 glEnable(GL_NORMALIZE);
71 glShadeModel(GL_SMOOTH);
72 glEnable(GL_COLOR_MATERIAL);
73 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
74 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
80 glActiveTexture(GL_TEXTURE0);
81 glEnable(GL_TEXTURE_2D);
82 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
83 glActiveTexture(GL_TEXTURE1);
84 glEnable(GL_TEXTURE_2D);
87 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
94 glMatrixMode(GL_MODELVIEW);
95 glLoadMatrixf(glm::value_ptr(model_view));
96 glMatrixMode(GL_PROJECTION);
97 glLoadMatrixf(glm::value_ptr(projection));
104 glDisable(GL_LIGHTING);
107 glEnable(GL_LIGHTING);
108 for (
int light_id = 0; light_id < i; light_id++)
110 glEnable(GL_LIGHT0 + light_id);
112 for (
int light_id = i; light_id <
LIGHTS_MAX; light_id++)
114 glDisable(GL_LIGHT0 + light_id);
120 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat.
diffuse.data());
121 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat.
ambient.data());
122 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat.
specular.data());
123 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat.
shininess);
125 GLfloat memis[] = { 0.0, 0.0, 0.0, 1.0 };
126 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, memis);
131 glMatrixMode(GL_MODELVIEW);
134 glLightfv(GL_LIGHT0 + i, GL_POSITION, lt.
position.data());
136 GLfloat lambi[] = { 0.0, 0.0, 0.0, 1.0 };
137 glLightfv(GL_LIGHT0 + i, GL_AMBIENT, lambi);
139 glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, lt.
diffuse.data());
140 glLightfv(GL_LIGHT0 + i, GL_SPECULAR, lt.
specular.data());
146 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, &amb[0]);
151 if (enable) { glEnable(GL_CLIP_PLANE0); }
152 else { glDisable(GL_CLIP_PLANE0); }
157 glClipPlane(GL_CLIP_PLANE0, eqn.data());
164 if (buf.
count() == 0) {
return; }
165 GLuint new_hnd = glGenLists(1);
167 disp_lists.emplace_back(DispListData_{new_hnd, buf.
getShape(), buf.
count(), layout});
195 cerr <<
"WARNING: Unhandled vertex layout " << layout << endl;
203 if (buf.
count() == 0) {
return; }
204 GLuint new_hnd = glGenLists(1);
206 disp_lists.emplace_back(DispListData_{new_hnd, buf.
getShape(), buf.
getIndices().size(), layout});
235 cerr <<
"WARNING: Unhandled vertex layout " << layout << endl;
246 if (hnd == 0) {
return; }
247 if (disp_lists[hnd].count == 0) {
return; }
255 glColor4f(1.f, 1.f, 1.f, 1.f);
261 glNormal3f(0.f, 0.f, 1.f);
263 glCallList(disp_lists[hnd].list);
272 glNormal3f(0.f, 0.f, 1.f);
273 glMultiTexCoord2f(GL_TEXTURE0, 0.f, 0.f);
279 glMatrixMode(GL_MODELVIEW);
283 glTranslatef(0.f, 0.f, -0.005);
284 glMatrixMode(GL_PROJECTION);
287 glm::vec4 pos(e.rx, e.ry, e.rz, 1.0);
296 glTranslatef(pos.x, pos.y, pos.z);
297 float pen_x = e.ox, pen_y = e.oy;
299 for (
char c : e.text)
304 float cur_x = pen_x + g.
bear_x - 1;
305 float cur_y = -pen_y - g.
bear_y - 1;
312 glBegin(GL_TRIANGLE_STRIP);
313 glMultiTexCoord2f(GL_TEXTURE1, g.
tex_x, 0);
314 glVertex2f(cur_x, -cur_y);
315 glMultiTexCoord2f(GL_TEXTURE1, g.
tex_x + g.
w / tex_w, 0);
316 glVertex2f(cur_x + g.
w, -cur_y);
317 glMultiTexCoord2f(GL_TEXTURE1, g.
tex_x, g.
h / tex_h);
318 glVertex2f(cur_x, -cur_y - g.
h);
319 glMultiTexCoord2f(GL_TEXTURE1, g.
tex_x + g.
w / tex_w, g.
h / tex_h);
320 glVertex2f(cur_x + g.
w, -cur_y - g.
h);
325 glMatrixMode(GL_MODELVIEW);
332 if (hnd == 0) {
return; }
333 if (disp_lists[hnd].count == 0) {
return; }
341 fbType = GL_3D_COLOR_TEXTURE;
348 fbType = GL_3D_COLOR;
353 if (disp_lists[hnd].shape == GL_LINES)
356 sizebuf = (disp_lists[hnd].count / 2) + disp_lists[hnd].count * fbStride;
358 else if (disp_lists[hnd].shape == GL_TRIANGLES)
364 sizebuf = (disp_lists[hnd].count / 3) * (2 + fbStride * 4);
368 std::cerr <<
"Warning: unhandled primitive type in FFPrinter::preDraw()" <<
373 vector<float> xfb_buf;
374 xfb_buf.resize(sizebuf);
375 glFeedbackBuffer(sizebuf, fbType, xfb_buf.data());
377 glRenderMode(GL_FEEDBACK);
380 glRenderMode(GL_RENDER);
382 if (glRenderMode(GL_RENDER) < 0)
384 std::cerr <<
"Warning: feedback data exceeded available buffer size" <<
390 while (tok_idx < xfb_buf.size())
392 switch ((GLuint)xfb_buf[tok_idx])
395 case GL_LINE_RESET_TOKEN:
398 glm::vec3 coord0 = glm::make_vec3(&xfb_buf[tok_idx]),
399 coord1 = glm::make_vec3(&xfb_buf[tok_idx + fbStride]);
400 glm::vec4 color0 = glm::make_vec4(&xfb_buf[tok_idx + 3]),
401 color1 = glm::make_vec4(&xfb_buf[tok_idx + 3 + fbStride]);
406 pal.
GetColorFromVal(xfb_buf[tok_idx + 7 + fbStride], glm::value_ptr(color1));
408 cbuf.
lines.emplace_back(coord0, color0);
409 cbuf.
lines.emplace_back(coord1, color1);
410 tok_idx += fbStride * 2;
413 case GL_POLYGON_TOKEN:
415 int n = xfb_buf[tok_idx + 1];
418 glm::vec3 coord0 = glm::make_vec3(&xfb_buf[tok_idx]),
419 coord1 = glm::make_vec3(&xfb_buf[tok_idx + fbStride]);
420 glm::vec4 color0 = glm::make_vec4(&xfb_buf[tok_idx + 3]),
421 color1 = glm::make_vec4(&xfb_buf[tok_idx + 3 + fbStride]);
426 pal.
GetColorFromVal(xfb_buf[tok_idx + 7 + fbStride], glm::value_ptr(color1));
429 for (
int i = 0; i < n-2; i++)
432 int vtxStart = fbStride * (2 + 3*i);
433 glm::vec3 coord2 = glm::make_vec3(&xfb_buf[tok_idx + vtxStart]);
434 glm::vec4 color2 = glm::make_vec4(&xfb_buf[tok_idx + 3 + vtxStart]);
437 pal.
GetColorFromVal(xfb_buf[tok_idx + 7 + vtxStart], glm::value_ptr(color2));
439 cbuf.
triangles.emplace_back(coord0, color0);
440 cbuf.
triangles.emplace_back(coord1, color1);
441 cbuf.
triangles.emplace_back(coord2, color2);
446 tok_idx += n * fbStride;
450 case GL_BITMAP_TOKEN:
451 case GL_DRAW_PIXEL_TOKEN:
452 case GL_COPY_PIXEL_TOKEN:
455 tok_idx += 1 + fbStride;
void setupFFVertexArray(TVtx *buffer)
static void clearLegacy()
virtual void setTransformMatrices(glm::mat4 model_view, glm::mat4 projection)
virtual size_t count() const =0
Gets the number of vertices contained in the buffer.
static void setupLegacy(void *)
std::array< float, 4 > position
std::array< float, 4 > diffuse
void bufferToDevice(array_layout layout, IVertexBuffer &buf) override
void GetColorFromVal(double val, float *rgba)
std::array< float, 4 > ambient
void setTransformMatrices(glm::mat4 model_view, glm::mat4 projection) override
void setClipPlaneEqn(const std::array< double, 4 > &eqn) override
float GetKerning(char cprev, char c)
std::array< float, 4 > specular
void setPointLight(int i, Light lt) override
std::array< float, 4 > diffuse
void drawDeviceBuffer(int hnd) override
std::array< float, 4 > static_color
void setNumLights(int i) override
void setMaterial(Material mat) override
void setHandle(int dev_hnd)
void captureXfbBuffer(PaletteState &pal, CaptureBuffer &cbuf, int hnd) override
std::array< float, 4 > specular
virtual const std::vector< int > & getIndices() const =0
virtual GLenum getShape() const =0
Gets the primitive type contained by the vertex buffer.
const glyph & GetTexChar(char c) const
void setAmbientLight(const std::array< float, 4 > &amb) override
vector< FeedbackVertex > lines
vector< FeedbackVertex > triangles
void clearFFVertexArray()
void setClipPlaneUse(bool enable) override