简体   繁体   中英

How to tell where the texture is drawn in OpenGL / libgdx?

How do we know which texture is related to which mesh in OpenGL? In this example, we tell the mesh we use texture coordinates, but we don't say which texture (if we have more than one), and we don't tell the texture where to be drawn. How does it work? (I know the concept of UVs, but I don't know the concept of "where" the texture is drawn) :

mesh = new Mesh(true, 4, 6,
     new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"),
     new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords"));
texture = new Texture(Gdx.files.internal("data/img.png"));
mesh.setVertices(new float[] { 
      -1024f, -1024f, 0, 0, 1,
       1024f, -1024f, 0, 1, 1,
       1024f,  1024f, 0, 1, 0,
      -1024f,  1024f, 0, 0, 0
});


@Override
public void render() {
    // Texturing --------------------- /
    gl.glActiveTexture(GL10.GL_TEXTURE0);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    texture.bind();

    mesh.render(GL10.GL_TRIANGLES);
}

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