summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilrik de Loose <wilrik@wilrik.nl>2008-01-08 08:10:41 (GMT)
committerWilrik de Loose <wilrik@wilrik.nl>2008-01-08 08:10:41 (GMT)
commit8b709499993c0590038e440853e6a84b2ff54654 (patch)
tree061bd9bc349f08149ea569a8580bae9a088c7e1f
parent8dc29e0202fb48c078aebf271b31e903a1076d95 (diff)
download2iv35-8b709499993c0590038e440853e6a84b2ff54654.zip
2iv35-8b709499993c0590038e440853e6a84b2ff54654.tar.gz
2iv35-8b709499993c0590038e440853e6a84b2ff54654.tar.bz2
bitmap image glyphs
-rw-r--r--Smoke/Week 2.suobin57344 -> 64000 bytes
-rw-r--r--Smoke/Week 2.vcproj10
-rw-r--r--Smoke/arrow.bmpbin0 -> 3126 bytes
-rw-r--r--Smoke/fluids.c2
-rw-r--r--Smoke/fluids.h3
-rw-r--r--Smoke/renderer_gl.c347
6 files changed, 270 insertions, 92 deletions
diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo
index 95f90c5..1203660 100644
--- a/Smoke/Week 2.suo
+++ b/Smoke/Week 2.suo
Binary files differ
diff --git a/Smoke/Week 2.vcproj b/Smoke/Week 2.vcproj
index 2c7c4db..92c6134 100644
--- a/Smoke/Week 2.vcproj
+++ b/Smoke/Week 2.vcproj
@@ -63,7 +63,7 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="&quot;gtkglext-win32-1.0.lib gdkglext-win32-1.0.lib glu32.lib opengl32.lib user32.lib kernel32.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gdi32.lib imm32.lib shell32.lib ole32.lib atk-1.0.lib gdk_pixbuf-2.0.lib pangowin32-1.0.lib pangocairo-1.0.lib cairo.lib pangoft2-1.0.lib fontconfig.lib freetype.lib z.lib pango-1.0.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib"
+ AdditionalDependencies="&quot;gtkglext-win32-1.0.lib gdkglext-win32-1.0.lib glu32.lib opengl32.lib user32.lib kernel32.lib gtk-win32-2.0.lib gdk-win32-2.0.lib gdi32.lib imm32.lib shell32.lib ole32.lib atk-1.0.lib gdk_pixbuf-2.0.lib pangowin32-1.0.lib pangocairo-1.0.lib cairo.lib pangoft2-1.0.lib fontconfig.lib freetype.lib z.lib pango-1.0.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib Glaux.lib"
OutputFile="$(OutDir)/Week 2.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="D:\GTK\lib"
@@ -966,19 +966,19 @@
>
</File>
<File
- RelativePath="fftw-2.1.3\fftw\Makefile.am"
+ RelativePath="fftw-2.1.3\rfftw\Makefile.am"
>
</File>
<File
- RelativePath="fftw-2.1.3\rfftw\Makefile.am"
+ RelativePath="fftw-2.1.3\fftw\Makefile.am"
>
</File>
<File
- RelativePath="fftw-2.1.3\rfftw\Makefile.in"
+ RelativePath="fftw-2.1.3\fftw\Makefile.in"
>
</File>
<File
- RelativePath="fftw-2.1.3\fftw\Makefile.in"
+ RelativePath="fftw-2.1.3\rfftw\Makefile.in"
>
</File>
<File
diff --git a/Smoke/arrow.bmp b/Smoke/arrow.bmp
new file mode 100644
index 0000000..eef0be3
--- /dev/null
+++ b/Smoke/arrow.bmp
Binary files differ
diff --git a/Smoke/fluids.c b/Smoke/fluids.c
index eece203..f80a2f0 100644
--- a/Smoke/fluids.c
+++ b/Smoke/fluids.c
@@ -43,7 +43,7 @@ int vis_dataset = DATASET_RHO;
int active_slider = 0;
int glyph_scalar = SCALAR_RHO;
int glyph_vector = VECTOR_VEL;
-int glyph_sort = GLYPH_ARROWS;
+int glyph_sort = GLYPH_BITMAPS;
GLuint startList;
float threshold1 = 0.2f;
float threshold2 = 2.0f;
diff --git a/Smoke/fluids.h b/Smoke/fluids.h
index c042094..4f1fdf6 100644
--- a/Smoke/fluids.h
+++ b/Smoke/fluids.h
@@ -31,7 +31,8 @@ extern int frame_index;
#define GLYPH_ARROWS 0
#define GLYPH_LINES 1
-#define GLYPH_CYLINDERS 2
+#define GLYPH_CONES 2
+#define GLYPH_BITMAPS 3
extern int winWidth, winHeight; //size of the graphics window, in pixels
extern int color_dir; //use direction color-coding or not
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index 1f6b9a4..d84e59c 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -7,7 +7,8 @@
#include <math.h>
#include <GL/gl.h>
-#include <GL/glu.h>
+#include <GL/glu.h>
+#include <gl\glaux.h>
#include <rfftw.h>
@@ -39,11 +40,12 @@
#define MIN_ZOOM -100.0f
#define MAX_ZOOM -4000.0f
-
#define LEGEND_X_POS -298.0f
#define LEGEND_Y_POS -295.0f
#define LEGEND_Z_POS -735.0f
+#define BITMAP_SOURCE "arrow.bmp"
+
float x_pos = DEFAULT_X_POS;
float y_pos = DEFAULT_Y_POS;
float z_pos = DEFAULT_ZOOM;
@@ -52,6 +54,8 @@ static int renderer_grid = FALSE;
static int renderer_zoomspeed = DEFAULT_ZOOM_SPEED;
+GLuint texture[1];
+
static void render_legend(void)
{
int i;
@@ -150,7 +154,7 @@ static void render_normal(void)
DIM = fluids_get_dim();
wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width
hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height
- float normal_scale = 10.0f;
+ float normal_scale = 16.0f;
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
@@ -162,7 +166,7 @@ static void render_normal(void)
{
idx = (j * DIM) + i;
px = wn + (fftw_real)i * wn;
- py = hn + (fftw_real)(j + 1) * hn;
+ py = hn + (fftw_real)(j + 1) * hn;
glVertex3f(px, py, height_array[idx]);
glVertex3f(px + normal_array[idx].x * normal_scale,
@@ -271,6 +275,86 @@ static void render_smoke(void)
}
}
+AUX_RGBImageRec * LoadBmp(char *filename)
+{
+ FILE *file = NULL;
+
+ if (!filename)
+ {
+ return NULL;
+ }
+
+ fopen_s(&file, filename, "r");
+
+ if (file)
+ {
+ fclose(file);
+ return auxDIBImageLoad(filename);
+ }
+
+ return NULL;
+
+} // LoadBMP
+
+
+int LoadTextures(void)
+{
+ int status = TRUE;
+ AUX_RGBImageRec *textureImage[1];
+
+ memset(textureImage, 0, sizeof(void *)*1);
+
+ if (textureImage[0] = LoadBmp(BITMAP_SOURCE))
+ {
+ status = TRUE;
+ glGenTextures(1, &texture[0]); // Create the texture
+
+ // Typical texture generation using data from the bitmap
+ glBindTexture(GL_TEXTURE_2D, texture[0]);
+
+ // Generate The Texture
+ glTexImage2D(GL_TEXTURE_2D, // We're dealing with a 2D texture
+ 0, // Level of detail
+ 3, // Nr of color components (3 for RGB)
+ textureImage[0]->sizeX, // Width of image
+ textureImage[0]->sizeY, // Height of image
+ 0, // Border (left to 0)
+ GL_RGB, // We'll be using RGB colors
+ GL_UNSIGNED_BYTE, // Image is made up of unsigned bytes
+ textureImage[0]->data // The actual data
+ );
+
+ // Create MipMapped texture
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+
+ gluBuild2DMipmaps(GL_TEXTURE_2D,
+ 3,
+ textureImage[0]->sizeX,
+ textureImage[0]->sizeY,
+ GL_RGB,
+ GL_UNSIGNED_BYTE,
+ textureImage[0]->data
+ );
+
+ if (textureImage[0]) // If Texture Exists
+ {
+ if (textureImage[0]->data) // If Texture Image Exists
+ {
+ free(textureImage[0]->data); // Free The Texture Image Memory
+ }
+
+ free(textureImage[0]); // Free The Image Structure
+ }
+ }
+ else
+ {
+ status = FALSE;
+ }
+
+ return status;
+
+} // LoadTextures
static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, float i, float j)
{
@@ -337,7 +421,7 @@ static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, floa
glPopMatrix();
break;
- case GLYPH_CYLINDERS:
+ case GLYPH_CONES:
x_dev = x1 - x0;
y_dev = y1 - y0;
length = quake_root(x_dev * x_dev + y_dev * y_dev) / 16;
@@ -354,6 +438,27 @@ static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, floa
glPopMatrix();
break;
+
+ case GLYPH_BITMAPS:
+ if (size < 0.08f) return;
+
+ glPushMatrix();
+
+ glTranslatef(x0, y0, z0);
+ glRotatef(theta, 0.0, 0.0, 1.0);
+ glTranslatef(-x0, -y0, -z0);
+
+ glBegin(GL_TRIANGLE_STRIP);
+ glTexCoord2f(1, 1); glVertex2d( 20 * size + x0, 20 * size + y0);
+ glTexCoord2f(0, 1); glVertex2d(-20 * size + x0, 20 * size + y0);
+ glTexCoord2f(1, 0); glVertex2d( 20 * size + x0, -20 * size + y0);
+ glTexCoord2f(0, 0); glVertex2d(-20 * size + x0, -20 * size + y0);
+ glEnd();
+
+ glRotatef(-theta, 0.0, 0.0, 1.0);
+
+ glPopMatrix();
+ break;
}
}
@@ -413,6 +518,20 @@ static void render_glyphs(void)
gluDeleteQuadric(qobj);
}
+//#define percentage(h, l, t) ( 1 - ( (t - min(h, l) ) / (max(h, l) - min(h, l) ) ) )
+
+float percentage(float h, float l, float t)
+{
+ float perc, delp, deltp;
+ float min = min(h, l);
+ float max = max(h, l);
+
+ delp = max - min;
+ deltp = t - min;
+ perc = deltp / delp;
+
+ return perc;
+}
static void render_isolines(void)
{
@@ -440,7 +559,10 @@ static void render_isolines(void)
int state = 0;
static int prev_state = 0;
struct color4f color;
- float threshold, max;
+ float threshold;
+
+ static int low = 0;
+ static int hig = 0;
v0 = v1 = v2 = v3 = 0.0f;
x0 = y0 = x1 = y1 = 0.0f;
@@ -448,6 +570,7 @@ static void render_isolines(void)
threshold = min(threshold1, threshold2) + count * iso_scale;
glDisable(GL_LIGHTING);
+ glLineWidth(2.0f);
glBegin(GL_LINES);
for (i = 0; i < DIM - 1; i++)
@@ -470,85 +593,136 @@ static void render_isolines(void)
if (v2 >= threshold) { state += 4; }
if (v3 >= threshold) { state += 8; }
- x_offset = wn + (fftw_real)i * wn;
- y_offset = hn + (fftw_real)j * hn;
-
- switch (state)
+ if (state > 0 && state < 15)
{
- case 5:
- case 10:
- //y0 = 0.5f * hn;
- //x1 = 0.5f * wn;
- x0 = 0;
- y0 = (threshold / max(v3, v0)) * hn;
- x1 = (threshold / max(v1, v0)) * wn;
- y1 = hn;
-
- glVertex3i(x_offset + x0, y_offset + y0, 5.0f);
- glVertex3i(x_offset + x1, y_offset + y1, 5.0f);
- // no break !!
- case 4:
- case 11:
- //x0 = 0.5f * wn;
- //y1 = 0.5f * hn;
- x0 = (threshold / max(v3, v2)) * wn;
- y0 = 0;
- x1 = wn;
- y1 = (threshold / max(v2, v1)) * hn;
- break;
- case 6:
- case 9:
- //x0 = 0.5f * wn;
- //x1 = 0.5f * wn;
- x0 = (threshold / max(v3, v2)) * wn;
- y0 = 0;
- x1 = (threshold / max(v1, v0)) * wn;
- y1 = hn;
- break;
- case 7:
- case 8:
- //x0 = 0.5f * wn;
- //y1 = 0.5f * hn;
- x0 = (threshold / max(v3, v2)) * wn;
- y0 = 0;
- x1 = 0;
- y1 = (threshold / max(v3, v0)) * hn;
- break;
- case 3:
- case 12:
- //y0 = 0.5f * hn;
- //y1 = 0.5f * hn;
- x0 = 0;
- y0 = (threshold / max(v3, v0)) * hn;
- x1 = wn;
- y1 = (threshold / max(v2, v1)) * hn;
- break;
- case 2:
- case 13:
- //x0 = 0.5f * wn;
- //y1 = 0.5f * hn;
- x0 = (threshold / max(v1, v0)) * wn;
- y0 = hn;
- x1 = wn;
- y1 = (threshold / max(v2, v1)) * hn;
- break;
- case 1:
- case 14:
- //y0 = 0.5f * hn;
- //x1 = 0.5f * wn;
- x0 = 0;
- y0 = (threshold / max(v3, v0)) * hn;
- x1 = (threshold / max(v1, v0)) * wn;
- y1 = hn;
- break;
- case 0: case 15: default:
- x0 = y0 = x1 = y1 = 0.0f;
- break;
+ x_offset = wn + (fftw_real)i * wn;
+ y_offset = hn + (fftw_real)j * hn;
+
+ switch (state)
+ {
+ case 1:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+ break;
+
+ case 2:
+ x0 = percentage(v1, v0, threshold, 0) * wn;
+ y0 = hn;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 3:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 4:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 5:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+
+ glVertex3i(x_offset + x0, y_offset + y0, 5.0f);
+ glVertex3i(x_offset + x1, y_offset + y1, 5.0f);
+
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 6:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+ break;
+
+ case 7:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = 0;
+ y1 = percentage(v3, v0, threshold, 0) * hn;
+ break;
+
+ case 8:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = 0;
+ y1 = percentage(v3, v0, threshold, 0) * hn;
+ break;
+
+ case 9:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+ break;
+
+ case 10:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+
+ glVertex3i(x_offset + x0, y_offset + y0, 5.0f);
+ glVertex3i(x_offset + x1, y_offset + y1, 5.0f);
+
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 11:
+ x0 = percentage(v3, v2, threshold, 0) * wn;
+ y0 = 0;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 12:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 13:
+ x0 = percentage(v1, v0, threshold, 0) * wn;
+ y0 = hn;
+ x1 = wn;
+ y1 = percentage(v2, v1, threshold, 0) * hn;
+ break;
+
+ case 14:
+ x0 = 0;
+ y0 = percentage(v3, v0, threshold, 0) * hn;
+ x1 = percentage(v1, v0, threshold, 0) * wn;
+ y1 = hn;
+ break;
+
+ case 0: case 15: default:
+ x0 = y0 = x1 = y1 = 0.0f;
+ break;
+ }
+
+ // draw line
+ glVertex3i(x_offset + x0, y_offset + y0, 5.0f);
+ glVertex3i(x_offset + x1, y_offset + y1, 5.0f);
}
-
- // draw line
- glVertex3i(x_offset + x0, y_offset + y0, 5.0f);
- glVertex3i(x_offset + x1, y_offset + y1, 5.0f);
}
}
@@ -656,9 +830,10 @@ void render_flowvis(void)
void renderer_init_gl(void)
{
float LightAmbient[] = { 0.10f, 0.10f, 0.10f, 1.00f }; // Ambient light values
- float LightDiffuse[] = { 0.40f, 0.40f, 0.40f, 0.00f }; // Diffuse light values
- float LightPosition[] = { -300.0f, -300.0f, -300.0f, 1.00f }; // Position of the light source
+ float LightDiffuse[] = { 0.50f, 0.50f, 0.50f, 0.00f }; // Diffuse light values
+ float LightPosition[] = { -250.0f, -250.0f, -300.0f, 1.00f }; // Position of the light source
+ glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); // Enable smooth shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black background
glClearDepth(1.0f); // Depth buffer setup
@@ -675,6 +850,8 @@ void renderer_init_gl(void)
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
+
+ LoadTextures();
}