OpenGL not rendering my images to the screen

Posted by Brendan Webster on Game Development See other posts from Game Development or by Brendan Webster
Published on 2012-04-03T21:36:24Z Indexed on 2012/04/03 23:41 UTC
Read the original article Hit count: 365

Filed under:
|
|

for some reason my game isn't showing the image I am rendering to the screen.

My engine is state based, and at the beginning I set the logo, but it isn't showing on the screen.

Here is my method of doing so

first I create one image and assign some values to it's preset values.

//create one image instance for the logo background
    O_File.v_Create_Images(1);
    //set the atributes of the background
    //first Image
    O_File.sImage[0].nImageDepth = -30.0f;
    O_File.sImage[0].sImageLocation = "image.bmp";

    //load the images int 
    O_File.v_Load_Images();

Then I load them with DevIL

void C_File_Manager::v_Load_Images()
{
    ilGenImages(1, &image);
    ilBindImage(image);

    for(int i = 0;i < sImage.size();i++)
    {
        success = ilLoadImage(sImage[i].sImageLocation.c_str());
        if (success)
        {
            success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

            glGenTextures(1, &image);
            glBindTexture(GL_TEXTURE_2D, image); 

            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

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

            //asign values to the width and height of the image if they are already not assigned
            if(sImage[i].nImageHeight == 0)
                sImage[i].nImageHeight = ilGetInteger(IL_IMAGE_HEIGHT);
            if(sImage[i].nImageWidth == 0)
                sImage[i].nImageWidth = ilGetInteger(IL_IMAGE_WIDTH);

            std::cout << sImage[i].nImageHeight << std::endl;

            const std::string word = sImage[i].sImageLocation.c_str();
            std::cout << sImage[i].sImageLocation.c_str() << std::endl;
            ilLoadImage(word.c_str());

            ilDeleteImages(1, &image); 
        }
    }
}

and then I apply them to the screen

void C_File_Manager::v_Apply_Images()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    for(int i = 0;i < sImage.size();i++)
    {
        //move the image to where it should be on the screen;
        glTranslatef(sImage[i].nImageX,sImage[i].nImageY,sImage[i].nImageDepth);
        //rotate image around the 3 axes 
        glRotatef(sImage[i].fImageAngleX,1,0,0);
        glRotatef(sImage[i].fImageAngleY,0,1,0);
        glRotatef(sImage[i].fImageAngleZ,0,0,1);
        //scale the image
        glScalef(1,1,1);
        //center the image
        glTranslatef((sImage[i].nImageWidth/2),(sImage[i].nImageHeight/2),0);

        //draw the box that will encase the loaded image
        glBegin(GL_QUADS);
        //change the color of the loaded image;
        glColor4f(1,1,1,1);
        //top left corner of image
        glNormal3f(0.0,0,0.0);
        glTexCoord2f (1.0, 0.0);
        glVertex3f(0,0,sImage[i].nImageDepth);
        //top right corner of image
        glNormal3f(1.0,0,0.0);
        glTexCoord2f (1.0, 1.0);
        glVertex3f(0,sImage[i].nImageHeight,sImage[i].nImageDepth);
        //bottom right corner of image
        glNormal3f(-1.0,0,0.0);
        glTexCoord2f (0.0, 1.0);
        glVertex3f(sImage[i].nImageWidth,sImage[i].nImageHeight,sImage[i].nImageDepth);
        //bottom left corner of image
        glNormal3f(-1.0,0,0.0);
        glTexCoord2f(0.0, 0.0);
        glVertex3f(sImage[i].nImageWidth,0,sImage[i].nImageDepth);
        glEnd();
    }
}

when I debug there is no errors at all, but yet the images don't show up on the screen, I have positioned the camera at (0,0,-1) and that is where the images should show up.

the clipping plane is set 1 to 1000.

There is probably some random problem with the code, but I just can't catch it.

© Game Development or respective owner

Related posts about c++

Related posts about vector