List of usage examples for com.badlogic.gdx.graphics GL20 GL_TRIANGLES
int GL_TRIANGLES
To view the source code for com.badlogic.gdx.graphics GL20 GL_TRIANGLES.
Click Source Link
From source file:com.badlogic.gdx.tests.gles2.SimpleVertexShader.java
License:Apache License
@Override public void render() { angle += Gdx.graphics.getDeltaTime() * 40.0f; float aspect = Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight(); projection.setToProjection(1.0f, 20.0f, 60.0f, aspect); view.idt().trn(0, 0, -2.0f);//w ww. j a v a 2 s.c om model.setToRotation(axis, angle); combined.set(projection).mul(view).mul(model); Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT); shader.begin(); shader.setUniformMatrix("u_mvpMatrix", combined); mesh.render(shader, GL20.GL_TRIANGLES); shader.end(); Gdx.app.log("angle", "" + angle); }
From source file:com.badlogic.invaders.simulation.Simulation.java
License:Apache License
private void populate() { ObjLoader objLoader = new ObjLoader(); shipModel = objLoader.loadModel(Gdx.files.internal("data/ship.obj")); invaderModel = objLoader.loadModel(Gdx.files.internal("data/invader.obj")); blockModel = objLoader.loadModel(Gdx.files.internal("data/block.obj")); shotModel = objLoader.loadModel(Gdx.files.internal("data/shot.obj")); final Texture shipTexture = new Texture(Gdx.files.internal("data/ship.png"), Format.RGB565, true); shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); final Texture invaderTexture = new Texture(Gdx.files.internal("data/invader.png"), Format.RGB565, true); invaderTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); shipModel.materials.get(0).set(TextureAttribute.createDiffuse(shipTexture)); invaderModel.materials.get(0).set(TextureAttribute.createDiffuse(invaderTexture)); ((ColorAttribute) blockModel.materials.get(0).get(ColorAttribute.Diffuse)).color.set(0, 0, 1, 0.5f); blockModel.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); shotModel.materials.get(0).set(ColorAttribute.createDiffuse(1, 1, 0, 1f)); final Texture explosionTexture = new Texture(Gdx.files.internal("data/explode.png"), Format.RGBA4444, true); explosionTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); final Mesh explosionMesh = new Mesh(true, 4 * 16, 6 * 16, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0")); float[] vertices = new float[4 * 16 * (3 + 2)]; short[] indices = new short[6 * 16]; int idx = 0;/*ww w. j a v a 2 s .com*/ int index = 0; for (int row = 0; row < 4; row++) { for (int column = 0; column < 4; column++) { vertices[idx++] = 1; vertices[idx++] = 1; vertices[idx++] = 0; vertices[idx++] = 0.25f + column * 0.25f; vertices[idx++] = 0 + row * 0.25f; vertices[idx++] = -1; vertices[idx++] = 1; vertices[idx++] = 0; vertices[idx++] = 0 + column * 0.25f; vertices[idx++] = 0 + row * 0.25f; vertices[idx++] = -1; vertices[idx++] = -1; vertices[idx++] = 0; vertices[idx++] = 0f + column * 0.25f; vertices[idx++] = 0.25f + row * 0.25f; vertices[idx++] = 1; vertices[idx++] = -1; vertices[idx++] = 0; vertices[idx++] = 0.25f + column * 0.25f; vertices[idx++] = 0.25f + row * 0.25f; final int t = (4 * row + column) * 4; indices[index++] = (short) (t); indices[index++] = (short) (t + 1); indices[index++] = (short) (t + 2); indices[index++] = (short) (t); indices[index++] = (short) (t + 2); indices[index++] = (short) (t + 3); } } explosionMesh.setVertices(vertices); explosionMesh.setIndices(indices); explosionModel = ModelBuilder.createFromMesh(explosionMesh, GL20.GL_TRIANGLES, new Material(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA), TextureAttribute.createDiffuse(explosionTexture))); ship = new Ship(shipModel); ship.transform.rotate(0, 1, 0, 180); for (int row = 0; row < 4; row++) { for (int column = 0; column < 8; column++) { Invader invader = new Invader(invaderModel, -PLAYFIELD_MAX_X / 2 + column * 2f, 0, PLAYFIELD_MIN_Z + row * 2f); invaders.add(invader); } } for (int shield = 0; shield < 3; shield++) { blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -2)); blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -3)); blocks.add(new Block(blockModel, -10 + shield * 10 + 0, 0, -3)); blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -3)); blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -2)); } }
From source file:com.bladecoder.engine.util.Utils3D.java
License:Apache License
public static void createFloor() { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin();/*www .j a v a 2 s . c o m*/ MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked, new Material(ColorAttribute.createDiffuse(Color.WHITE))); mpb.setColor(1f, 1f, 1f, 1f); // mpb.box(0, -0.1f, 0, 10, .2f, 10); mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0); floorModel = modelBuilder.end(); floorInstance = new ModelInstance(floorModel); // TODO Set only when FBO is active floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); }
From source file:com.dgzt.core.shape.ArcShape.java
License:Open Source License
/** * The constructor.// w w w .j a v a 2s . c om * * @param shader - The shader. * @param startDegrees - The start degrees. * @param degreesNum - The number of degrees. * @param color - The color. */ public ArcShape(final ShaderProgram shader, final int startDegrees, final int degreesNum, final Color color) { super(shader, GL20.GL_TRIANGLES, degreesNum * 2, getIndices(degreesNum), color); this.startDegrees = startDegrees; this.degreesNum = degreesNum; }
From source file:com.dgzt.core.shape.LineShape.java
License:Open Source License
/** * The constructor.//w w w. j ava 2 s . co m * * @param shader - The shader. * @param color - The color. */ public LineShape(final ShaderProgram shader, final Color color) { super(shader, GL20.GL_TRIANGLES, VERTICES_NUM, new short[] { 0, 1, 2, 2, 3, 1 }, color); }
From source file:com.dgzt.core.shape.RectangleShape.java
License:Open Source License
/** * Constructor.//from w w w. j a va 2s . co m * * @param shader - The shader. * @param color - The color. */ public RectangleShape(final ShaderProgram shader, final Color color) { super(shader, GL20.GL_TRIANGLES, VERTICES_NUM, new short[] { 0, 1, 2, 2, 3, 0 }, color); }
From source file:com.doom.render.QuadBatch.java
License:Apache License
@Override public void flush() { if (idx == 0) return;/* w w w. j a v a 2 s .c o m*/ renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
From source file:com.esotericsoftware.spine.utils.TwoColorPolygonBatch.java
License:Open Source License
@Override public void flush() { if (vertexIndex == 0) return;// ww w. ja v a 2 s . com totalRenderCalls++; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, vertexIndex); mesh.setIndices(triangles, 0, triangleIndex); Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); mesh.render(shader, GL20.GL_TRIANGLES, 0, triangleIndex); vertexIndex = 0; triangleIndex = 0; }
From source file:com.github.fauu.helix.core.MapRegion.java
License:Open Source License
public void create(Vector2 size, Tile[] tiles, Array<Object> objects, TextureAtlas textureAtlas, GeometrySet geometrySet) {//from w w w. j av a2 s . c o m this.size = size; this.textureAtlas = textureAtlas; this.geometrySet = geometrySet; this.objects = objects; if (tiles != null) { this.tiles = tiles; } else { final int tilesLength = (int) (size.x * size.y); tiles = new Tile[tilesLength]; for (int i = 0; i < tilesLength; i++) { final Tile.Builder tileBuilder = new Tile.Builder(); final int tileX = i % (int) size.x; final int tileY = (int) Math.floor(i / (tilesLength / size.y)); tiles[i] = tileBuilder.setNo(i).setPosition(new Vector2(tileX, tileY)).setElevation(0) .setTextureId(0).setGeometryId(0).setFacing(Direction.SOUTH).build(); } } this.tiles = tiles; mesh = new MapRegionMesh(tiles, geometrySet, textureAtlas); renderable = new Renderable(); renderable.mesh = mesh; renderable.material = new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE), new TextureAttribute(TextureAttribute.Diffuse, textureAtlas.getTextures().first())); renderable.meshPartOffset = 0; renderable.meshPartSize = mesh.getNumVertices(); renderable.primitiveType = GL20.GL_TRIANGLES; renderable.worldTransform.idt(); }
From source file:com.github.fauu.helix.editor.displayable.TileHighlightDisplayable.java
License:Open Source License
public TileHighlightDisplayable() { ModelBuilder modelBuilder = new ModelBuilder(); Model model = modelBuilder.createRect(0, 0, Z_OFFSET, 1, 0, Z_OFFSET, 1, 1, Z_OFFSET, 0, 1, Z_OFFSET, 0, 0, 1, GL20.GL_TRIANGLES, new Material(new ColorAttribute(ColorAttribute.createDiffuse(color)), new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)), VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates); instance = new ModelInstance(model); }