Jump to content
  • Advertisement
Sign in to follow this  
Rui

texture arrays

This topic is 3388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey! here's the problem: i want to load 6 images using devil end put them in a texture array. i guess i could do it one by one, basically repeating the same code 6 times (one for each image), but im trying to do it in a way that uses less lines of code. so here's what i have:
 void load_img_devil () {
	int width, height, format, il_img;
	
	ilInit ();
	iluInit();
	ilutRenderer(ILUT_OPENGL);
	
	for(int i=0;i<6;i++){
		ilGenImages (1, (ILuint*)&il_img); // get an unique ID
		ilBindImage(il_img); // Bind this image name.
		if (i==0) if(!ilLoadImage((const wchar_t *)"F:\\Side1.png")) exit(0); // Load the image
		if (i==1) if(!ilLoadImage((const wchar_t *)"F:\\Side2.png")) exit(0); // Load the image
		if (i==2) if(!ilLoadImage((const wchar_t *)"F:\\Side3.png")) exit(0); // Load the image
		if (i==3) if(!ilLoadImage((const wchar_t *)"F:\\Side4.png")) exit(0); // Load the image
		if (i==4) if(!ilLoadImage((const wchar_t *)"F:\\Side5.png")) exit(0); // Load the image
		if (i==5) if(!ilLoadImage((const wchar_t *)"F:\\Side6.png")) exit(0); // Load the image
		width = ilGetInteger (IL_IMAGE_WIDTH);
		height = ilGetInteger (IL_IMAGE_HEIGHT);
		il_imgData = ilGetData();
		format = ilGetInteger(IL_IMAGE_FORMAT);

		// create GL texture
		glGenTextures (1, (GLuint *)&texID); // get texture unique ID
		glBindTexture (GL_TEXTURE_2D, texID); // bind it
		
		// associate with data read with DevIL
		glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, format,
		GL_UNSIGNED_BYTE, il_imgData);
		
		// Release data space created with DevIL
		ilDeleteImages(1, (const ILuint *)&il_img);
        }
	
	// Parameterise Texture
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}

the thing is.. it doesnt work. to test it i made a square and textured it with texID[0], it appears white; as with any other index. Note 1: texID and il_imgData are global variables; arrays with lenght 6. Note 2: if i open brackets after 'if(i==0)' and close it after the ilDeleteImages call, it works.(for the first image)

Share this post


Link to post
Share on other sites
Advertisement
@DevFred: i can. i dont get any compiler errors or warnings. in fact, that's why i did the cast in the first place, otherwise i'd get a compiler error. plus, if i try to load only one texture, it works. my guess is the problem is somewhere in the loop.

@Zahlman: i'm not sure what you mean but i think it's more or less what DevFred said, so...

Thanks for the replies.

Share this post


Link to post
Share on other sites
That for loop seems like an excellent candidate for a function. Then you can just call it six times, once for each file.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rui
@DevFred: i can. i dont get any compiler errors or warnings. in fact, that's why i did the cast in the first place, otherwise i'd get a compiler error. plus, if i try to load only one texture, it works. my guess is the problem is somewhere in the loop.

@Zahlman: i'm not sure what you mean but i think it's more or less what DevFred said, so...

Thanks for the replies.


No, DevFred is right. you're casting one type of pointer (char*) to (wchar_t* )..
One is an 8-bit ascii string, the other is a 16-bit unicode string, something which is valid C++ (so no compiler error) but in this case it's still a bug.
Use L"F:\\Side1.png" to create a 16-bit unicode string.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rui
@DevFred: i can. i dont get any compiler errors or warnings. in fact, that's why i did the cast in the first place, otherwise i'd get a compiler error. plus, if i try to load only one texture, it works. my guess is the problem is somewhere in the loop.

@Zahlman: i'm not sure what you mean but i think it's more or less what DevFred said, so...

Thanks for the replies.


While casting like that isn't a compiler error, it's a logical error and most likely explains why you're getting untextured triangles.

To use wide character strings use a capital L before the quotation mark.

Share this post


Link to post
Share on other sites
Quote:
Original post by dashurc
While casting like that isn't a compiler error, it's a logical error and most likely explains why you're getting untextured triangles.

Hey, i resent that! ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by Rui
@DevFred: i can. i dont get any compiler errors or warnings. in fact, that's why i did the cast in the first place, otherwise i'd get a compiler error.

So if you give meat to a vegetarian and he complains "I don't like meat", what do you do? Simply tell him "Don't worry, just pretend it's a vegetable"?

Share this post


Link to post
Share on other sites
k, thanks everyone. i see now why that's an error. devfred really put it in perspective for me lol..

but replacing '(const wchar_t*) "F:\\Side1.pgn"' for 'L"Side1.pgn"' made ilLoadImage exit though..

(following erissian's advice it works perfect, with 'const wchar_t*')

any ideas why that might be?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!