/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
@Override public void dispose () { texture.dispose(); shader.dispose(); vbo.dispose(); ibo.dispose(); }
@Override public void resume () { vbo.invalidate(); ibo.invalidate(); }
@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")); }
@Override public void render () { GL20 gl = Gdx.gl20; gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClearColor(0.7f, 0, 0, 1); gl.glClear(GL20.GL_COLOR_BUFFER_BIT); gl.glEnable(GL20.GL_TEXTURE_2D); shader.begin(); shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); indices.bind(); gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position()); indices.unbind(); vbo.unbind(shader); shader.end(); }
@Override public void render () { // System.out.println( "render"); Gdx.gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glEnable(GL20.GL_TEXTURE_2D); shader.begin(); shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); ibo.bind(); Gdx.gl20.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, 0); ibo.unbind(); vbo.unbind(shader); shader.end(); }
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);
/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
@Override public void dispose () { texture.dispose(); vbo.dispose(); indices.dispose(); shader.dispose(); }
/** Creates a new Mesh with the given attributes. Adds extra optimizations for dynamic (frequently modified) meshes. * * @param staticVertices whether vertices of this mesh are static or not. Allows for internal optimizations. * @param staticIndices whether indices of this mesh are static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate * * @author Jaroslaw Wisniewski <j.wisniewski@appsisle.com> **/ public Mesh (boolean staticVertices, boolean staticIndices, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(staticVertices, maxVertices, attributes); indices = new IndexBufferObject(staticIndices, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
/** Creates a new Mesh with the given attributes. Adds extra optimizations for dynamic (frequently modified) meshes. * * @param staticVertices whether vertices of this mesh are static or not. Allows for internal optimizations. * @param staticIndices whether indices of this mesh are static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate * * @author Jaroslaw Wisniewski <j.wisniewski@appsisle.com> **/ public Mesh (boolean staticVertices, boolean staticIndices, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(staticVertices, maxVertices, attributes); indices = new IndexBufferObject(staticIndices, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, new VertexAttributes(attributes)); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, new VertexAttributes(attributes)); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
case VertexBufferObject: vertices = new VertexBufferObject(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; break;
case VertexBufferObject: vertices = new VertexBufferObject(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; break;
/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
/** Creates a new Mesh with the given attributes. Adds extra optimizations for dynamic (frequently modified) meshes. * * @param staticVertices whether vertices of this mesh are static or not. Allows for internal optimizations. * @param staticIndices whether indices of this mesh are static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttributes}. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate * * @author Jaroslaw Wisniewski <j.wisniewski@appsisle.com> **/ public Mesh (boolean staticVertices, boolean staticIndices, int maxVertices, int maxIndices, VertexAttributes attributes) { vertices = makeVertexBuffer(staticVertices, maxVertices, attributes); indices = new IndexBufferObject(staticIndices, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
/** Creates a new Mesh with the given attributes. * * @param isStatic whether this mesh is static or not. Allows for internal optimizations. * @param maxVertices the maximum number of vertices this mesh can hold * @param maxIndices the maximum number of indices this mesh can hold * @param attributes the {@link VertexAttribute}s. Each vertex attribute defines one property of a vertex such as position, * normal or texture coordinate */ public Mesh (boolean isStatic, int maxVertices, int maxIndices, VertexAttribute... attributes) { vertices = makeVertexBuffer(isStatic, maxVertices, new VertexAttributes(attributes)); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; addManagedMesh(Gdx.app, this); }
case VertexBufferObject: vertices = new VertexBufferObject(isStatic, maxVertices, attributes); indices = new IndexBufferObject(isStatic, maxIndices); isVertexArray = false; break;