Texture Problem

For people working on the C++ code.
User avatar
Krisi
Member
 
Posts: 41
Joined: Sat Oct 15, 2011 21:32
Location: Germany

Texture Problem

by Krisi » Mon Feb 20, 2012 21:38

Ive started to code a 3D torch but i have a big problem with the texture.
Here is the code section (for the first torch direction):
Code: Select all
case NDT_TORCHLIKE:
        {
            v3s16 dir = n.getWallMountedDir(nodedef);
           
            AtlasPointer ap(0);
            if(dir == v3s16(0,-1,0)){
                ap = f.tiles[0].texture; // floor
            } else if(dir == v3s16(0,1,0)){
                ap = f.tiles[1].texture; // ceiling
            // For backwards compatibility
            } else if(dir == v3s16(0,0,0)){
                ap = f.tiles[0].texture; // floor
            } else {
                ap = f.tiles[2].texture; // side
            }

            // Set material
            video::SMaterial material;
            material.setFlag(video::EMF_LIGHTING, false);
            material.setFlag(video::EMF_BACK_FACE_CULLING, false);
            material.setFlag(video::EMF_BILINEAR_FILTER, false);
            material.setFlag(video::EMF_FOG_ENABLE, true);
            //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
            material.MaterialType
                    = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
            material.setTexture(0, ap.atlas);

            video::SColor c(255,255,255,255);
           
            if (dir == v3s16(0,-1,0)) {
                video::S3DVertex vertices[28] =
                {
                    video::S3DVertex(-1.000001, -0.000000, -1.000000, -0.000000, -0.000000, -1.000000,c, 0.400000, 1.000000),
                    video::S3DVertex(-1.000002, 7.999998, -1.000000, -0.000000, -0.000000, -1.000000,c, 0.400000, 0.000000),
                    video::S3DVertex(1.000000, 7.999998, -1.000000, -0.000000, -0.000000, -1.000000,c, 0.200000, 0.000000),
                    video::S3DVertex(1.000002, 0.000000, -1.000000, -0.000000, -0.000000, -1.000000,c, 0.200000, 1.000000),
                    video::S3DVertex(1.000001, 7.999998, 1.000000, 1.000000, 0.000000, 0.000000,c, 0.600000, 0.000000),
                    video::S3DVertex(1.000002, -0.000000, 1.000000, 1.000000, 0.000000, 0.000000,c, 0.600000, 1.000000),
                    video::S3DVertex(1.000002, 0.000000, -1.000000, 1.000000, 0.000000, 0.000000,c, 0.800000, 1.000000),
                    video::S3DVertex(1.000001, 7.999998, 1.000000, 1.000000, 0.000000, -0.000001,c, 0.600000, 0.000000),
                    video::S3DVertex(1.000002, 0.000000, -1.000000, 1.000000, 0.000000, -0.000001,c, 0.800000, 1.000000),
                    video::S3DVertex(1.000000, 7.999998, -1.000000, 1.000000, 0.000000, -0.000001,c, 0.800000, 0.000000),
                    video::S3DVertex(-1.000002, 7.999998, 1.000000, 0.000000, 0.000000, 1.000000,c, 0.400000, 0.000000),
                    video::S3DVertex(-1.000000, -0.000000, 1.000000, 0.000000, 0.000000, 1.000000,c, 0.400000, 0.999999),
                    video::S3DVertex(1.000001, 7.999998, 1.000000, 0.000000, 0.000000, 1.000000,c, 0.600000, 0.000000),
                    video::S3DVertex(1.000002, -0.000000, 1.000000, 0.000000, -0.000000, 1.000000,c, 0.600000, 1.000000),
                    video::S3DVertex(-1.000002, 7.999998, -1.000000, -1.000000, -0.000000, 0.000000,c, -0.000000, 0.000000),
                    video::S3DVertex(-1.000001, -0.000000, -1.000000, -1.000000, -0.000000, 0.000000,c, 0.000000, 1.000000),
                    video::S3DVertex(-1.000002, 7.999998, 1.000000, -1.000000, -0.000000, 0.000000,c, 0.200000, 0.000000),
                    video::S3DVertex(-1.000001, -0.000000, -1.000000, -1.000000, -0.000000, 0.000001,c, 0.000000, 1.000000),
                    video::S3DVertex(-1.000000, -0.000000, 1.000000, -1.000000, -0.000000, 0.000001,c, 0.200000, 1.000000),
                    video::S3DVertex(-1.000002, 7.999998, 1.000000, -1.000000, -0.000000, 0.000001,c, 0.200000, 0.000000),
                    video::S3DVertex(-1.000001, -0.000000, -1.000000, 0.000000, -1.000000, 0.000000,c, 1.000000, 0.833333),
                    video::S3DVertex(1.000002, 0.000000, -1.000000, 0.000000, -1.000000, 0.000000,c, 0.800000, 0.833333),
                    video::S3DVertex(-1.000000, -0.000000, 1.000000, 0.000000, -1.000000, 0.000000,c, 1.000000, 1.000000),
                    video::S3DVertex(1.000002, -0.000000, 1.000000, -0.000000, -1.000000, -0.000000,c, 0.933333, 1.000000),
                    video::S3DVertex(-1.000002, 7.999998, -1.000000, 0.000000, 1.000000, 0.000000,c, 1.000000, 0.500000),
                    video::S3DVertex(-1.000002, 7.999998, 1.000000, 0.000000, 1.000000, 0.000000,c, 0.800000, 0.500000),
                    video::S3DVertex(1.000001, 7.999998, 1.000000, 0.000000, 1.000000, 0.000000,c, 0.800000, 0.666667),
                    video::S3DVertex(1.000000, 7.999998, -1.000000, 0.000000, 1.000000, -0.000000,c, 1.000000, 0.666667),
                };
                for(s32 i=0; i<28; i++)
                {
                    vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
                }
                u16 indices[] = {0, 1, 2, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 13, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 21, 23, 22, 24, 25, 26, 24, 26, 27};
                // Add to mesh collector
                collector.append(material, vertices, 28, indices, 36);
            } else {
                // Wall at X+ of node
                video::S3DVertex vertices[4] =
                {
                    video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
                            ap.x0(), ap.y1()),
                    video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
                            ap.x1(), ap.y1()),
                    video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
                            ap.x1(), ap.y0()),
                    video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
                            ap.x0(), ap.y0()),
                };
                for(s32 i=0; i<4; i++)
                {
                    if(dir == v3s16(1,0,0))
                        vertices[i].Pos.rotateXZBy(0);
                    if(dir == v3s16(-1,0,0))
                        vertices[i].Pos.rotateXZBy(180);
                    if(dir == v3s16(0,0,1))
                        vertices[i].Pos.rotateXZBy(90);
                    if(dir == v3s16(0,0,-1))
                        vertices[i].Pos.rotateXZBy(-90);
                    if(dir == v3s16(0,-1,0))
                        vertices[i].Pos.rotateXZBy(45);
                    if(dir == v3s16(0,1,0))
                        vertices[i].Pos.rotateXZBy(-45);

                    vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
                }
                u16 indices[] = {0,1,2,2,3,0};
                collector.append(material, vertices, 4, indices, 6);
            }
        break;}

And here is the result. I think i do not have to say where is the bug:
Image
Edit: The original code is from content_mapblock.cpp
Last edited by Krisi on Tue Feb 21, 2012 17:53, edited 1 time in total.
3D Player in Minetest?! - New GUI and more graphic options
"Lets do this..." Ghost Riley
Linux needs a good ego-shooter!!...
Sorry for my bad english
 

sapier
Developer
 
Posts: 763
Joined: Tue Aug 16, 2011 18:17

by sapier » Mon Feb 20, 2012 22:49

can you please post a image link that is viewable? ;-)
DON'T mention coding style!
(c) sapier all rights reserved
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51
Location: Rös̓̇chenhof

by kahrl » Tue Feb 21, 2012 00:33

Apparently it's http://krisi12345.lima-city.de/Screen-Pics/torch-bug.png

Looks like a texture atlas problem, but I don't have time to investigate it in more detail right now.
 


Return to Partly official engine development



Who is online

Users browsing this forum: No registered users and 1 guest