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 :
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
(...)
image1 = SOIL_load_image("res/img1.png",&width,&height,0,SOIL_LOAD_RGBA);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE, image1);
SOIL_free_image_data(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 :
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;
image2 = NULL;
changed();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
(...)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image1);
SOIL_free_image_data(image1);
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 ?
[UPDATE]
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 ?
[UPDATE AGAIN]
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;
exit(0);
}
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 ?