Sign in to follow this  
scwizzo

[SOLVED] trouble with glGenTexture and changing textures

Recommended Posts

I had this working once before, but now I cannot seem to get it working and it's driving me nuts. A second set of eyes may see what I can't. Every time I run the program the message "texture ID == NULL" shows, and I get a white texture. I have no idea why it is becoming NULL, as I am creating the texture, then changing the RGB values to it, along with the mipmap. So yea if anyone can figure out why I keep getting a blank white image it would be greatly appreciated.
[source lang=cpp]
int main(int argc, char** argv)
{
    char FilePath[25];

    printf("Enter file name: ");
    cin>> FilePath;
    
    //createFromAvi(FilePath);
    /*InitAVI(FilePath, pGetFrame, iWidth, iHeight, FirstFrame, TotalFrames);
    if(pGetFrame == NULL){
        printf("Error: pGetFrame returned NULL\n");
        return 0;
    }
    printf("Width: %i\nHeight: %i\nTotal Frames: %i\n", iWidth, iHeight, TotalFrames);*/
    
    glEnable (GL_TEXTURE_2D); /* enable texture mapping */
    //glEnable (GL_DEPTH_TEST);
    //glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
    CreateTexture(g_TexID);
    if(GetLastError() == GL_INVALID_VALUE || GetLastError() == GL_INVALID_OPERATION) printf("Error: cannot create texture\n");

    //int histR[256], histG[256], histB[256];
    
    GetBMPDimensions(FilePath, g_Width, g_Height);
    
    rgb = new byte[g_Width*g_Height*3];
    grey = new byte[g_Width*g_Height*3];
    
    if(!LoadBMPFile(FilePath, g_TexID, rgb, g_Width, g_Height)) printf("Error: cannot load image\n");
    
    RGBToGreyScale(rgb, grey, g_Width, g_Height);
    
    //CreateCumulHistogram(grey, histR, histG, histB, g_Width, g_Height, GREY_CLR);
    //NormalizeHistogram(grey, histR, histG, histB, g_Width, g_Height);
    
    ChangeTexture(g_TexID, grey, g_Width, g_Height);

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(g_Width, g_Height);
    glutInitWindowPosition(512 - g_Width / 2, 384 - g_Height / 2);
    glutCreateWindow("FPS: ");
    
    /* THIS IS THE LINE IM TALKING ABOUT */
    if(!glIsTexture(g_TexID)) printf("Error: texture ID == NULL\n");
    
    time(&clock1);
    
    glutIdleFunc(displayFunc);
    glutDisplayFunc(displayFunc);
    glutMainLoop();
    
    
    //createFromAvi(FilePath);
    return 0;
}

bool ChangeTexture(GLuint TexID, byte* rgb, int iWidth, int iHeight)
{
    glBindTexture(GL_TEXTURE_2D, TexID); // Bind the ID texture specified by the 2nd parameter

    // Finally we define the 2d texture
    glTexImage2D(GL_TEXTURE_2D, 0, 3, iWidth, iHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb);

    // And create 2d mipmaps for the minifying function
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, iWidth, iHeight, GL_RGB, GL_UNSIGNED_BYTE, rgb);

    return true;
}

void CreateTexture(GLuint TexID)
{
    glGenTextures(1, &TexID); //generate 1 texture

    glBindTexture(GL_TEXTURE_2D, TexID); // Bind the ID texture specified by the 2nd parameter

    // The next commands sets the texture parameters
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produces better results)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); //The minifying function

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // We don't combine the color with the original surface color, use only the texture map.
}




EDIT: I got it working now, i was missing some enables and initializing a window. [Edited by - scwizzo on May 28, 2009 11:32:20 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this