Help with Modern OpenGL Call Function to create Texture ?

OpenGL C++ Beginners
  • pixie_laluna
    Likes 0

    Problem Description

    Hi, I’m following your Modern OpenGL tutorial and I tried to make multi-texture using SOIL. I have 2 textures now with 2 different image source, something like this
    Texture 1:

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, textures[0]);
    (...)
    image1 = SOIL_load_image("res/img1.png", &width, &height, 0, SOIL_LOAD_RGBA);​ //"img2.png" for image2
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,image1);
    SOIL_free_image_data(image1);

    It’s working, and I can call them by changing between texture. Now I want to use single image from SOIL as an input for my color-processig function, and store the result as texture 1 and 2. 

    I created function changed(), using input image (img0) I will do some pixel modification store the results as t1 and t2 (both unsigned char). I want to use t1 as source for texture1, and t2 as 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).

    I tried to call the 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;
    image2 = NULL;
    changed();
    
    //Texture 1
    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);
    
    //then Texture 2 using 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 ?

    [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 ?

     


Login to reply