Ejemplo n.º 1
0
void Texture2::Load(const std::string& filename, bool linear, bool mipmaps)
{
	// bind texture
	Bind();
	// initialize DevIL
	if(!devil_initialized) {
		ilutRenderer(ILUT_OPENGL);
		devil_initialized = true;
	}
	// create image
	ILuint Id;
	ilGenImages(1, &Id);
	ilBindImage(Id);
	// load image from file
	bool success = ilLoadImage(filename.c_str()) == IL_TRUE;
	if(!success) {
		ilDeleteImages(1, &Id); // delete image
		throw std::runtime_error("Failed to load image from file: '" + filename + "'");
	}
	width_ = ilGetInteger(IL_IMAGE_WIDTH);
	height_ = ilGetInteger(IL_IMAGE_HEIGHT);
	// set opengl parameters
	Setup(linear, mipmaps);
	// load current image into current OpenGL texture
	success = ilutGLTexImage(0) == IL_TRUE;
	if(mipmaps) {
		// automagically
		glGenerateMipmap(GL_TEXTURE_2D);
	}
	ilDeleteImages(1, &Id); // delete image
	if(!success) {
		throw std::string("Failed to load image into OpenGL");
	}
}
Ejemplo n.º 2
0
	// Modified from the ilut source file for GLBind
	GLuint BindTexImageWithClampAndFilter(GLint ClampMode, GLint FilterMode)
	{
		GLuint	TexID = 0;
		
		glGenTextures(1, &TexID);
		glBindTexture(GL_TEXTURE_2D, TexID);
		
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, ClampMode);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, ClampMode);
		
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, FilterMode);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, FilterMode);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
		glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
		glPixelStorei(GL_UNPACK_SWAP_BYTES, IL_FALSE);
		
		if (!ilutGLTexImage(0)) 
		{
			glDeleteTextures(1, &TexID);
			return 0;
		}
		
		return TexID;
	}
Ejemplo n.º 3
0
ILboolean ilOgl::Upload(ilImage &Image, ILuint Level)
{
	Image.Bind();
	return ilutGLTexImage(Level);
}
void TransIcelandicExpress::redraw( void ) {	

	static tex_init = 0;	

	
	if (!tex_init) {		

		ilutRenderer( ILUT_OPENGL );

		ilGenImages( 1, &ImageName );

		ilBindImage( ImageName );
		glEnable( GL_TEXTURE_2D );
		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
		if (!ilLoadImage( "ludum48.png" )) {
			printf("Loading image failed\n");
		}

		
		gl_tex_id = ilutGLBindTexImage();
		ilutGLTexImage( 0 );

		tex_init = 1;
	} 

	glBindTexture (GL_TEXTURE_2D, gl_tex_id );

	glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	//glEnable( GL_CULL_FACE );
	glEnable( GL_DEPTH_TEST );

	// 3d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 60.0, 800.0/600.0, 0.05, 100.0 );



	gluLookAt(	player->pos[0]+cameraPos[0], 
				player->pos[1]+cameraPos[1]+c_PlayerHeight, 
				player->pos[2]+cameraPos[2],

				player->pos[0], 
				player->pos[1]+ c_PlayerHeight, 
				player->pos[2],

				0.0, 1.0, 0.0 );
				

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	// apply some of the camera xform to the light just to make
	// it more shiny
	glPushMatrix();
	float viewHead = atan2( cameraPos[2], cameraPos[0] );	
	glRotated( viewHead * SG_RADIANS_TO_DEGREES, 0.0f, 1.0f, 0.0f );
	setupLights();
	glPopMatrix();

	draw3d();

	// 2d part
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();	
	gluOrtho2D( 0, 800, 0, 600 ) ;

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_LIGHTING );
	draw2d();

	SDL_GL_SwapBuffers();

}