Sign in to follow this  

using devil to copy part of one texture to a second texture

Recommended Posts

Hi all
I need to pre process some textures before I use them. Basically I'm using devil to load the the source texture, then create a second texture on the fly and copy a section of the source texture using ilBlit, to test I output the image as a bitmap. The problem is the bitmap comes out as the right shape and size but is blank, no copied image. I'm really unsure what I'm doing wrong. I should add iloverlayimage dose not work but ilCopy does, though obviouslky wrong , that is it copies the whole image over.
Can anyone tell me what I'm doing wrong with ilBlit in my code? Thanks!

void LoadAnimationImages( VIDEO_ANIMATION *anim, string filename )
ILuint image,blankimage;

/*generate buffer*/
ilGenImages( 1, &image );
/*bind image to buffer*/
ilBindImage( image );
/*load the texture*/
if( !ilLoadImage( filename.c_str() ) )
printf( "\n falied to load texture \n ");

/*get height and with of pixels*/
int pixels_width = ( ilGetInteger( IL_IMAGE_WIDTH ) / GetNumberOfAnimations( anim ) ) * GetFramesUsed( anim ) ;
int pixels_hight = ilGetInteger( IL_IMAGE_HEIGHT );
int bpp = ilGetInteger(IL_IMAGE_BPP);
ILint format = ilGetInteger(IL_IMAGE_FORMAT);
ILint depth = ilGetInteger(IL_IMAGE_DEPTH);
ILint type = ilGetInteger(IL_IMAGE_TYPE);

printf( "\n width %d height %d depth %d \n",pixels_width,pixels_hight, depth );

/**********************create a blank image*********************/
/*generate buffer*/
ilGenImages( 1, &blankimage );
/*bind image to buffer*/
ilBindImage( blankimage );
/* create a new image */
ilTexImage( pixels_width, pixels_hight, depth, bpp, format, type, (void*)NULL );

/*copy some data from main image to reel vector data*/
[b]ilBlit( blankimage, 0,0,depth, 0,0,depth, 128,128,depth ); //to dest x,y,z, from source x,y,z, width height depilth,[/b]

//ilOverlayImage( image, 100,100,depth ); does not work
//ilCopy( image ) will work

/*test to maked sure image is copied*/
ilSaveImage("test.bmp"); //test image comes out right size etc but with no image eg just black?




Share this post

Link to post
Share on other sites
(FYI OpenIL isn't part of OpenGL, so not really the right forum section).

The problem you are having is that you are binding the blank image but also passing it as the source parameter to ilBlit. ilBlit blits from the source image provided by the first parameter, to the currently bound image. OpenIL is highly stateful in the same way OpenGL is. When you bind an object as a target, all calls relating to that target apply to the object bound. So ilBindImage(image) means that all OpenIL operations that target an image from that point (until you bind another image) will effect the specified image. That is why ilBlit only takes a single image parameter (source) although you might expect it to take two (source and destination). The destination is the currently bound image.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this