Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ruudje

Whats wrong with this??? (textures)

This topic is 5384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i].norm[1],
                        object->face[i].norm[2]);

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

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

                //----------------- THIRD VERTEX -----------------
                // Normal of the first vertex
                glNormal3fv (object->vertex[ object->face[i].c ].norm);
                // Texture coordinates of the third vertex
                glTexCoord2f( object->mapcoord[ object->face[i].c ].u,
                        object->mapcoord[ object->face[i].c ].v);
                // Coordinates of the Third vertex
                glVertex3f( object->vertex[ object->face[i].c ].x,
                        object->vertex[ object->face[i].c ].y,
                        object->vertex[ object->face[i].c ].z);
        }
        glEnd();
}
 
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 on my model, and Im positive it has uv coordinates

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!