Note that there are some explanatory texts on larger screens.

plurals
  1. POTexture on a mesh doesn't render correctly Libgdx
    primarykey
    data
    text
    <p>I am trying to put a texture on a mesh, but failing. I am trying to render <a href="http://imgur.com/J9AaRzX" rel="nofollow">something like this, where texture can be seen</a> but I get <a href="http://imgur.com/Pl2lbBe" rel="nofollow">this</a>, where I can barely see the triangle. I am running the following code:</p> <pre><code>public class Game implements ApplicationListener{ Mesh mesh; ShaderProgram shader; Texture texture; public static void main(String[] args) { LwjglApplication app = new LwjglApplication(new Game(), "Mesh Tutorial 1", 800, 600, true); } protected static ShaderProgram createMeshShader() { String vert = Gdx.files.internal("data/VertexShader.txt").readString(); String frag = Gdx.files.internal("data/FragmentShader.txt").readString(); ShaderProgram.pedantic = false; ShaderProgram shader = new ShaderProgram(vert, frag); return shader; } @Override public void create() { if (mesh == null) { mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE)); mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0.2f, 0.3f, 0.4f, 1f, 0, 1, 0.5f, -0.5f, 0, 0.1f, 0.2f, 0.1f, 1f, 1, 1, 0, 0.5f, 0, 0, 0.4f, 0.5f, 0.5f, 1f, 0 }); mesh.setIndices(new short[] { 0, 1, 2 }); texture = new Texture(Gdx.files.internal("data/badlogic.png")); } shader = createMeshShader(); } @Override public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_TEXTURE_2D); texture.bind(); mesh.render(shader, GL20.GL_TRIANGLES); } @Override public void resize(int width, int height) {} @Override public void pause() {} @Override public void resume() {} @Override public void dispose() {} </code></pre> <p>The <strong>Vertexshader</strong> is: </p> <pre><code>attribute vec4 a_position; attribute vec4 a_color; attribute vec2 a_texCoords; uniform mat4 u_projTrans; varying vec4 vColor; varying vec2 vTexCoord; void main() { vColor = a_color; vTexCoord = a_texCoords; gl_Position = u_projTrans * a_position; } </code></pre> <p><strong>Fragmentshader</strong>:</p> <pre><code>#ifdef GL_ES precision mediump float; #endif varying vec4 v_color; varying vec2 v_texCoords; uniform sampler2D u_texture; void main(){ vec4 texColor = texture2D(u_texture, v_texCoords); gl_FragColor = v_color * texColor; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload