All pastes #224780 Raw Edit

Mine

public text v1 · immutable
#224780 ·published 2006-10-27 15:57 UTC
rendered paste body
void Body::Load_Texture(AppTest* app, std::string filename, std::string mat_name ) { 
	csColor* transp;
	iTextureList* texturelist;

	csRef<iEngine> engine = app->GetEngine();
	if (!engine) printf("Star::Load_Texture: Failed to locate iEngine renderer!\n");

	csRef<iGraphics3D> g3d = app->Get_g3d();
	if (!g3d) printf("Body::Load_Image: Failed to locate 3D renderer!\n");

	csRef<iLoader> loader = app->Get_Loader();
	if (!g3d) printf("Body::Load_Image: Failed to locate 3D renderer!\n");

	csRef<iTextureManager> 	texture_manager = g3d->GetTextureManager();
	if (!texture_manager) printf("Body::Load_Image: Failed to load Texture Manager!\n");
	printf("before new File\n");
	csRef<csPhysicalFile> file = new csPhysicalFile( filename.c_str() ,"rb");
	if (!file) printf("Body::Load_Image: Failed to open image file: %s!\n" , filename.c_str() );
	
	csRef<iDataBuffer> buf = file->GetAllData();
	printf("After GetAllData\n");
	//mat_name.c_str()
	csRef<iTextureWrapper> texturewapper = loader->LoadTexture ( "gstar" ,
					buf, CS_TEXTURE_3D, 	texture_manager , true, true, true );

	printf("After create Texturewapper\n");
//	transp = new csColor;
//	transp->Set(1,0,1);
	
	// Create a Texture from a image file on VFS
//	if ( !engine->CreateTexture ( mat_name.c_str() , filename.c_str() , transp , CS_TEXTURE_3D ) ) {
//			printf("Star::Load_Texture: Failed loading Texture %s\n" , filename.c_str() );}

	// Use the texture to create a Material 
//	texturelist = engine->GetTextureList();
//	engine->CreateMaterial ( mat_name.c_str() , texturelist->FindByName(mat_name.c_str())	); 

	iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName (mat_name.c_str()); //mat_name.c_str()
	if ( !mat ) { printf(" Star::Load_Texture: Material %s not found!\n",mat_name.c_str() ); } 

	// Now add the texture to the mesh
	if (!mesh->GetMeshObject ()->SetMaterialWrapper (mat))
				printf ("Body::Load_Texture: Error SetMaterialWrapper failed\n") ;
		
}