Results 1 to 3 of 3

Thread: Texture loaded with SOIL isn't displayed

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    8

    Texture loaded with SOIL isn't displayed

    Here's the thing: I don't get any SOIL or OpenGL errors, and yet the image I load isn't displayed.

    Texture load & draw code:
    Code :
    // textures is std::map<std::string, GLuint>
    if (textures.find(imagepath)==textures.end())
        {
        textures[imagepath] = SOIL_load_OGL_texture(imagepath.c_str(),
                                                    SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,0);
        owner->setdbgstr("loading texture...");
        }
    else if(textures[imagepath]!=0)
        {
            owner->setdbgstr("texture is loaded successfully");
     
            oglImage(textures[imagepath]);
     
            std::string error = "toll!";
            GLenum laste = GL_NO_ERROR;
            while(true)
            {
                GLenum err = glGetError();
                if ( err == GL_NO_ERROR )
                    break;
                if ( err == laste )
                {
                    errr = "Error with glGetError()";
                    break;
                }
                laste = err;
                error = "OpenGL error: "+std::to_string(err);
            }
            owner->setdbgstr(error);
        }
    else
        {
        owner->setdbgstr("Error loading image: " + std::string(SOIL_last_result(),0,3));
        }

    oglImage:
    Code :
    void oglImage(GLuint gluimage)
    {
        double ww, hh;
        ww=100.0;
        hh=100.0;
        double r = 1.0, g = 1.0, b = 1.0, a = 1.0;
        double points[] =
        {
            0.0, 0.0,   r, g, b, a, 0.0, 0.0,
            0.0,  hh,   r, g, b, a, 0.0, 1.0,
             ww,  hh,   r, g, b, a, 1.0, 1.0,
             ww, 0.0,   r, g, b, a, 1.0, 0.0
        };
        GLuint vbo;
        glGenBuffersARB(1, &vbo);
        glBindBufferARB(GL_ARRAY_BUFFER, vbo);
        glBufferDataARB(GL_ARRAY_BUFFER,4 * sizeof(double) * 8,&points[0],GL_STATIC_DRAW);
     
        glEnable(GL_TEXTURE_2D);
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
     
        glBindTexture(GL_TEXTURE_2D, gluimage);
     
        glBindBufferARB(GL_ARRAY_BUFFER, vbo);
        glVertexPointer(2, GL_DOUBLE, sizeof(double) * 8, NULL);
        glTexCoordPointer(2, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*6));
        glDrawArrays(GL_QUADS, 0, 4);
        //glFlush() is called later down the line, other gl elements are drawn just fine
     
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisable(GL_TEXTURE_2D);
    }

    Another version of oglImage, only draws a white square:
    Code :
    void oglImage(GLuint gluimage)
    {
        double ww, hh;
        ww=100.0;
        hh=100.0;
        double r = 1.0, g = 1.0, b = 1.0, a = 1.0;
        double points[] =
        {
            0.0, 0.0,   r, g, b, a, 0.0, 0.0,
            0.0,  hh,   r, g, b, a, 0.0, 1.0,
             ww,  hh,   r, g, b, a, 1.0, 1.0,
             ww, 0.0,   r, g, b, a, 1.0, 0.0
        };
     
        GLuint vao;
        glGenVertexArraysAPPLE(1, &vao);
        glBindVertexArrayAPPLE(vao);
        GLuint vbo1;
        glGenBuffersARB(1, &vbo1);
        //vbo1 = image;
        glBindBufferARB(GL_ARRAY_BUFFER, vbo1);
        //glBindBufferARB(GL_ARRAY_BUFFER, image);
        glBindTexture(GL_TEXTURE_2D, gluimage);
        glBufferDataARB(GL_ARRAY_BUFFER,4 * sizeof(double) * 8,&points[0],GL_STATIC_DRAW);
        glVertexPointer(2, GL_DOUBLE, sizeof(double) * 8, NULL);
        glColorPointer(4, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*2));
        glTexCoordPointer(2, GL_DOUBLE, sizeof(double) * 8, (void*)(sizeof(double)*6));
        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_COLOR_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glDrawArraysEXT(GL_QUADS, 0, 4);
        glDisableClientState(GL_COLOR_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    }

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    There's so much wrong with this code that it's difficult to know where to start.

    You're mixing extension and non-extenstion versions of function calls and enums.

    You're mixing VAOs with legacy fixed vertex attributes.

    You're using doubles.

    You're leaking memory and object handles.

    I suggest that you fix your code so that it's at least conformant with the spec and documentation, then see if the problem recurs.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    8
    Quote Originally Posted by mhagain View Post
    There's so much wrong with this code that it's difficult to know where to start.

    You're mixing extension and non-extenstion versions of function calls and enums.

    You're mixing VAOs with legacy fixed vertex attributes.

    You're using doubles.

    You're leaking memory and object handles.

    I suggest that you fix your code so that it's at least conformant with the spec and documentation, then see if the problem recurs.
    I used extension versions whenever non-extension ones were not available - am on 1.4. All other times I used the non-extension versions, as there are no non-extension versions.

    I wasn't sure on using VAOs, but read that they should always be used to provide forward compability. Or have I misread something?

    Why is using doubles wrong?

    If by leaking object handles you mean the map, I do need to display multiple images simultaneously. Or do you have something else in mind?

Similar Threads

  1. Segmentation fault when loading texture using SOIL
    By Donnie in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-01-2015, 06:52 AM
  2. Don't see my texture on cube, SOIL
    By Schieby in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-01-2013, 01:40 PM
  3. Sth wrong with texture loaded using SOIL
    By imported_butterfly in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-15-2013, 12:51 AM
  4. Texture Mapping/Loading an image using SOIL
    By annette in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-16-2011, 10:44 AM
  5. why my texture is not displayed ?
    By airseb in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-07-2003, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean