Java Code Examples for com.jogamp.opengl.GL2#GL_TRIANGLES
The following examples show how to use
com.jogamp.opengl.GL2#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: Model.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
public Model() { super(); sourceName=null; loader=null; isLoaded=false; unloadASAP=false; VBO = null; hasNormals=false; hasColors=false; hasUVs=false; renderStyle = GL2.GL_TRIANGLES; isDirty=false; adjust.setIdentity(); }
Example 2
Source File: BoxEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
/** * Procedurally generate a list of triangles that form a box, subdivided by some amount. */ protected void updateModel() { model.clear(); model.renderStyle=GL2.GL_TRIANGLES; //model.renderStyle=GL2.GL_LINES; // set to see the wireframe float w = (float)(width.get()/2); float d = (float)(depth.get()/2); float h = (float)(height.get()*1.0); int wParts = (int)(w/4)*2; int hParts = (int)(h/8)*2; int dParts = (int)(d/4)*2; Vector3d n=new Vector3d(); Vector3d p0=new Vector3d(); Vector3d p1=new Vector3d(); Vector3d p2=new Vector3d(); Vector3d p3=new Vector3d(); // bottom n.set( 0, 0,-1); p0.set(-w, d,0); p1.set( w, d,0); p2.set( w,-d,0); p3.set(-w,-d,0); addSubdividedPlane(n,p0,p1,p2,p3,wParts,dParts); // top n.set( 0, 0, 1); p0.set( w, d,h); p1.set(-w, d,h); p2.set(-w,-d,h); p3.set( w,-d,h); addSubdividedPlane(n,p0,p1,p2,p3,wParts,dParts); // sides n.set( 0, 1, 0); p0.set(-w, d,h); p1.set( w, d,h); p2.set( w, d,0); p3.set(-w, d,0); addSubdividedPlane(n,p0,p1,p2,p3,wParts,hParts); n.set( 0,-1, 0); p0.set( w,-d,h); p1.set(-w,-d,h); p2.set(-w,-d,0); p3.set( w,-d,0); addSubdividedPlane(n,p0,p1,p2,p3,(int)(w/10),hParts); n.set( 1, 0, 0); p0.set( w, d,0); p1.set( w, d,h); p2.set( w,-d,h); p3.set( w,-d,0); addSubdividedPlane(n,p0,p1,p2,p3,dParts,hParts); n.set(-1, 0, 0); p0.set(-w,-d,h); p1.set(-w, d,h); p2.set(-w, d,0); p3.set(-w,-d,0); addSubdividedPlane(n,p0,p1,p2,p3,dParts,hParts); }
Example 3
Source File: BoxEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
/** * Subdivide a plane into triangles. * @param n plane normal * @param p0 northwest corner * @param p1 northeast corner * @param p2 southeast corner * @param p3 southwest corner * @param xParts east/west divisions * @param yParts north/south divisions */ protected void addSubdividedPlane(Vector3d n, Vector3d p0, Vector3d p1, Vector3d p2, Vector3d p3, int xParts, int yParts) { xParts = Math.max(xParts, 1); yParts = Math.max(yParts, 1); Vector3d pA=new Vector3d(); Vector3d pB=new Vector3d(); Vector3d pC=new Vector3d(); Vector3d pD=new Vector3d(); Vector3d pE=new Vector3d(); Vector3d pF=new Vector3d(); Vector3d pG=new Vector3d(); Vector3d pH=new Vector3d(); for(int x=0;x<xParts;x++) { pA.set(MathHelper.interpolate(p0, p1, (double)(x )/(double)xParts)); pB.set(MathHelper.interpolate(p0, p1, (double)(x+1)/(double)xParts)); pC.set(MathHelper.interpolate(p3, p2, (double)(x )/(double)xParts)); pD.set(MathHelper.interpolate(p3, p2, (double)(x+1)/(double)xParts)); for(int y=0;y<yParts;y++) { pE.set(MathHelper.interpolate(pA, pC, (double)(y )/(double)yParts)); pF.set(MathHelper.interpolate(pB, pD, (double)(y )/(double)yParts)); pG.set(MathHelper.interpolate(pA, pC, (double)(y+1)/(double)yParts)); pH.set(MathHelper.interpolate(pB, pD, (double)(y+1)/(double)yParts)); if(model.renderStyle == GL2.GL_TRIANGLES) { model.hasNormals=true; model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addVertex((float)pE.x, (float)pE.y, (float)pE.z); model.addVertex((float)pF.x, (float)pF.y, (float)pF.z); model.addVertex((float)pH.x, (float)pH.y, (float)pH.z); model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addNormal((float)n.x, (float)n.y, (float)n.z); model.addVertex((float)pE.x, (float)pE.y, (float)pE.z); model.addVertex((float)pH.x, (float)pH.y, (float)pH.z); model.addVertex((float)pG.x, (float)pG.y, (float)pG.z); } else if(model.renderStyle == GL2.GL_LINES) { model.addVertex((float)pF.x, (float)pF.y, (float)pF.z); model.addVertex((float)pH.x, (float)pH.y, (float)pH.z); model.addVertex((float)pH.x, (float)pH.y, (float)pH.z); model.addVertex((float)pE.x, (float)pE.y, (float)pE.z); model.addVertex((float)pH.x, (float)pH.y, (float)pH.z); model.addVertex((float)pG.x, (float)pG.y, (float)pG.z); model.addVertex((float)pG.x, (float)pG.y, (float)pG.z); model.addVertex((float)pE.x, (float)pE.y, (float)pE.z); } } } }
Example 4
Source File: OpenGL.java From gama with GNU General Public License v3.0 | 3 votes |
/** * Draws an arbitrary shape using a set of vertices as input, computing the normal if necessary and drawing the * contour if a border is present * * @param yNegatedVertices * the set of vertices to draw * @param number * the number of vertices to draw. Either 3 (a triangle), 4 (a quad) or -1 (a polygon) * @param solid * whether to draw the shape as a solid shape * @param clockwise * whether to draw the shape in the clockwise direction (the vertices are always oriented clockwise) * @param computeNormal * whether to compute the normal for this shape * @param border * if not null, will be used to draw the contour */ public void drawSimpleShape(final ICoordinates yNegatedVertices, final int number, final boolean solid, final boolean clockwise, final boolean computeNormal, final Color border) { if (solid) { if (computeNormal) { setNormal(yNegatedVertices, clockwise); } final int style = number == 4 ? GL2.GL_QUADS : number == -1 ? GL2.GL_POLYGON : GL2.GL_TRIANGLES; drawVertices(style, yNegatedVertices, number, clockwise); } drawClosedLine(yNegatedVertices, border, -1); }