From 8b709499993c0590038e440853e6a84b2ff54654 Mon Sep 17 00:00:00 2001 From: Wilrik de Loose Date: Tue, 8 Jan 2008 08:10:41 +0000 Subject: bitmap image glyphs --- Smoke/Week 2.suo | Bin 57344 -> 64000 bytes Smoke/Week 2.vcproj | 10 +- Smoke/arrow.bmp | Bin 0 -> 3126 bytes Smoke/fluids.c | 2 +- Smoke/fluids.h | 3 +- Smoke/renderer_gl.c | 347 +++++++++++++++++++++++++++++++++++++++------------- 6 files changed, 270 insertions(+), 92 deletions(-) create mode 100644 Smoke/arrow.bmp diff --git a/Smoke/Week 2.suo b/Smoke/Week 2.suo index 95f90c5..1203660 100644 Binary files a/Smoke/Week 2.suo and b/Smoke/Week 2.suo 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 @@ /> #include -#include +#include +#include #include @@ -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(); } -- cgit v0.12