Search in sources :

Example 1 with IndexBufferObject

use of com.badlogic.gdx.graphics.glutils.IndexBufferObject in project libgdx by libgdx.

the class VertexBufferObjectShaderTest method create.

@Override
public void create() {
    //@off
    String vertexShader = "attribute vec4 a_position;    \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main()                  \n" + "{                            \n" + "   v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n" + "   v_texCoords = a_texCoords; \n" + "   gl_Position =  a_position;  \n" + "}                            \n";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main()                                  \n" + "{                                            \n" + "  gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
    //@on
    shader = new ShaderProgram(vertexShader, fragmentShader);
    vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_color"));
    float[] vertices = new float[] { -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f) };
    vbo.setVertices(vertices, 0, vertices.length);
    indices = new IndexBufferObject(3);
    indices.setIndices(new short[] { 0, 1, 2 }, 0, 3);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) IndexBufferObject(com.badlogic.gdx.graphics.glutils.IndexBufferObject) VertexBufferObject(com.badlogic.gdx.graphics.glutils.VertexBufferObject) Texture(com.badlogic.gdx.graphics.Texture)

Example 2 with IndexBufferObject

use of com.badlogic.gdx.graphics.glutils.IndexBufferObject in project libgdx by libgdx.

the class IndexBufferObjectShaderTest method create.

@Override
public void create() {
    String vertexShader = "attribute vec4 a_position;    \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main()                  \n" + "{                            \n" + "   v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n" + "   v_texCoords = a_texCoords; \n" + "   gl_Position =  a_position;  \n" + "}                            \n";
    String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main()                                  \n" + "{                                            \n" + "  gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
    shader = new ShaderProgram(vertexShader, fragmentShader);
    vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_color"));
    float[] vertices = new float[] { -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f) };
    vbo.setVertices(vertices, 0, vertices.length);
    ibo = new IndexBufferObject(true, 3);
    ibo.setIndices(new short[] { 0, 1, 2 }, 0, 3);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
Also used : ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) IndexBufferObject(com.badlogic.gdx.graphics.glutils.IndexBufferObject) VertexBufferObject(com.badlogic.gdx.graphics.glutils.VertexBufferObject) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Texture (com.badlogic.gdx.graphics.Texture)2 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)2 IndexBufferObject (com.badlogic.gdx.graphics.glutils.IndexBufferObject)2 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)2 VertexBufferObject (com.badlogic.gdx.graphics.glutils.VertexBufferObject)2