List of usage examples for com.badlogic.gdx.graphics GL10 GL_TRIANGLES
int GL_TRIANGLES
To view the source code for com.badlogic.gdx.graphics GL10 GL_TRIANGLES.
Click Source Link
From source file:com.kevlanche.threedeetest.ScalableObjLoader.java
License:Apache License
protected ModelData loadModelData(FileHandle file, boolean flipV) { String line;//from w w w . ja v a 2s . c o m String[] tokens; char firstChar; MtlLoader mtl = new MtlLoader(); // Create a "default" Group and set it as the active group, in case // there are no groups or objects defined in the OBJ file. Group activeGroup = new Group("default"); groups.add(activeGroup); BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()), 4096); int id = 0; try { while ((line = reader.readLine()) != null) { tokens = line.split("\\s+"); if (tokens.length < 1) break; if (tokens[0].length() == 0) { continue; } else if ((firstChar = tokens[0].toLowerCase().charAt(0)) == '#') { continue; } else if (firstChar == 'v') { if (tokens[0].length() == 1) { verts.add(Float.parseFloat(tokens[1]) * this.objScale); verts.add(Float.parseFloat(tokens[2]) * this.objScale); verts.add(Float.parseFloat(tokens[3]) * this.objScale); } else if (tokens[0].charAt(1) == 'n') { norms.add(Float.parseFloat(tokens[1])); norms.add(Float.parseFloat(tokens[2])); norms.add(Float.parseFloat(tokens[3])); } else if (tokens[0].charAt(1) == 't') { uvs.add(Float.parseFloat(tokens[1])); uvs.add((flipV ? 1 - Float.parseFloat(tokens[2]) : Float.parseFloat(tokens[2]))); } } else if (firstChar == 'f') { String[] parts; Array<Integer> faces = activeGroup.faces; for (int i = 1; i < tokens.length - 2; i--) { parts = tokens[1].split("/"); faces.add(getIndex(parts[0], verts.size)); if (parts.length > 2) { if (i == 1) activeGroup.hasNorms = true; faces.add(getIndex(parts[2], norms.size)); } if (parts.length > 1 && parts[1].length() > 0) { if (i == 1) activeGroup.hasUVs = true; faces.add(getIndex(parts[1], uvs.size)); } parts = tokens[++i].split("/"); faces.add(getIndex(parts[0], verts.size)); if (parts.length > 2) faces.add(getIndex(parts[2], norms.size)); if (parts.length > 1 && parts[1].length() > 0) faces.add(getIndex(parts[1], uvs.size)); parts = tokens[++i].split("/"); faces.add(getIndex(parts[0], verts.size)); if (parts.length > 2) faces.add(getIndex(parts[2], norms.size)); if (parts.length > 1 && parts[1].length() > 0) faces.add(getIndex(parts[1], uvs.size)); activeGroup.numFaces++; } } else if (firstChar == 'o' || firstChar == 'g') { // This implementation only supports single object or group // definitions. i.e. "o group_a group_b" will set group_a // as the active group, while group_b will simply be // ignored. if (tokens.length > 1) activeGroup = setActiveGroup(tokens[1]); else activeGroup = setActiveGroup("default"); } else if (tokens[0].equals("mtllib")) { mtl.load(file.parent().child(tokens[1])); } else if (tokens[0].equals("usemtl")) { if (tokens.length == 1) activeGroup.materialName = "default"; else activeGroup.materialName = tokens[1]; } } reader.close(); } catch (IOException e) { return null; } // If the "default" group or any others were not used, get rid of them for (int i = 0; i < groups.size; i++) { if (groups.get(i).numFaces < 1) { groups.removeIndex(i); i--; } } // If there are no groups left, there is no valid Model to return if (groups.size < 1) return null; // Get number of objects/groups remaining after removing empty ones final int numGroups = groups.size; final ModelData data = new ModelData(); for (int g = 0; g < numGroups; g++) { Group group = groups.get(g); Array<Integer> faces = group.faces; final int numElements = faces.size; final int numFaces = group.numFaces; final boolean hasNorms = group.hasNorms; final boolean hasUVs = group.hasUVs; final float[] finalVerts = new float[(numFaces * 3) * (3 + (hasNorms ? 3 : 0) + (hasUVs ? 2 : 0))]; for (int i = 0, vi = 0; i < numElements;) { int vertIndex = faces.get(i++) * 3; finalVerts[vi++] = verts.get(vertIndex++); finalVerts[vi++] = verts.get(vertIndex++); finalVerts[vi++] = verts.get(vertIndex); if (hasNorms) { int normIndex = faces.get(i++) * 3; finalVerts[vi++] = norms.get(normIndex++); finalVerts[vi++] = norms.get(normIndex++); finalVerts[vi++] = norms.get(normIndex); } if (hasUVs) { int uvIndex = faces.get(i++) * 2; finalVerts[vi++] = uvs.get(uvIndex++); finalVerts[vi++] = uvs.get(uvIndex); } } final int numIndices = numFaces * 3 >= Short.MAX_VALUE ? 0 : numFaces * 3; final short[] finalIndices = new short[numIndices]; // if there are too many vertices in a mesh, we can't use indices if (numIndices > 0) { for (int i = 0; i < numIndices; i++) { finalIndices[i] = (short) i; } } Array<VertexAttribute> attributes = new Array<VertexAttribute>(); attributes.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); if (hasNorms) attributes.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if (hasUVs) attributes.add( new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); String nodeId = "node" + (++id); String meshId = "mesh" + id; String partId = "part" + id; ModelNode node = new ModelNode(); node.id = nodeId; node.meshId = meshId; node.scale = new Vector3(1, 1, 1); node.translation = new Vector3(); node.rotation = new Quaternion(); ModelNodePart pm = new ModelNodePart(); pm.meshPartId = partId; pm.materialId = group.materialName; node.parts = new ModelNodePart[] { pm }; ModelMeshPart part = new ModelMeshPart(); part.id = partId; part.indices = finalIndices; part.primitiveType = GL10.GL_TRIANGLES; ModelMesh mesh = new ModelMesh(); mesh.id = meshId; mesh.attributes = attributes.toArray(VertexAttribute.class); mesh.vertices = finalVerts; mesh.parts = new ModelMeshPart[] { part }; data.nodes.add(node); data.meshes.add(mesh); ModelMaterial mm = mtl.getMaterial(group.materialName); data.materials.add(mm); } //for (ModelMaterial m : mtl.materials) //data.materials.add(m); // An instance of ObjLoader can be used to load more than one OBJ. // Clearing the Array cache instead of instantiating new // Arrays should result in slightly faster load times for // subsequent calls to loadObj if (verts.size > 0) verts.clear(); if (norms.size > 0) norms.clear(); if (uvs.size > 0) uvs.clear(); if (groups.size > 0) groups.clear(); return data; }
From source file:com.kingx.dungeons.graphics.cube.CubeRenderer.java
License:Apache License
private void renderMesh() { if (idx == 0) return;/*from w w w . j ava 2s .c o m*/ renderCalls++; totalRenderCalls++; int quadsInBatch = idx / verticesPerQuad; if (quadsInBatch / Cube.QUADS > cubeCount) cubeCount = quadsInBatch; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(quadsInBatch * CubeSide.INDICES); total += idx; if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc); } if (customShader != null) mesh.render(customShader, App.DEBUG != null && App.isWireframe() ? GL10.GL_LINES : GL10.GL_TRIANGLES, 0, quadsInBatch * CubeSide.INDICES); else mesh.render(shader, App.DEBUG != null && App.isWireframe() ? GL10.GL_LINES : GL10.GL_TRIANGLES, 0, quadsInBatch * CubeSide.INDICES); idx = 0; currBufferIdx++; if (currBufferIdx == buffers.length) currBufferIdx = 0; mesh = buffers[currBufferIdx]; }
From source file:org.interreg.docexplore.reader.book.BookCover.java
License:Open Source License
public void render(Bindable coverTex, Bindable innerCoverTex) { GL10 gl = Gdx.gl10;//from w w w. j av a2 s.co m gl.glColor4f(1, 1, 1, 1); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glEnable(GL10.GL_TEXTURE_2D); if (innerCoverTex != null && !book.app.bookEngine.coverOnly()) { innerCoverTex.bind(); meshes[innerBinding].render(GL10.GL_TRIANGLES); } if (coverTex != null) { coverTex.bind(); meshes[outerBinding].render(GL10.GL_TRIANGLES); } // meshes[topBinding].render(GL10.GL_TRIANGLES); // meshes[bottomBinding].render(GL10.GL_TRIANGLES); // meshes[frontBinding].render(GL10.GL_TRIANGLES); gl.glDisable(GL10.GL_TEXTURE_2D); }
From source file:org.interreg.docexplore.reader.book.BookPageStack.java
License:Open Source License
public void renderGeometryOnly() { if (nStackPages == 0) return;/*from w w w . j a v a 2s. c om*/ stackSide.render(GL10.GL_TRIANGLES); spineFill.render(GL10.GL_TRIANGLES); stackFront.render(GL10.GL_TRIANGLES); }
From source file:org.interreg.docexplore.reader.book.BookPageStack.java
License:Open Source License
public void render(Bindable pageTexture, Bindable regionMask) { if (nStackPages == 0) return;/* w w w . j ava 2 s. com*/ stackSide.render(GL10.GL_TRIANGLES); spineFill.render(GL10.GL_TRIANGLES); Gdx.gl10.glColor4f(1, 1, 1, 1); Gdx.gl10.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); Gdx.gl10.glEnable(GL10.GL_TEXTURE_2D); pageTexture.bind(); stackFront.render(GL10.GL_TRIANGLES); if (regionMask != null) { Gdx.gl10.glDisable(GL10.GL_LIGHTING); Gdx.gl10.glDepthFunc(GL10.GL_LEQUAL); float shade = book.app.bookEngine.roiOverlay.active || book.app.bookEngine.roiOverlay.leaving ? .5f * book.app.bookEngine.roiOverlay.alpha : .5f * (cnt > 100 ? 200 - cnt : cnt) / 100f; Gdx.gl10.glColor4f(1, 1, 1, shade); regionMask.bind(); stackFront.render(GL10.GL_TRIANGLES); Gdx.gl10.glEnable(GL10.GL_LIGHTING); } Gdx.gl10.glDisable(GL10.GL_TEXTURE_2D); Gdx.gl10.glDepthFunc(GL10.GL_LESS); cnt = (cnt + 1) % 200; }
From source file:org.interreg.docexplore.reader.book.page.BookPage.java
License:Open Source License
public void renderGeometryOnly() { frontPage.render(GL10.GL_TRIANGLES); backPage.render(GL10.GL_TRIANGLES); }
From source file:org.interreg.docexplore.reader.book.page.BookPage.java
License:Open Source License
public void render(Bindable front, Bindable back) { Gdx.gl10.glColor4f(1, 1, 1, 1);//from w w w.j ava 2 s . c o m Gdx.gl10.glEnable(GL10.GL_POLYGON_OFFSET_FILL); Gdx.gl10.glPolygonOffset(0, -20000); Gdx.gl10.glEnable(GL10.GL_TEXTURE_2D); front.bind(); frontPage.render(GL10.GL_TRIANGLES); back.bind(); backPage.render(GL10.GL_TRIANGLES); Gdx.gl10.glDisable(GL10.GL_TEXTURE_2D); Gdx.gl10.glDisable(GL10.GL_POLYGON_OFFSET_FILL); }
From source file:org.interreg.docexplore.reader.book.roi.ROIOverlay.java
License:Open Source License
static void doQuad(float x1, float y1, float x2, float y2) { if (quad == null) quad = GfxUtils.buildQuad(0, 0, 0, 0, 1, 1, 1, 1); GL10 gl = Gdx.gl10;/*from www. j a va2s . c o m*/ gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glPushMatrix(); gl.glTranslatef(x1, y1, 0); gl.glScalef(x2 - x1, y2 - y1, 1); quad.render(GL10.GL_TRIANGLES); gl.glPopMatrix(); }
From source file:org.interreg.docexplore.reader.DebugGraphics.java
License:Open Source License
public void fillTriangle(double x1, double y1, double x2, double y2, double x3, double y3) { FloatBuffer data = threeMesh.getVerticesBuffer(); data.limit(data.capacity());// w w w. j a v a2 s .com data.put(0, (float) x1).put(1, (float) y1).put(2, 0); data.put(3, (float) x2).put(4, (float) y2).put(5, 0); data.put(6, (float) x3).put(7, (float) y3).put(8, 0); Gdx.gl10.glPolygonMode(GL10.GL_FRONT_AND_BACK, GL10.GL_FILL); //Gdx.gl10.glPolygonMode(GL10.GL_FRONT_AND_BACK, GL10.GL_LINE); threeMesh.render(GL10.GL_TRIANGLES); Gdx.gl10.glPolygonMode(GL10.GL_FRONT_AND_BACK, GL10.GL_FILL); }
From source file:org.interreg.docexplore.reader.gfx.GfxUtils.java
License:Open Source License
public static void doQuad(float x1, float y1, float s1, float t1, float r1, float g1, float b1, float a1, float x2, float y2, float s2, float t2, float r2, float g2, float b2, float a2, float x3, float y3, float s3, float t3, float r3, float g3, float b3, float a3, float x4, float y4, float s4, float t4, float r4, float g4, float b4, float a4) { if (quadTCMesh == null) { quadTCMesh = new Mesh(false, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, "p"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "tc"), new VertexAttribute(VertexAttributes.Usage.Color, 4, "c")); FloatBuffer vertexBuffer = quadTCMesh.getVerticesBuffer(); vertexBuffer.limit(vertexBuffer.capacity()); ShortBuffer indexBuffer = quadTCMesh.getIndicesBuffer(); indexBuffer.limit(indexBuffer.capacity()); indexBuffer.put(new short[] { 0, 1, 2, 0, 2, 3 }); indexBuffer.flip();//ww w.java2s. co m } FloatBuffer vertexBuffer = quadTCMesh.getVerticesBuffer(); vertexBuffer.put(x1).put(y1).put(0).put(s1).put(t1).put(r1).put(g1).put(b1).put(a1).put(x2).put(y2).put(0) .put(s2).put(t2).put(r2).put(g2).put(b2).put(a2).put(x3).put(y3).put(0).put(s3).put(t3).put(r3) .put(g3).put(b3).put(a3).put(x4).put(y4).put(0).put(s4).put(t4).put(r4).put(g4).put(b4).put(a4) .flip(); quadTCMesh.render(GL10.GL_TRIANGLES); }