Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is the first time I've had this problem, my code just won't load the images I need it to.

Here is my first function for loading the image into data:

    void C_Resource_Loader::v_Create_Image(std::string filename,int nID)
{
    //create image and bind to it
    ilGenImages(1, &image[nID]);
    ilBindImage(image[nID]);

    //check if DevIL successfully loads the image
    success = ilLoadImage(filename.c_str());
    if(success)
    {
        success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
        if (!success)
            SDL_Quit();
        //create texture and bind to it
        glGenTextures(nID,&texture[nID]);
        glBindTexture(GL_TEXTURE_2D,texture[nID]);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


        glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
        ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
        ilGetData());

        ilDeleteImages(nID, &texture[nID]);
    }
}

and here is my code for putting the image on the screen:

void C_Resource_Loader::v_Apply_Image(int nID, int pn_X, int pn_Y, int pn_Depth)
{
    glPushMatrix();

    //bind the image so it can be textured
    glGenTextures(1,&texture[nID]);
    glBindTexture(GL_TEXTURE_2D,texture[nID]);

    //move the image to the set x and y
    glTranslatef(pn_X,pn_Y,-600);

    glBegin(GL_QUADS);

    glTexCoord2i(0,0); 
    glVertex3f(0,0,pn_Depth);
    glTexCoord2i(0,1); 
    glVertex3f(0,32,pn_Depth);
    glTexCoord2i(1,1); 
    glVertex3f(32,32,pn_Depth);
    glTexCoord2i(1,0); 
    glVertex3f(32,0,pn_Depth);

    glEnd();
    glPopMatrix();
}

Is there a major problem with it, because this code should work, I've used it many times before...

share|improve this question
1  
What is going wrong? Are you getting any errors? –  ktodisco May 13 '12 at 16:56
    
the images aren't binding to the quad –  Brendan Webster May 13 '12 at 18:53
1  
What debugging steps have you taken so far? –  Patrick Hughes May 13 '12 at 20:20
1  
So the quad is just showing up black? Check for OpenGL errors when you pass the image data and create the quad. It's possible that you didn't call ilInit() before loading the image, and so OpenGL is getting NULL data. –  ktodisco May 13 '12 at 21:51
add comment

1 Answer

up vote 1 down vote accepted

You are calling glGenTextures right before drawing your quad. This should be only called when loading the texture data, since this creates a texture reference in the GPU for use by your code.

And check you are calling glEnable(GL_TEXTURE_2D) somewhere in your code so 2D texturing can be used.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.