summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2008-01-08 15:31:00 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2008-01-08 15:31:00 (GMT)
commitf4183dfb298b22f21cd553e0856d7270ebfae451 (patch)
tree17cda68c849c8b5ab80133d935bd9a8e19b2b8da
parentca385d1f354c71b767fb569860ceac58b90861b4 (diff)
download2iv35-f4183dfb298b22f21cd553e0856d7270ebfae451.zip
2iv35-f4183dfb298b22f21cd553e0856d7270ebfae451.tar.gz
2iv35-f4183dfb298b22f21cd553e0856d7270ebfae451.tar.bz2
removed stupid aux dependancy
-rw-r--r--Smoke/renderer_gl.c166
1 files changed, 67 insertions, 99 deletions
diff --git a/Smoke/renderer_gl.c b/Smoke/renderer_gl.c
index 84f15d6..0e88c5a 100644
--- a/Smoke/renderer_gl.c
+++ b/Smoke/renderer_gl.c
@@ -4,11 +4,11 @@
#include <windows.h>
#endif
+#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
-#include <GL/glu.h>
-#include <gl\glaux.h>
+#include <GL/glu.h>
#include <rfftw.h>
@@ -45,6 +45,10 @@
#define LEGEND_Z_POS -735.0f
#define BITMAP_SOURCE "arrow.bmp"
+#define BITMAP_OFFSET 0x0a
+#define BITMAP_HEADERSIZE 0x0e
+#define BITMAP_WIDTH 0x12
+#define BITMAP_HEIGHT 0x16
float x_pos = DEFAULT_X_POS;
float y_pos = DEFAULT_Y_POS;
@@ -54,7 +58,8 @@ static int renderer_grid = FALSE;
static int renderer_zoomspeed = DEFAULT_ZOOM_SPEED;
-GLuint texture[1];
+static GLuint texture;
+
static void render_legend(void)
{
@@ -275,88 +280,51 @@ 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;
- }
-
- glBindTexture(GL_TEXTURE_2D, NULL);
-
- return status;
-
-} // LoadTextures
+
+GLuint LoadTextures(char *filename)
+{
+ GLuint return_value;
+ FILE *bitmap;
+
+ return_value = 0;
+
+ bitmap = fopen(filename, "rb");
+ if (bitmap) {
+ size_t filesize;
+ unsigned int dataoffset;
+ GLsizei width, height;
+ unsigned char *imagedata;
+
+ fseek(bitmap, 0, SEEK_END);
+ filesize = ftell(bitmap);
+ fseek(bitmap, BITMAP_OFFSET, SEEK_SET);
+ fread(&dataoffset, 4, 1, bitmap);
+/* fseek(bitmap, BITMAP_HEADERSIZE, SEEK_SET); */
+/* fread(&headersize, 4, 1, bitmap); */
+ fseek(bitmap, BITMAP_WIDTH, SEEK_SET);
+ fread(&width, 4, 1, bitmap);
+/* fseek(bitmap, BITMAP_HEIGHT, SEEK_SET); */
+ fread(&height, 4, 1, bitmap);
+
+ imagedata = (unsigned char *)malloc((filesize -dataoffset) /* *(char *) */);
+
+ fseek(bitmap, dataoffset, SEEK_SET);
+ fread(imagedata, (filesize -dataoffset), 1, bitmap);
+
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+// gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_BGR, GL_UNSIGNED_BYTE, imagedata);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ free(imagedata);
+ }
+
+ fclose(bitmap);
+
+ return return_value;
+}
+
static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, float i, float j)
{
@@ -446,7 +414,7 @@ static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, floa
glPushMatrix();
- glBindTexture(GL_TEXTURE_2D, texture[0]);
+ glBindTexture(GL_TEXTURE_2D, texture);
glTranslatef(x0, y0, z0);
glRotatef(theta, 0.0, 0.0, 1.0);
glTranslatef(-x0, -y0, -z0);
@@ -459,7 +427,7 @@ static void render_glyph(GLUquadricObj *qobj, float x_value, float y_value, floa
glEnd();
glRotatef(-theta, 0.0, 0.0, 1.0);
- glBindTexture(GL_TEXTURE_2D, NULL);
+ glBindTexture(GL_TEXTURE_2D, 0);
glPopMatrix();
break;
@@ -524,17 +492,17 @@ static void render_glyphs(void)
//#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;
+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)
@@ -858,7 +826,7 @@ void renderer_init_gl(void)
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
- LoadTextures();
+ texture = LoadTextures(BITMAP_SOURCE);
}