Archive for January, 2007

Posted by kent at 31 January 2007

Category: c++

Fungerer ved å spørre klassen etter en gitt texture (static GLuint load(const char *file)), deretter returnerer den en ID (som brukes av glBindTexture()) for å fargelegge objekter og sånt. Er ikke testet 100% og forutsetter at filnavnet eksisterer.

Klassen er 100% statisk og er ikke beregnet på å instansieres.

Bruk, eksempel:

	j1->tex =j2->tex =j3->tex =j4->tex = GLTexture::load("earth.raw");
	sol->tex = GLTexture::load("sol.raw");

Klassekode:

// GLTexture.h
#pragma once

#include <gl/GL.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <io.h>
#include <algorithm>
#include <map>

using namespace std;

static map<const char *, GLuint> bilder;	// texture, id
static Array<const char *> filer;		// filnavn

class GLTexture
{
private:
	// raw texture
	static GLuint LoadTextureRAW( const char * filename )
	{
		GLuint texture;
		int width, height;
		unsigned char * data;
		FILE * file;

		file = fopen( filename, "rb" );
		if ( file == NULL ) return 0;

		width = 1024;
		height = 512;
		data = (unsigned char *)malloc( width * height * 3 );

		fread( data, width * height * 3, 1, file );
		fclose( file );

		glGenTextures( 1, &texture );
		glBindTexture( GL_TEXTURE_2D, texture );
		glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

		gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );

		free( data );

		return texture;
	}

	// bitmap
	static GLuint LoadBitmap(const char *filename)
	{
		int i, j=0; //Index variables
		FILE *l_file; //File pointer
		unsigned char *l_texture; //The pointer to the memory zone in which we will load the texture

		// windows.h gives us these types to work with the Bitmap files
		BITMAPFILEHEADER fileheader;
		BITMAPINFOHEADER infoheader;
		RGBTRIPLE rgb;

		GLuint num_texture; // The counter of the current texture is increased
		glGenTextures( 1, &num_texture );
		if( (l_file = fopen(filename, "rb"))==NULL) return (-1); // Open the file for reading

		fread(&fileheader, sizeof(fileheader), 1, l_file); // Read the fileheader

		fseek(l_file, sizeof(fileheader), SEEK_SET); // Jump the fileheader
		fread(&infoheader, sizeof(infoheader), 1, l_file); // and read the infoheader

		// Now we need to allocate the memory for our image (width * height * color deep)
		l_texture = (byte *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
		// And fill it with zeros
		memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);

		// At this point we can read every pixel of the image
		for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
		{
				// We load an RGB value from the file
				fread(&rgb, sizeof(rgb), 1, l_file);

				// And store it
				l_texture[j+0] = rgb.rgbtRed; // Red component
				l_texture[j+1] = rgb.rgbtGreen; // Green component
				l_texture[j+2] = rgb.rgbtBlue; // Blue component
				l_texture[j+3] = 255; // Alpha value
				j += 4; // Go to the next position
		}

		fclose(l_file); // Closes the file stream

		glBindTexture(GL_TEXTURE_2D, num_texture); // Bind the ID texture specified by the 2nd parameter

		// The next commands sets the texture parameters
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // We don't combine the color with the original surface color, use only the texture map.

		// Finally we define the 2d texture
		glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);

		// And create 2d mipmaps for the minifying function
		gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);

		free(l_texture); // Free the memory we used to load the texture

		return (num_texture); // Returns the current texture OpenGL ID
	}

public:
	static char *earth, *spaceship, *sol;

	GLTexture()
	{}

	static GLuint load(const char *file)
	{
		int size = bilder.size();

		for (int i=0; i<size; i++)
		{
			if (!strcmpi(file, filer[i]))
			{
				file = filer[i];
				i=size;
			}

		}

		GLuint id = bilder[file];

		if (id == 0)
		{
			// load texture
			const char *ext = strrchr(file, '.');
			if (ext == NULL) { ext = file; } else { ext++; }

			if (!strcmpi(ext,"raw"))
			{
				id = LoadTextureRAW(file);
			}

			if (!strcmpi(ext,"bmp"))
			{
				id = LoadBitmap(file);
			}

			bilder[file] = id;
			filer.add(file);
		}

		return bilder[file];
	}
};
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 31 January 2007

Category: c++

	void rem (int i)
	{
		data.erase(data.begin()+i);
	}
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 22 January 2007

Category: Interessant

Enten dør det av råte eller så forsvinner det opp i røyk, begge er nært forestående.

Tørketromlene er roten til begge problemene. Den innerste trommelen brenner snart opp pga. feil med motoren (den starter, men stopper etterhvert selv om varmeelementene går).

Den andre grunnen er at tørketromlene spyr ut vanndampen rett i rommet. Rørene som skal lede vanndampen _ut_ er ikke helt “som ny”.

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share

Posted by kent at 21 January 2007

Category: Uncategorized

Interface: 158.39.125.152 --- 0x8
Internet Address      Physical Address      Type
158.39.124.1          00-40-d0-7b-1a-4e     dynamic
158.39.124.3          00-e0-18-e9-0e-1f     dynamic
158.39.124.10         00-16-35-f4-81-c9     dynamic
158.39.124.144        00-15-f2-a0-f3-7a     dynamic
158.39.124.183        00-00-e8-50-86-66     dynamic
158.39.124.192        00-0c-6e-9d-ab-49     dynamic
158.39.125.11         00-40-d0-7b-1a-4e     dynamic
158.39.125.14         00-16-17-46-0f-c2     dynamic
158.39.125.18         00-c0-9f-eb-71-a1     dynamic
158.39.125.22         00-40-d0-7b-1a-4e     dynamic
158.39.125.25         00-40-d0-7b-1a-4e     dynamic
158.39.125.111        00-40-d0-7b-1a-4e     dynamic
158.39.125.127        00-40-d0-7b-1a-4e     dynamic
158.39.125.255        ff-ff-ff-ff-ff-ff     static
224.0.0.2             01-00-5e-00-00-02     static
224.0.0.22            01-00-5e-00-00-16     static
Interface: 158.39.125.152 --- 0x8
Internet Address      Physical Address      Type
158.39.124.1          00-11-bc-94-a8-00     dynamic
158.39.124.3          00-e0-18-e9-0e-1f     dynamic
158.39.124.10         00-16-35-f4-81-c9     dynamic
158.39.124.144        00-15-f2-a0-f3-7a     dynamic
158.39.124.183        00-00-e8-50-86-66     dynamic
158.39.124.192        00-0c-6e-9d-ab-49     dynamic
158.39.125.11         00-40-d0-7b-1a-4e     dynamic
158.39.125.14         00-16-17-46-0f-c2     dynamic
158.39.125.18         00-c0-9f-eb-71-a1     dynamic
158.39.125.22         00-40-d0-7b-1a-4e     dynamic
158.39.125.25         00-40-d0-7b-1a-4e     dynamic
158.39.125.111        00-40-d0-7b-1a-4e     dynamic
158.39.125.127        00-40-d0-7b-1a-4e     dynamic
158.39.125.255        ff-ff-ff-ff-ff-ff     static
224.0.0.2             01-00-5e-00-00-02     static
224.0.0.22            01-00-5e-00-00-16     static

Interface: 158.39.125.152 --- 0x8
Internet Address      Physical Address      Type
158.39.124.1          00-11-bc-94-a8-00     dynamic
158.39.124.3          00-e0-18-e9-0e-1f     dynamic
158.39.124.183        00-00-e8-50-86-66     dynamic
158.39.124.192        00-0c-6e-9d-ab-49     dynamic
158.39.125.18         00-40-d0-7b-1a-4e     dynamic
158.39.125.111        00-40-d0-7b-1a-4e     dynamic
158.39.125.255        ff-ff-ff-ff-ff-ff     static
VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
Share