OpenGL

Maybe sometime in the future I’m able to publish anything useful here.

In the mean time, enjoy this RAW  texture loader.

	static GLuint LoadTextureRAW( const char * filename )
	{
		GLuint texture;
		int width, height;
		unsigned char * data;
		FILE * file;

		file = fopen( filename, "rb" );
		/*if(!file)
		{
			cout << "** FATAL ERROR: Can't open texture\n";
			exit(-1);
		}*/
		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 );
		//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA ,GL_UNSIGNED_BYTE, data+1);

		free( data );

		return texture;
	}

Popularity: 1% [?]

1 Comment

  1. køk says

    Gratulerer med Programmer dagen! (13 september) :) )

    Journalist spør programmer:
    - Hvordan klarte du å lære deg engelsk så fort?
    - Tja…, de tok jo egentlig alle ord fra C++…

Leave a Reply

Leave a Reply
  • (required)
  • (required) (will not be published)