diff options
Diffstat (limited to 'Smoke/renderer_gl.c')
-rw-r--r-- | Smoke/renderer_gl.c | 151 |
1 files changed, 92 insertions, 59 deletions
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c index 15cff39..01205fe 100644 --- a/Smoke/renderer_gl.c +++ b/Smoke/renderer_gl.c @@ -111,7 +111,6 @@ static void render_legend(void) glDisable(GL_BLEND); glLoadIdentity(); - glTranslatef(LEGEND_X_POS, LEGEND_Y_POS, LEGEND_Z_POS); for (i = 0; i < winWidth; i++) { @@ -130,60 +129,60 @@ static void render_legend(void) colormap_set_scaling(s); colormap_set_clamping(c); - clamp_scaled_min = colormap_get_clamp_min() *winWidth; - clamp_scaled_max = colormap_get_clamp_max() *winWidth; + clamp_scaled_min = colormap_get_clamp_min() * winWidth; + clamp_scaled_max = colormap_get_clamp_max() * winWidth; - scale_scaled_min = colormap_get_scale_min() *winWidth; - scale_scaled_max = colormap_get_scale_max() *winWidth; + scale_scaled_min = colormap_get_scale_min() * winWidth; + scale_scaled_max = colormap_get_scale_max() * winWidth; glBegin(GL_LINES); if (colormap_get_scaling()) { glColor3f(1, 0, 0); - glVertex2i(scale_scaled_min, winHeight -4); - glVertex2i(scale_scaled_min, winHeight -18); - glVertex2i(scale_scaled_max, winHeight -4); - glVertex2i(scale_scaled_max, winHeight -18); + glVertex2i(scale_scaled_min, winHeight - 4); + glVertex2i(scale_scaled_min, winHeight - 18); + glVertex2i(scale_scaled_max, winHeight - 4); + glVertex2i(scale_scaled_max, winHeight - 18); } if (colormap_get_clamping()) { glColor4f(0.2, 0.2, 0.2, 1.0); - glVertex2i(clamp_scaled_min, winHeight -6); - glVertex2i(clamp_scaled_min, winHeight -18); - glVertex2i(clamp_scaled_max, winHeight -6); - glVertex2i(clamp_scaled_max, winHeight -18); + glVertex2i(clamp_scaled_min, winHeight - 6); + glVertex2i(clamp_scaled_min, winHeight - 18); + glVertex2i(clamp_scaled_max, winHeight - 6); + glVertex2i(clamp_scaled_max, winHeight - 18); } if (!(i %20)) { glColor3f(0.7, 0.7, 0.7); - glVertex2i(i -1, winHeight -6); - glVertex2i(i -1, winHeight -22); - glVertex2i(i, winHeight -6); - glVertex2i(i, winHeight -22); - glVertex2i(i +1, winHeight -6); - glVertex2i(i +1, winHeight -22); + glVertex2i(i -1, winHeight - 6); + glVertex2i(i -1, winHeight - 22); + glVertex2i(i, winHeight - 6); + glVertex2i(i, winHeight - 22); + glVertex2i(i +1, winHeight - 6); + glVertex2i(i +1, winHeight - 22); } else { glColor3f(color.r, color.g, color.b); - glVertex2i(i, winHeight -6); - glVertex2i(i, winHeight -18); + glVertex2i(i, winHeight - 6); + glVertex2i(i, winHeight - 18); } glEnd(); glBegin(GL_TRIANGLES); if (colormap_get_scaling()) { glColor3f(1, 0, 0); - glVertex2i(scale_scaled_min, winHeight -6); - glVertex2i(scale_scaled_min -4, winHeight); - glVertex2i(scale_scaled_min +4, winHeight); - glVertex2i(scale_scaled_max, winHeight -6); - glVertex2i(scale_scaled_max -4, winHeight); - glVertex2i(scale_scaled_max +4, winHeight); + glVertex2i(scale_scaled_min, winHeight - 6); + glVertex2i(scale_scaled_min - 4, winHeight); + glVertex2i(scale_scaled_min + 4, winHeight); + glVertex2i(scale_scaled_max, winHeight - 6); + glVertex2i(scale_scaled_max - 4, winHeight); + glVertex2i(scale_scaled_max + 4, winHeight); } if (colormap_get_clamping()) { glColor3f(0.9, 0.9, 0.9); - glVertex2i(clamp_scaled_min, winHeight -18); - glVertex2i(clamp_scaled_min -4, winHeight -25); - glVertex2i(clamp_scaled_min +4, winHeight -25); - glVertex2i(clamp_scaled_max, winHeight -18); - glVertex2i(clamp_scaled_max -4, winHeight -25); - glVertex2i(clamp_scaled_max +4, winHeight -25); + glVertex2i(clamp_scaled_min, winHeight - 18); + glVertex2i(clamp_scaled_min - 4, winHeight - 25); + glVertex2i(clamp_scaled_min + 4, winHeight - 25); + glVertex2i(clamp_scaled_max, winHeight - 18); + glVertex2i(clamp_scaled_max - 4, winHeight - 25); + glVertex2i(clamp_scaled_max + 4, winHeight - 25); } glEnd(); } @@ -750,8 +749,8 @@ static void render_isolines(void) } // end switch state // draw line - glVertex3i(e1.x, e1.y, e1.z); - glVertex3i(e2.x, e2.y, e2.z); + glVertex3i((GLint)e1.x, (GLint)e1.y, (GLint)e1.z); + glVertex3i((GLint)e2.x, (GLint)e2.y, (GLint)e2.z); } } // end for count glEnd(); @@ -761,10 +760,10 @@ static void render_isolines(void) static void render_streamlines(void) { - int i, j, k, l, idx, DIM; + int i, j, k, l, idx, idx_x, idx_y, DIM; float v; struct point p; - int *frame_history; + fftw_real *frame_history; fftw_real cell_x, cell_y; i = j = k = l = 0; @@ -773,22 +772,26 @@ static void render_streamlines(void) for (i = 0; i < get_cur_seedpoint(); i++) { p = get_seedpoint(i); + + glBegin(GL_LINE_STRIP); - while (j < DIM) + for (j = 0; j < HISTORY_SIZE; j++) { - // frame_history = frame_hist[j]; + frame_history = streamlines_get_history(j); cell_x = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width cell_y = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell heigh - cell_x = round(p.x / cell_x); - cell_y = round(p.y / cell_y); + idx_x = round(p.x / cell_x); + idx_y = round(p.y / cell_y); + + idx = (int)(cell_x * cell_y); - idx = cell_x + (cell_y * DIM) + (j * DIM * DIM); - v = frame_history[idx]; + v = (float)frame_history[idx]; - j++; + glVertex3f(p.x + v, winHeight - p.y, 0.0f - j * 10.0f); } + glEnd(); } } @@ -823,33 +826,33 @@ static void render_flowvis(void) py = hn + (fftw_real)j * hn; idx = (j * DIM) + i; - color = flowvis_get_color(history[idx]); + color = flowvis_get_color((float)history[idx]); glColor4f(color.r, color.g, color.b, color.a); - glVertex2f(px, py); // vertex 1 + glVertex2f((GLfloat)px, (GLfloat)py); // vertex 1 for (i = 0; i < DIM - 1; i++) { px = wn + (fftw_real)i * wn; py = hn + (fftw_real)(j + 1) * hn; idx = ((j + 1) * DIM) + i; - color = flowvis_get_color(history[idx]); + color = flowvis_get_color((float)history[idx]); glColor4f(color.r, color.g, color.b, color.a); - glVertex2f(px, py); // vertex 2 + glVertex2f((GLfloat)px, (GLfloat)py); // vertex 2 px = wn + (fftw_real)(i + 1) * wn; py = hn + (fftw_real)j * hn; idx = (j * DIM) + (i + 1); - color = flowvis_get_color(history[idx]); + color = flowvis_get_color((float)history[idx]); glColor4f(color.r, color.g, color.b, color.a); - glVertex2f(px, py); // vertex 3 + glVertex2f((GLfloat)px, (GLfloat)py); // vertex 3 } px = wn + (fftw_real)(DIM - 1) * wn; py = hn + (fftw_real)(j + 1) * hn; idx = ((j + 1) * DIM) + (DIM - 1); - color = flowvis_get_color(history[idx]); + color = flowvis_get_color((float)history[idx]); glColor4f(color.r, color.g, color.b, color.a); - glVertex2f(px, py); // vertex 4 + glVertex2f((GLfloat)px, (GLfloat)py); // vertex 4 glEnd(); } @@ -963,17 +966,22 @@ void visualize(struct vis_data_arrays *vis_data) glRotatef(y_rot, 0.0f, 1.0f, 0.0f); glRotatef(z_rot, 0.0f, 0.0f, 1.0f); - glTranslatef(-winWidth/2, -winHeight/2, 0.0f); + glTranslatef((GLfloat)(-winWidth / 2), (GLfloat)(-winHeight / 2), 0.0f); if (renderer_render_grid) { render_grid(); } - if (smoke_get_render()) { - render_smoke(); - } - else if (smoke_grid_get_render()) { - render_grid_smoke(); + if (smoke_get_render()) + { + if (smoke_get_sort() == SMOKE_FLUID) + { + render_smoke(); + } + else // SMOKE_GRID + { + render_grid_smoke(); + } } if (isolines_get_render()) { @@ -1004,7 +1012,32 @@ void visualize(struct vis_data_arrays *vis_data) render_streamlines(); - render_legend(); + //create an orthographic projection matrix for rendering the legendbar
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+
+ glLoadIdentity();
+
+ //create an orthographic viewing volume with the same dimensions as the
+ //window in front of the previous viewing volume
+ //from znear = 0.0 to zfar = 1.0
+ glOrtho(0.0, (GLfloat)winWidth, 0.0, (GLfloat)winHeight, 0.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix(); //save the current modelview matrix
+
+ glLoadIdentity();
+
+ //now render the legendbar
+ render_legend();
+
+ //restore the previous modelview matrix
+ glPopMatrix();
+
+ //restore the previous projection matrix
+ glMatrixMode(GL_PROJECTION);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW); glPopMatrix(); } |