Advertisement

Whats wrong with this??? (textures)

Started by September 25, 2003 12:41 PM
3 comments, last by Ruudje 21Β years, 5Β months ago
CBitmap is a class holding the bitmap data texture[0] is a GLuint, a member of the file_3ds class

void file_3ds::LoadBMP(char * filename)
{
        CBitmap *bmp = new CBitmap(filename);

        glGenTextures(1, &texture[0]);   // Create The Texture

        // Typical Texture Generation Using Data From The Bitmap
        glBindTexture(GL_TEXTURE_2D, texture[0]);

        // Generate The Texture
        glTexImage2D(GL_TEXTURE_2D, 0, 3, bmp->getWidth(), bmp->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, bmp->getData());

        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering

        delete bmp;
}
 
My drawing code:

void file_3ds::render(void)
{
        int i;

        // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)

        glBindTexture(GL_TEXTURE_2D, texture[0]);

        glBegin(GL_TRIANGLES);
        for (i = 0; i < object->polygons_qty ; i++)
        {
                glNormal3f(
                        object->face.norm[0],
                        object->face.norm[1],
                        object->face.norm[2]);

                //—————– FIRST VERTEX —————–
                // Normal of the first vertex
                glNormal3fv (object->vertex[ object->face.a ].norm);
                // Texture coordinates of the first vertex
                glTexCoord2f( object->mapcoord[ object->face.a ].u,
                        object->mapcoord[ object->face.a ].v);
                // Coordinates of the first vertex
                glVertex3f( object->vertex[ object->face.a ].x,
                        object->vertex[ object->face.a ].y,
                        object->vertex[ object->face.a ].z); //Vertex definition

                //—————– SECOND VERTEX —————–
                // Normal of the first vertex
                glNormal3fv (object->vertex[ object->face.b ].norm);
                // Texture coordinates of the second vertex
                glTexCoord2f( object->mapcoord[ object->face.b ].u,
                        object->mapcoord[ object->face.b ].v);
                // Coordinates of the second vertex
                glVertex3f( object->vertex[ object->face.b ].x,
                        object->vertex[ object->face.b ].y,
                        object->vertex[ object->face.b ].z);

                //—————– THIRD VERTEX —————–
                // Normal of the first vertex
                glNormal3fv (object->vertex[ object->face.c ].norm);
                // Texture coordinates of the third vertex
                glTexCoord2f( object->mapcoord[ object->face.c ].u,
                        object->mapcoord[ object->face.c ].v);
                // Coordinates of the Third vertex
                glVertex3f( object->vertex[ object->face.c ].x,
                        object->vertex[ object->face.c ].y,
                        object->vertex[ object->face.c ].z);
        }
        glEnd();
}
 </pre> 
My problem:
I dont get a texture :''(

It meets all demands for textures, its 256x256 etc Its in the path blablabla. I simply dont get to see a texture &#111;n my model, and Im positive it has uv coordinates  </i>  
Is glEnable(GL_TEXTURE_2D) anywhere?
Advertisement
After your glBindTexture(GL_TEXTURE_2D, texture[0]) in the render function use glEnable(GL_TEXTURE_2D).

Also to make sure use glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) before you do any rendering.
glEnable(GL_TEXTURE_2D) is in the initgl function...
Someone please shoot me... I made a HUGE newbie mistake!!! I was trying to load the texture in the constructor of my class, but it wasnt possible untill AFTER the constructor returns, since the data wouldnt exist yet. STUPID STUPID one line of code in the wrong place kept me busy all day.

This topic is closed to new replies.

Advertisement