Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

opengl tga textured polygon shows up white

  • 25-03-2008 6:03pm
    #1
    Registered Users, Registered Users 2 Posts: 7


    Hi I have created a polygon and am trying to apply a texture that I loaded from a .tga file in the same directory as the exe here is the relevant code:
    bool loadTGA(const char *filename, STGA& tgaFile)
    {
        FILE *file;
        unsigned char type[4];
        unsigned char info[6];
    
            file = fopen(filename, "rb");
    
            if (!file)
            return false;
    
        fread (&type, sizeof (char), 3, file);
        fseek (file, 12, SEEK_SET);
        fread (&info, sizeof (char), 6, file);
    
        //image type either 2 (color) or 3 (greyscale)
        if (type[1] != 0 || (type[2] != 2 && type[2] != 3))
        {
            fclose(file);
            return false;
        }
    
        tgaFile.width = info[0] + info[1] * 256;
        tgaFile.height = info[2] + info[3] * 256;
        tgaFile.byteCount = info[4] / 8;
    
        if (tgaFile.byteCount != 3 && tgaFile.byteCount != 4) {
            fclose(file);
    
            return false;
        }
    
    
        long imageSize = tgaFile.width * tgaFile.height
     * tgaFile.width * tgaFile.byteCount;
    
        //allocate memory for image data
        tgaFile.data = new unsigned char[imageSize];
    
        //read in image data
        fread(tgaFile.data, sizeof(unsigned char), imageSize, file);
    
        //close file
        fclose(file);
    glGenTextures(1,&texture[0]);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    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_DECAL);
    glTexImage2D(GL_TEXTURE_2D,0,3,tgaFile.width,tgaFile.height,0,GL_RGB,GL_UNSIGNED_BYTE,tgaFile.data);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    
        return true;
    }
    
    
    
    
    void interf (void)
    {
    STGA tgaFile;
    loadTGA("Irk.tga",tgaFile);
     
      
      glBindTexture(GL_TEXTURE_2D,texture[0]);
      glBegin(GL_QUADS);
      //glColor3f(0.3,0.4,0.8);
      glTexCoord2f(0,0); glVertex2f(-3,4);
        glTexCoord2f(1,0); glVertex2f(-1,4);
          glTexCoord2f(1,1); glVertex2f(-1,8);
            glTexCoord2f(0,1); glVertex2f(-3,8);
      glEnd();
    }
    
    Any ideas as to why the polygon just shows up white?
    Thanks in advance.


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Make sure texturing is enabled with glEnable(GL_TEXTURE_2D); before drawing.


  • Registered Users, Registered Users 2 Posts: 7 thunderBuns


    Yeah I have glEnable in my init funtion but I put it in just above the glGenTextures just to check. No change though it still shows up as a white square. Any other suggestions?


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    What are the dimensions of the texture?


  • Registered Users, Registered Users 2 Posts: 7 thunderBuns


    Ah I changed it to 512x512 there and now it shows up. Well spotted. It's still a little screwy though the bottom triangle shows up fine but the top one is all stretched and wierd. Is this to do with my texCoords?


Advertisement