This project is read-only.

map texture to 3d obj model

Jun 28, 2012 at 5:09 PM
Edited Jun 29, 2012 at 12:53 AM


iam new to sharpgl i want to map texture image to 3d obj model here is my code

 textureImage = new Bitmap("b.tif");          
            texture = new uint[1];

            //  Get one texture id, and stick it into the textures array.
            gl.GenTextures(1, texture);

            //  Bind the texture.
            gl.BindTexture(OpenGL.GL_TEXTURE_2D, texture[0]);

            //  Tell OpenGL where the texture data is.
            gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE,
                textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);

            //  Specify linear filtering.
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST);
            gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST);

            gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
                                  Scene scene = SerializationEngine.Instance.LoadScene("b.obj");
            if (scene != null)
                foreach (var polygon in scene.SceneContainer.Traverse<Polygon>())

                    BoundingVolume boundingVolume = polygon.BoundingVolume;
                    float[] extent = new float[3];
                    polygon.BoundingVolume.GetBoundDimensions(out extent[0], out extent[1], out extent[2]);

                    float maxExtent = extent.Max();

                    //  Scale so that we are at most 10 units in size.
                    float scaleFactor = maxExtent > 10 ? 10.0f / maxExtent : 1;
                    polygon.Transformation.ScaleX = scaleFactor;
                    polygon.Transformation.ScaleY = scaleFactor;
                    polygon.Transformation.ScaleZ = scaleFactor;

           foreach (Polygon polygon in polygons)
               gl.Color(255.0f, 0.0f, 0.0f);
               polygon.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);



where b.obj is 3d model of bear and b.tif is the skin downloaded with the obj when i run the object appear that something wrong in texture mapping the obj appear blue but the texture is brown i don't know what wrong but any answer will help me please i need fast answer thanks in advance

i solve it

the problem that i wasn't understand how to make two objects and map two different texture but i did and it solved object not appear blue . but the texture not map correctly to object the face of the bear appear on its back i don't know  the reason :(