Skip to main content
gamedev.net
🔒 Locked

Texture binding in DevIL

Started by MindCode 5 replies 2.6k views
Original Post
MindCode
MindCode
Not really an OpenGL question but imagelib.org seems to be down, and I really need some help.

int main(int argc, char *argv[]) {

	ilInit();

	iluInit();

	ilEnable(IL_FILE_OVERWRITE);


	ILuint image[4];

	ilGenImages(4, ℑ[0]);


	ilBindImage(image[0]);

	ilLoadImage("Grass.bmp");

	ilBindImage(image[1]);

	ilLoadImage("Dessert.bmp");

	ilBindImage(image[2]);

	ilLoadImage("Leaves.bmp");

	ilBindImage(image[3]);

	ilLoadImage("Water.bmp");


	ilBindImage(image[0]);


	ilDeleteImages(4, ℑ[0]);


	return 0;
}
 
This is the EXACT code I compiled. The program stalls. If I remove the second binding of image[0] the program begins and ends without flaw. There''s something about the seconde binding that fucks up the program. Is it a DevIL bug, or am I doing something wrong?
That's just my understanding; I could be wrong.
krumms
krumms
Hi there,

it''s been a while since I''ve looked at DevIL, and I don''t know why that would crash it, but you''ve pretty much answered your own question:

why do you ilBindImage( image[0] ) when you''re just going to delete all the images you''ve loaded immediately afterwards? Leave out the second ilBindImage( image[0] ) call. You don''t need it - as you can see from the code, ilDeleteImages takes a pointer to the beginning of the images, so the image doesn''t need to be bound.

That said, it sounds kinda strange that it would stall - perhaps a silly bug in their code. Maybe check the list of bugs for DevIL and if you can''t find anything, get in contact with the developers.

Tom L
refrain_from_stupidity( &me );
Thunder_Hawk
Thunder_Hawk
quote:
Original post by MindCode
imagelib.org seems to be down

It seems fine to me...
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
zedzeek
zedzeek
been a long time since i used it but IIRC ilBindTexture doesnt actually bind the texture for use with opengl u still have to use glBindTexture( GL_...)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
MindCode
MindCode
quote:
Leave out the second ilBindImage( image[0] ) call. You don't need it


Originally there was a plenty of stuff after that, I just cut code away until I determined that was the problem.

Now that imagelib.org is up I'll give it another shot.


Just found out that this works. Go figure ???


int main(int argc, char *argv[]) {

ilInit();

iluInit();

ilEnable(IL_FILE_OVERWRITE);

ILuint image1,image2,image3,image4;

image1 = iluGenImage();
image2 = iluGenImage();
image3 = iluGenImage();
image4 = iluGenImage();

ilBindImage(image1);
ilLoadImage("Grass.bmp");
ilBindImage(image2);
ilLoadImage("Dessert.bmp");
ilBindImage(image3);
ilLoadImage("Leaves.bmp");
ilBindImage(image4);
ilLoadImage("Water.bmp");

ilBindImage(image1);

iluDeleteImage(image1);
iluDeleteImage(image2);
iluDeleteImage(image3);
iluDeleteImage(image4);

return 0;
}


[edited by - MindCode on October 28, 2002 12:47:01 PM]
That's just my understanding; I could be wrong.
MindCode
MindCode
Here''s what I''m doing. The whole shebang.


void AddAlphaChannel(float fAlpha1, float fAlpha2, float fAlpha3, float fAlpha4) {

ILint iWidth = ilGetInteger(IL_IMAGE_WIDTH);
ILint iHeight = ilGetInteger(IL_IMAGE_HEIGHT);

ILubyte *pData = ilGetData();

ILubyte *pAlpha = new ILubyte[iWidth*iHeight*4];

ILubyte *pBuf = pAlpha;



float fMinDelta = fAlpha4 - fAlpha1;
float fMaxDelta = fAlpha3 - fAlpha2;

float fMinInc = fMinDelta / float(iHeight);
float fMaxInc = fMaxDelta / float(iHeight);

float fMin = fAlpha1;
float fMax = fAlpha2;


for(int y = 0; y < iHeight; y++) {


float fDx = fMax - fMin;

float fInc = fDx / float(iWidth);

float fAlpha = fMin;

fMin += fMinInc;
fMax += fMaxInc;


for(int x = 0; x < iWidth; x++) {

float K = fAlpha * 255.f;

pBuf[0] = pData[2];
pBuf[1] = pData[1];
pBuf[2] = pData[0];
pBuf[3] = ILubyte(K);

fAlpha += fInc;

pBuf += 4;
pData += 3;
}
}


ilTexImage(iWidth, iHeight, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, pAlpha);
}



void BlendTextures(ILuint ILimage1, ILuint ILimage2, ILuint ILimage3, ILuint ILimage4) {

ilBindImage(ILimage1);

AddAlphaChannel(1.f, 0.f, 0.f, 0.f);

ilBindImage(ILimage2);

AddAlphaChannel(0.f, 1.f, 0.f, 0.f);

ilBindImage(ILimage3);

AddAlphaChannel(0.f, 0.f, 1.f, 0.f);

ilBindImage(ILimage4);

AddAlphaChannel(0.f, 0.f, 0.f, 1.f);


ILuint ILblend;

ILblend = iluGenImage();

ilTexImage(128, 128, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL);

ilOverlayImage(ILimage1, 0, 0, 0);
ilOverlayImage(ILimage2, 0, 0, 0);
ilOverlayImage(ILimage3, 0, 0, 0);
ilOverlayImage(ILimage4, 0, 0, 0);

ilSaveImage("Test.bmp");

iluDeleteImage(ILblend);
}



int main(int argc, char *argv[]) {

ilInit();
iluInit();
ilEnable(IL_FILE_OVERWRITE);

ILuint image1,image2,image3,image4;

image1 = iluGenImage();
image2 = iluGenImage();
image3 = iluGenImage();
image4 = iluGenImage();

ilBindImage(image1);
ilLoadImage("Grass.bmp");
ilBindImage(image2);
ilLoadImage("Dessert.bmp");
ilBindImage(image3);
ilLoadImage("Leaves.bmp");
ilBindImage(image4);
ilLoadImage("Water.bmp");

BlendTextures(image1,image2,image3,image4);

iluDeleteImage(image1);
iluDeleteImage(image2);
iluDeleteImage(image3);
iluDeleteImage(image4);

return 0;
}


I solved my original problem by using the ilu gen/delete rather than the il gen/delete, but now I have a new problem. The program stalls in the function BlendTextures. Specifically it stalls on the first ilOverlayImage call. I don''t know why.
That's just my understanding; I could be wrong.
MindCode
MindCode
Here''s what I''m doing. The whole shebang.


void AddAlphaChannel(float fAlpha1, float fAlpha2, float fAlpha3, float fAlpha4) {

ILint iWidth = ilGetInteger(IL_IMAGE_WIDTH);
ILint iHeight = ilGetInteger(IL_IMAGE_HEIGHT);

ILubyte *pData = ilGetData();

ILubyte *pAlpha = new ILubyte[iWidth*iHeight*4];

ILubyte *pBuf = pAlpha;



float fMinDelta = fAlpha4 - fAlpha1;
float fMaxDelta = fAlpha3 - fAlpha2;

float fMinInc = fMinDelta / float(iHeight);
float fMaxInc = fMaxDelta / float(iHeight);

float fMin = fAlpha1;
float fMax = fAlpha2;


for(int y = 0; y < iHeight; y++) {


float fDx = fMax - fMin;

float fInc = fDx / float(iWidth);

float fAlpha = fMin;

fMin += fMinInc;
fMax += fMaxInc;


for(int x = 0; x < iWidth; x++) {

float K = fAlpha * 255.f;

pBuf[0] = pData[2];
pBuf[1] = pData[1];
pBuf[2] = pData[0];
pBuf[3] = ILubyte(K);

fAlpha += fInc;

pBuf += 4;
pData += 3;
}
}


ilTexImage(iWidth, iHeight, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, pAlpha);
}



void BlendTextures(ILuint ILimage1, ILuint ILimage2, ILuint ILimage3, ILuint ILimage4) {

ilBindImage(ILimage1);

AddAlphaChannel(1.f, 0.f, 0.f, 0.f);

ilBindImage(ILimage2);

AddAlphaChannel(0.f, 1.f, 0.f, 0.f);

ilBindImage(ILimage3);

AddAlphaChannel(0.f, 0.f, 1.f, 0.f);

ilBindImage(ILimage4);

AddAlphaChannel(0.f, 0.f, 0.f, 1.f);


ILuint ILblend;

ILblend = iluGenImage();

ilTexImage(128, 128, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, NULL);

ilOverlayImage(ILimage1, 0, 0, 0);
ilOverlayImage(ILimage2, 0, 0, 0);
ilOverlayImage(ILimage3, 0, 0, 0);
ilOverlayImage(ILimage4, 0, 0, 0);

ilSaveImage("Test.bmp");

iluDeleteImage(ILblend);
}



int main(int argc, char *argv[]) {

ilInit();
iluInit();
ilEnable(IL_FILE_OVERWRITE);

ILuint image1,image2,image3,image4;

image1 = iluGenImage();
image2 = iluGenImage();
image3 = iluGenImage();
image4 = iluGenImage();

ilBindImage(image1);
ilLoadImage("Grass.bmp");
ilBindImage(image2);
ilLoadImage("Dessert.bmp");
ilBindImage(image3);
ilLoadImage("Leaves.bmp");
ilBindImage(image4);
ilLoadImage("Water.bmp");

BlendTextures(image1,image2,image3,image4);

iluDeleteImage(image1);
iluDeleteImage(image2);
iluDeleteImage(image3);
iluDeleteImage(image4);

return 0;
}


I solved my original problem by using the ilu gen/delete rather than the il gen/delete, but now I have a new problem. The program stalls in the function BlendTextures. Specifically it stalls on the first ilOverlayImage call. I don''t know why.
That's just my understanding; I could be wrong.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.