Java Code Examples for com.badlogic.gdx.graphics.GL20#GL_TRIANGLES
The following examples show how to use
com.badlogic.gdx.graphics.GL20#GL_TRIANGLES .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Terrain.java From Mundus with Apache License 2.0 | 6 votes |
public void init() { final int numVertices = this.vertexResolution * vertexResolution; final int numIndices = (this.vertexResolution - 1) * (vertexResolution - 1) * 6; mesh = new Mesh(true, numVertices, numIndices, attribs); this.vertices = new float[numVertices * stride]; mesh.setIndices(buildIndices()); buildVertices(); mesh.setVertices(vertices); MeshPart meshPart = new MeshPart(null, mesh, 0, numIndices, GL20.GL_TRIANGLES); meshPart.update(); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.part(meshPart, material); model = mb.end(); modelInstance = new ModelInstance(model); modelInstance.transform = transform; }
Example 2
Source File: MG3dModelLoader.java From Mundus with Apache License 2.0 | 6 votes |
private int parseType(String type) { if (type.equals("TRIANGLES")) { return GL20.GL_TRIANGLES; } else if (type.equals("LINES")) { return GL20.GL_LINES; } else if (type.equals("POINTS")) { return GL20.GL_POINTS; } else if (type.equals("TRIANGLE_STRIP")) { return GL20.GL_TRIANGLE_STRIP; } else if (type.equals("LINE_STRIP")) { return GL20.GL_LINE_STRIP; } else { throw new GdxRuntimeException("Unknown primitive type '" + type + "', should be one of triangle, trianglestrip, line, linestrip, lineloop or point"); } }
Example 3
Source File: HeadlessG3dModelLoader.java From gdx-proto with Apache License 2.0 | 6 votes |
private int parseType (String type) { if (type.equals("TRIANGLES")) { return GL20.GL_TRIANGLES; } else if (type.equals("LINES")) { return GL20.GL_LINES; } else if (type.equals("POINTS")) { return GL20.GL_POINTS; } else if (type.equals("TRIANGLE_STRIP")) { return GL20.GL_TRIANGLE_STRIP; } else if (type.equals("LINE_STRIP")) { return GL20.GL_LINE_STRIP; } else { throw new GdxRuntimeException("Unknown primitive type '" + type + "', should be one of triangle, trianglestrip, line, linestrip, lineloop or point"); } }
Example 4
Source File: GdxRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/*********************************************************************\ |* Render Calls *| \*********************************************************************/ public int convertElementMode(Mode mode) { switch (mode) { case Points: return GL20.GL_POINTS; case Lines: return GL20.GL_LINES; case LineLoop: return GL20.GL_LINE_LOOP; case LineStrip: return GL20.GL_LINE_STRIP; case Triangles: return GL20.GL_TRIANGLES; case TriangleFan: return GL20.GL_TRIANGLE_FAN; case TriangleStrip: return GL20.GL_TRIANGLE_STRIP; default: throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode); } }
Example 5
Source File: GLTFTypes.java From gdx-gltf with Apache License 2.0 | 5 votes |
/** https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#primitivemode */ public static int mapPrimitiveMode(Integer glMode){ if(glMode == null) return GL20.GL_TRIANGLES; // TODO not sure switch (glMode) { case 0: return GL20.GL_POINTS; case 1: return GL20.GL_LINES; case 2: return GL20.GL_LINE_LOOP; case 3: return GL20.GL_LINE_STRIP; case 4: return GL20.GL_TRIANGLES; case 5: return GL20.GL_TRIANGLE_STRIP; case 6: return GL20.GL_TRIANGLE_FAN; } throw new GdxRuntimeException("unsupported mode " + glMode); }
Example 6
Source File: GLTFMeshExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
public static Integer mapPrimitiveMode(int type){ switch(type){ case GL20.GL_POINTS: return 0; case GL20.GL_LINES: return 1; case GL20.GL_LINE_LOOP: return 2; case GL20.GL_LINE_STRIP: return 3; case GL20.GL_TRIANGLES: return null; // default not need to be set case GL20.GL_TRIANGLE_STRIP: return 5; case GL20.GL_TRIANGLE_FAN: return 6; } throw new GdxRuntimeException("unsupported primitive type " + type); }
Example 7
Source File: RainRenderer.java From Cubes with MIT License | 5 votes |
private RainMesh() { mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, VERTEX_ATTRIBUTES); meshPart = new MeshPart(); meshPart.mesh = mesh; meshPart.primitiveType = GL20.GL_TRIANGLES; meshPart.offset = 0; mesh.setIndices(indices); }
Example 8
Source File: SunRenderer.java From Cubes with MIT License | 5 votes |
private SunRenderer(boolean moon) { this.moon = moon; String texturePath = moon ? moonTexturePath : sunTexturePath; material = Assets.getMaterial(texturePath); textureRegion = Assets.getTextureRegion(texturePath); indices = new short[6]; short j = 0; for (int i = 0; i < indices.length; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); indices[i + 3] = (short) (j + 2); indices[i + 4] = (short) (j + 3); indices[i + 5] = (short) (j + 0); } vertices = new float[CubesVertexAttributes.COMPONENTS * 4]; mesh = new Mesh(false, 4, 6, CubesVertexAttributes.VERTEX_ATTRIBUTES); mesh.setIndices(indices); FaceVertices.createMinY(new Vector3(-0.5f, 0f, -0.5f), textureRegion, null, 0, 0, 0, FULL_LIGHT, vertices, 0); mesh.setVertices(vertices); renderable = new CubesRenderable(); renderable.meshPart.primitiveType = GL20.GL_TRIANGLES; renderable.meshPart.offset = 0; renderable.meshPart.size = 6; renderable.meshPart.mesh = mesh; renderable.material = material; renderable.setFogEnabled(false); }
Example 9
Source File: AreaMesh.java From Cubes with MIT License | 5 votes |
public AreaMesh(VertexAttributes vertexAttributes) { mesh = new Mesh(true, MAX_VERTICES, MAX_INDICES, vertexAttributes); meshPart = new MeshPart(); meshPart.mesh = mesh; meshPart.primitiveType = GL20.GL_TRIANGLES; meshPart.offset = 0; mesh.setIndices(indices); int components = CubesVertexAttributes.components(vertexAttributes); maxVertexOffset = MAX_VERTICES * components; renderable.material = Assets.blockItemSheet.getMaterial(); renderable.name = "AreaMesh"; }
Example 10
Source File: GameWorld.java From uracer-kotd with Apache License 2.0 | 4 votes |
private List<OrthographicAlignedStillModel> createWalls () { List<OrthographicAlignedStillModel> models = null; if (mapUtils.hasObjectGroup(ObjectGroup.Walls)) { Vector2 fromMt = new Vector2(); Vector2 toMt = new Vector2(); Vector2 offsetMt = new Vector2(); // create material TextureAttribute ta = new TextureAttribute(Art.meshTrackWall, 0, "u_texture"); ta.uWrap = TextureWrap.Repeat.getGLEnum(); ta.vWrap = TextureWrap.Repeat.getGLEnum(); Material mat = new Material("trackWall", ta); MapLayer group = mapUtils.getObjectGroup(ObjectGroup.Walls); if (group.getObjects().getCount() > 0) { models = new ArrayList<OrthographicAlignedStillModel>(group.getObjects().getCount()); for (int i = 0; i < group.getObjects().getCount(); i++) { PolylineMapObject o = (PolylineMapObject)group.getObjects().get(i); //@off List<Vector2> points = MapUtils.extractPolyData( o.getPolyline().getVertices()); //@on if (points.size() >= 2) { float wallTicknessMt = 0.75f; float[] mags = new float[points.size() - 1]; offsetMt.set(o.getPolyline().getX(), o.getPolyline().getY()); offsetMt.set(Convert.px2mt(offsetMt)); fromMt.set(Convert.px2mt(points.get(0))).add(offsetMt); fromMt.y = worldSizeMt.y - fromMt.y; for (int j = 1; j <= points.size() - 1; j++) { toMt.set(Convert.px2mt(points.get(j))).add(offsetMt); toMt.y = worldSizeMt.y - toMt.y; // create box2d wall Box2DFactory.createWall(box2dWorld, fromMt, toMt, wallTicknessMt, 0f); // compute magnitude mags[j - 1] = (float)Math.sqrt((toMt.x - fromMt.x) * (toMt.x - fromMt.x) + (toMt.y - fromMt.y) * (toMt.y - fromMt.y)); fromMt.set(toMt); } Mesh mesh = buildWallMesh(points, mags); StillSubMesh[] subMeshes = new StillSubMesh[1]; subMeshes[0] = new StillSubMesh("wall", mesh, GL20.GL_TRIANGLES); OrthographicAlignedStillModel model = new OrthographicAlignedStillModel(new StillModel(subMeshes), mat); model.setPosition(o.getPolyline().getX(), worldSizePx.y - o.getPolyline().getY()); model.setScale(1); models.add(model); } } } } return models; }
Example 11
Source File: G3dtLoader.java From uracer-kotd with Apache License 2.0 | 4 votes |
private static StillSubMesh readStillSubMesh (BufferedReader in, boolean flipV) throws IOException { String name = readString(in); IntArray indices = readFaces(in); int numVertices = readInt(in); int numAttributes = readInt(in); if (!readString(in).equals("position")) throw new GdxRuntimeException("first attribute must be position."); int numUvs = 0; boolean hasNormals = false; for (int i = 1; i < numAttributes; i++) { String attributeType = readString(in); if (!attributeType.equals("normal") && !attributeType.equals("uv")) throw new GdxRuntimeException("attribute name must be normal or uv"); if (attributeType.equals("normal")) { if (i != 1) throw new GdxRuntimeException("attribute normal must be second attribute"); hasNormals = true; } if (attributeType.equals("uv")) { numUvs++; } } VertexAttribute[] vertexAttributes = createVertexAttributes(hasNormals, numUvs); int vertexSize = new VertexAttributes(vertexAttributes).vertexSize / 4; float[] vertices = new float[numVertices * vertexSize]; int idx = 0; int uvOffset = hasNormals ? 6 : 3; for (int i = 0; i < numVertices; i++) { readFloatArray(in, vertices, idx); if (flipV) { for (int j = idx + uvOffset + 1; j < idx + uvOffset + numUvs * 2; j += 2) { vertices[j] = 1 - vertices[j]; } } idx += vertexSize; } Mesh mesh = new Mesh(true, numVertices, indices.size, vertexAttributes); mesh.setVertices(vertices); mesh.setIndices(convertToShortArray(indices)); return new StillSubMesh(name, mesh, GL20.GL_TRIANGLES); }
Example 12
Source File: Chunk.java From Radix with MIT License | 4 votes |
private void updateModelInstances() { if(opaqueFaces != null) { if(opaqueModel != null) opaqueModel.dispose(); Mesh opaqueMesh = mesher.meshFaces(opaqueFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d", startPosition.x, startPosition.z), opaqueMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()))); opaqueModel = modelBuilder.end(); opaqueModelInstance = new ModelInstance(opaqueModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; opaqueFaces = null; } if(translucentFaces != null) { if(translucentModel != null) translucentModel.dispose(); Mesh translucentMesh = mesher.meshFaces(translucentFaces, meshBuilder); modelBuilder.begin(); modelBuilder.part(String.format("c-%d,%d-t", startPosition.x, startPosition.z), translucentMesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()), new BlendingAttribute(), FloatAttribute.createAlphaTest(0.25f))); translucentModel = modelBuilder.end(); translucentModelInstance = new ModelInstance(translucentModel) { @Override public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) { super.getRenderable(out, node, nodePart); if(RadixClient.getInstance().isWireframe()) { out.primitiveType = GL20.GL_LINES; } else { out.primitiveType = GL20.GL_TRIANGLES; } return out; } }; translucentFaces = null; } }