Click here to Skip to main content
14,326,246 members
Rate this:
Please Sign up or sign in to vote.
Hi, I'm trying to work with multi-texture using SOIL. I think it's a mistake of how I call the texture. I have 2 textures now with 2 different image source (Texture 1 and Texture 2), they look like this :

Texture :
glBindTexture(GL_TEXTURE_2D, textures[0]); 

image1 = SOIL_load_image("res/img1.png",&width,&height,0,SOIL_LOAD_RGBA); 
//"res/img2.png" for image2 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE, image1); 

image 1 for Texture 1 & image 2 for Texture 2.

It’s working, and I can call them by changing between texture. Now I’m trying to change the image source for texture 1 and texture 2 as the same image (img0).

I created function changed(), using input image (img0) then I will do some pixel modification with img0 and store the results as t1 and t2 (both unsigned char). I want to use t1 as source for texture1, and t2 as the source for texture2, so I can call and switch between them later. (the code is pretty long, please let me know if you want me to include them).

What I have tried:

I tried to call the function like this :

 //create texture===================================================== 
GLuint textures[2]; 
glGenTextures(2, textures);   

image = SOIL_load_image("res/img0.png", &width, &height, 0, SOIL_LOAD_RGBA); 
if (image == NULL) exit(0); 
image1 = NULL; //(image1 = t1 later in changed() func.)
image2 = NULL; //(image2 = t2 later in changed() func.)

//Texture 1 
glBindTexture(GL_TEXTURE_2D, textures[0]); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image1); 

//then Texture 2 with image2

But it doesn’t work, no error and no image drawn to the scene. I checked with changing the clear color buffer value, and the color buffer works.So it’s the problem with calling the function and passing my image. Any suggestion ?


I added error handling code to check, like this :
while (!(err = glGetError())) { 		
            cout << "some error message" << err << endl; 	

And turn out the error is after my loading source image code :
image = SOIL_load_image("res/img0.png", &width, &height, 0, SOIL_LOAD_RGBA);

How do I properly load an image using SOIL as a source for a function ?
This is the same way I did it with GLUT and it’s working, is it different with GLFW ?


I replaced error handling with this, and the program is still runing. Not exit, so definitely the image is there.
if (image == NULL) {
		cout << "Error loading image source." << err << endl;

I also tried to print the width and height of the image, and I got the correct result on the console.
cout << width << " x " << height;

But the image isn’t showing. I only need this image to be input of my function, and later my function will generate 2 image result, I will use it as texture 1 and texture 2. Help ?
Updated 26-Nov-18 3:43am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

When you want to change between the images than it would be easier to have a flag which to use. Any load or reload activity is bad for performance.

Stick to the mantra: startup. load and modify only once with all static data.
Member 13987597 22-Nov-18 8:37am
Hi, I can change between texture already.
The problem is different, I want to use the same image to produce different source for each texture.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100