简体   繁体   中英

Bind texture to mesh in libGDX?

I have a mesh generated from data in Renderables. Environment is set. Material is a simple new Material() .

            ... /*init renderable*/

    /*set mesh parameters*/
    renderable.mesh = new Mesh(false, 
            (int)(meshVertexArray.length/SurfaceBuilder.__ELEMENTSPERVERTEX__), /*!vertices, not cordinates*/ 
            meshIndexArray.length,
            new VertexAttribute(Usage.Position,3,"a_position"),
            new VertexAttribute(Usage.Normal,3,"a_normal"),
            new VertexAttribute(Usage.TextureCoordinates,2,"a_texCoords"),
            new VertexAttribute(Usage.ColorPacked,4, "a_color")
    );

            ... /*set vertices*/

The mesh is generated properly, but I can't see the textures, only the gray (shaded) triangles. I did try the rtfm method, but so far I saw no way to bind a texture, so it displays properly in libGDX, only with shaders, and I'm not using them (I'm catching up on them after this feature is implemented). Is there a way in libGDX to bind textures to a mesh without shaders?

Without seeing your texturing code, maybe try specify a texture for your material using the following format:

    Material mat = new Material();
    //set the diffuse channel on the texture using some texture
    mat.set(TextureAttribute.createDiffuse(new Texture("crate.jpg"))); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM