Java Code Examples for com.jogamp.opengl.GL2#glBegin()

The following examples show how to use com.jogamp.opengl.GL2#glBegin() . 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: Local.java    From aparapi-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Render all particles to the OpenGL context
 * @param gl
 */

protected void render(GL2 gl) {
   gl.glBegin(GL2.GL_QUADS);

   for (int i = 0; i < (range.getGlobalSize(0) * 3); i += 3) {
      gl.glTexCoord2f(0, 1);
      gl.glVertex3f(xyz[i + 0], xyz[i + 1] + 1, xyz[i + 2]);
      gl.glTexCoord2f(0, 0);
      gl.glVertex3f(xyz[i + 0], xyz[i + 1], xyz[i + 2]);
      gl.glTexCoord2f(1, 0);
      gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1], xyz[i + 2]);
      gl.glTexCoord2f(1, 1);
      gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1] + 1, xyz[i + 2]);
   }
   gl.glEnd();
}
 
Example 2
Source File: BasicLine1.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    //gl.glTranslatef(0f, 0f, 2.0f);

    //Draw H  
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3d(-0.9, -0.9, -1);
    gl.glVertex3d(0.9, 0.9, -1);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(1f, 1f, -1f);
    gl.glVertex3f(-1.0f, 1.0f, -1.0f);
    gl.glEnd();

}
 
Example 3
Source File: MatrixHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * See drawMatrix(gl2,p,u,v,w,1)
 * @param gl2
 * @param m
 * @param scale
 */
public static void drawMatrix(GL2 gl2,Matrix4d m,double scale) {
	boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_DEPTH_TEST);
	boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_LIGHTING);
	
	gl2.glPushMatrix();
		gl2.glTranslated(m.m03,m.m13,m.m23);
		gl2.glScaled(scale, scale, scale);
		
		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3f(1,0,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m00,m.m10,m.m20);  // 1,0,0 = red
		gl2.glColor3f(0,1,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m01,m.m11,m.m21);  // 0,1,0 = green 
		gl2.glColor3f(0,0,1);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m02,m.m12,m.m22);  // 0,0,1 = blue
		gl2.glEnd();

	gl2.glPopMatrix();
	if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING);
	if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST);
}
 
Example 4
Source File: PrimitiveSolids.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * draw box based on two corners
 * @param gl2
 * @param bottom minimum bounds
 * @param top maximum bounds
 */
static public void drawBoxWireframe(GL2 gl2,Point3d bottom,Point3d top) {
	gl2.glDisable(GL2.GL_TEXTURE_2D);
	boolean lightWasOn = OpenGLHelper.disableLightingStart(gl2);
	
	double x0=bottom.x;
	double y0=bottom.y;
	double z0=bottom.z;
	double x1=top.x;
	double y1=top.y;
	double z1=top.z;

	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f( 0, 0,-1);	gl2.glVertex3d(x0,y1,z0);	gl2.glVertex3d(x1,y1,z0);	gl2.glVertex3d(x1,y0,z0);	gl2.glVertex3d(x0,y0,z0);	gl2.glEnd();  // bottom	
	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f( 0, 0, 1);	gl2.glVertex3d(x1,y1,z1);	gl2.glVertex3d(x0,y1,z1);	gl2.glVertex3d(x0,y0,z1);	gl2.glVertex3d(x1,y0,z1);	gl2.glEnd();  // top
	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f( 0, 1, 0);	gl2.glVertex3d(x0,y1,z1);	gl2.glVertex3d(x1,y1,z1);	gl2.glVertex3d(x1,y1,z0);	gl2.glVertex3d(x0,y1,z0);	gl2.glEnd();  // side
	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f( 0,-1, 0);	gl2.glVertex3d(x1,y0,z1);	gl2.glVertex3d(x0,y0,z1);	gl2.glVertex3d(x0,y0,z0);	gl2.glVertex3d(x1,y0,z0);	gl2.glEnd();
	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f( 1, 0, 0);	gl2.glVertex3d(x1,y1,z0);	gl2.glVertex3d(x1,y1,z1);	gl2.glVertex3d(x1,y0,z1);	gl2.glVertex3d(x1,y0,z0);	gl2.glEnd();
	gl2.glBegin(GL2.GL_LINE_LOOP);	gl2.glNormal3f(-1, 0, 0);	gl2.glVertex3d(x0,y0,z1);	gl2.glVertex3d(x0,y1,z1);	gl2.glVertex3d(x0,y1,z0);	gl2.glVertex3d(x0,y0,z0);	gl2.glEnd();

	OpenGLHelper.disableLightingEnd(gl2,lightWasOn);
}
 
Example 5
Source File: Main.java    From aparapi-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Render all particles to the OpenGL context
 * 
 * @param gl
 */

protected void render(GL2 gl) {
   gl.glBegin(GL2.GL_QUADS);
   int sz = range.getGlobalSize(0);
   for (int i = 0; i < sz; i++) {

      Body currBody = bodies[i];
      if(currBody.isHeavy())
         gl.glColor3f(1f, 0f, 0f);
      else
         gl.glColor3f(0f, 0f, 1f);

      gl.glTexCoord2f(0, 1);
      gl.glVertex3f(currBody.getX(), currBody.getY() + 1, currBody.getZ());
      gl.glTexCoord2f(0, 0);
      gl.glVertex3f(currBody.getX(), currBody.getY(), currBody.getZ());
      gl.glTexCoord2f(1, 0);
      gl.glVertex3f(currBody.getX() + 1, currBody.getY(), currBody.getZ());
      gl.glTexCoord2f(1, 1);
      gl.glVertex3f(currBody.getX() + 1, currBody.getY() + 1, currBody.getZ());

   }
   gl.glEnd();
}
 
Example 6
Source File: ArrowHead.java    From depan with Apache License 2.0 6 votes vote down vote up
/**
 * Draws and fills an arrowhead on the given <code>GL</code> instantiation.
 * The actual shape depends on the Arrowhead object that is being drawn.
 *
 * @param gl Graphics object that will draw this object.
 */
@Override
public void fill(GL2 gl) {
  // points must be use with the correct order (2-3-0-1) to use triangle fan.
  gl.glPushMatrix();
  float[] translate = GLScene.P(translateX, translateY);
  gl.glTranslatef(translate[0], translate[1], translate[2]);
  gl.glScalef(scaleX, scaleY, scaleZ);
  gl.glRotated(rotation * 180 / Math.PI, 0, 0, 1);
  gl.glBegin(GL2.GL_TRIANGLE_FAN);
  GLPanel.V(gl, controlPoints[2].x, controlPoints[2].y);
  // check if there exists 4 points before drawing the 4th point
  if (controlPoints.length == 4) {
    GLPanel.V(gl, controlPoints[3].x, controlPoints[3].y);
  }
  GLPanel.V(gl, controlPoints[0].x, controlPoints[0].y);
  GLPanel.V(gl, controlPoints[1].x, controlPoints[1].y);
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example 7
Source File: DragBallEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
protected void renderTranslationHandle(GL2 gl2,Vector3d n) {
	// draw line to box
	gl2.glBegin(GL2.GL_LINES);
	gl2.glVertex3d(0,0,0);
	gl2.glVertex3d(n.x,n.y,n.z);
	gl2.glEnd();

	// draw box
	Point3d b0 = new Point3d(+0.05,+0.05,+0.05); 
	Point3d b1 = new Point3d(-0.05,-0.05,-0.05);

	b0.scale(1);
	b1.scale(1);
	b0.add(n);
	b1.add(n);
	PrimitiveSolids.drawBox(gl2, b0,b1);
}
 
Example 8
Source File: Bezier3ControlPoint.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * visualize the line in opengl
 * @param gl2
 */
public void render(GL2 gl2) {
	//Vector3f u,v,w;
	
	//MatrixHelper.drawMatrix(gl2, position.interpolate(0), u, v, w);
	//MatrixHelper.drawMatrix(gl2, position.interpolate(1), u, v, w);
	boolean isLit = gl2.glIsEnabled(GL2.GL_LIGHTING);
	boolean isCM =  gl2.glIsEnabled(GL2.GL_COLOR_MATERIAL);
	boolean isDepth =  gl2.glIsEnabled(GL2.GL_DEPTH_TEST);

	gl2.glEnable(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_COLOR_MATERIAL);
	
	//*
	gl2.glColor4f(0, 0, 1, 1);
	gl2.glBegin(GL2.GL_LINES);
	gl2.glVertex3f(position.p0.x,position.p0.y,position.p0.z);
	gl2.glVertex3f(position.p1.x,position.p1.y,position.p1.z);
	
	gl2.glVertex3f(position.p2.x,position.p2.y,position.p2.z);
	gl2.glVertex3f(position.p3.x,position.p3.y,position.p3.z);
	gl2.glEnd();
	//*/
	
	gl2.glColor4f(0, 1, 0, 1);
	gl2.glBegin(GL2.GL_LINE_STRIP);
	final float NUM_STEPS=20;
	for(float i=0;i<=NUM_STEPS;++i) {
		Vector3f ipos = position.interpolate(i/NUM_STEPS);
		gl2.glVertex3f(ipos.x,ipos.y,ipos.z);
	}
	gl2.glEnd();
	
	if(isLit) gl2.glEnable(GL2.GL_LIGHTING);
	if(isCM) gl2.glEnable(GL2.GL_COLOR_MATERIAL);
	if(!isDepth) gl2.glDisable(GL2.GL_DEPTH_TEST);
}
 
Example 9
Source File: OpenGLGFXCMD.java    From sagetv with Apache License 2.0 5 votes vote down vote up
private void drawGLCurve(GL2 gl, float x, float y, float width, float height,
    float angs, float ange, int subdiv, int tlc, int trc, int brc, int blc,
    int xc, int yc, int widthc, int heightc, boolean full,
    int thickness)
{
  if(full)
  {
    gl.glBegin(gl.GL_TRIANGLE_FAN);
    setInterpolatedGLColor(gl, tlc, trc, brc, blc,
        x-xc, y-yc, widthc, heightc);
    gl.glVertex2f(x, y);
  }
  else
  {
    gl.glLineWidth(thickness);
    gl.glBegin(gl.GL_LINE_STRIP);
  }

  for(int i=0; i<=subdiv; i++)
  {
    float posx, posy;
    float ang=angs+(ange-angs)*i/subdiv;
    posx=width * (float)java.lang.Math.cos(ang);
    posy=height * (float)java.lang.Math.sin(ang);
    setInterpolatedGLColor(gl, tlc, trc, brc, blc,
        posx+x-xc, posy+y-yc, widthc, heightc);
    gl.glVertex2f(x + posx, y + posy);
    //System.out.println("x: "+(x+posx)+" y: "+(y+posy));
  }
  gl.glEnd();
}
 
Example 10
Source File: CubeSample2.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public void display(GLAutoDrawable drawable) {
		GL2 gl = drawable.getGL().getGL2();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);

		gl.glLoadIdentity();

		// 視点位置と視線方向
//		glu.gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

		// 図形の回転
		gl.glTranslatef(0.5f, 0.5f, 0.5f);
		gl.glRotatef(r, 0.0f, 1.0f, 0.0f);
		gl.glTranslatef(-0.5f, -0.5f, -0.5f);
		// 図形の描画
		gl.glColor3f(0.0f, 0.0f, 0.0f);
		gl.glBegin(GL_LINES);
		for (int i = 0; i < 12; i++) {
			gl.glVertex3fv(vertex[edge[i][0]], 0);
			gl.glVertex3fv(vertex[edge[i][1]], 0);
		}
		gl.glEnd();

		//一周回ったら回転角を 0 に戻す
		if (r++ >= 360.0f) r = 0;
		System.out.println("anim:" + animator.isAnimating() + ", r:" + r);
		if(willAnimatorPause) {
			animator.pause();
			System.out.println("animoator paused:");
			willAnimatorPause = false;
		}
		drawable.swapBuffers();
	}
 
Example 11
Source File: PrimitiveSolids.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draw a grid of lines in the current color
 * @param gl2 the render context
 * @param gridWidth the dimensions of the grid
 * @param gridHeight the dimensions of the grid
 * @param grid_space the distance between lines on the grid.
 */
static public void drawGrid(GL2 gl2,int gridWidth,int gridHeight,int grid_space) {
	gl2.glNormal3f(0,0,1);

	//boolean isBlend = gl2.glIsEnabled(GL2.GL_BLEND);
    //gl2.glEnable(GL2.GL_BLEND);
    //gl2.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
	gl2.glBegin(GL2.GL_LINES);
	gridWidth/=2;
	gridHeight/=2;
	
	for(int i=-gridWidth;i<=gridWidth;i+=grid_space) {
		//end = 0.5f-((float)Math.abs(i)/(float)(gridHeight))*0.5f;
		gl2.glVertex2f(i,-gridHeight);
		gl2.glVertex2f(i, 0         );
		gl2.glVertex2f(i, 0         );
		gl2.glVertex2f(i, gridHeight);
	}
	for(int i=-gridHeight;i<=gridHeight;i+=grid_space) {
		gl2.glVertex2f(-gridWidth,i);
		gl2.glVertex2f( 0        ,i);
		gl2.glVertex2f( 0        ,i);
		gl2.glVertex2f( gridWidth,i);
	}
	gl2.glEnd();
	
	//if(!isBlend) gl2.glDisable(GL2.GL_BLEND);
}
 
Example 12
Source File: PrimitiveSolids.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
static public void drawCircleXZ(GL2 gl2,double radius,int steps) {
	double stepSize = Math.PI*2 / (double)(steps+1);
	
	gl2.glBegin(GL2.GL_LINE_LOOP);
	for(double n=0;n<Math.PI*2;n+=stepSize) {
		double c = Math.cos(n);
		double s = Math.sin(n);
		gl2.glVertex3d(c*radius,0, s*radius);
	}
	gl2.glEnd();
}
 
Example 13
Source File: Ray.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void render(GL2 gl2) {
	gl2.glBegin(GL2.GL_LINES);
	gl2.glColor3d(1,0,0); 
	gl2.glVertex3d(start.x, start.y, start.z);
	gl2.glColor3d(0,1,0);
	gl2.glVertex3d(
			start.x+direction.x*50,
			start.y+direction.y*50, 
			start.z+direction.z*50);
}
 
Example 14
Source File: CubeTexture.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void drawImage(GL2 gl) {        
    
    gl.glColor3f(1f, 1f, 1f);
    gl.glBindTexture(GL2.GL_TEXTURE_2D, texture);
    gl.glBegin(GL2.GL_QUADS);
    // Front Face
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    // Back Face
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(1.0f, 1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    // Top Face
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(1.0f, 1.0f, -1.0f);
    // Bottom Face
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    // Right face
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(1.0f, 1.0f, -1.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    // Left Face
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, -1.0f);
    gl.glEnd();
}
 
Example 15
Source File: OpenGLVideoRenderer.java    From sagetv with Apache License 2.0 4 votes vote down vote up
public void renderFragmentProgram(GL2 gl, java.awt.Rectangle srcVideoRect, java.awt.Rectangle currVideoBounds)
{
  gl.glEnable(gl.GL_FRAGMENT_PROGRAM_ARB);
  gl.glBindProgramARB(gl.GL_FRAGMENT_PROGRAM_ARB, fragProg);
  gl.glActiveTexture(gl.GL_TEXTURE0);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,videot[0]);
  gl.glActiveTexture(gl.GL_TEXTURE1);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,videot[1]);
  gl.glActiveTexture(gl.GL_TEXTURE2);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,videot[2]);
  gl.glDisable(gl.GL_BLEND);
  gl.glColor4f(1,1,1,1);
  gl.glBegin(gl.GL_QUADS);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE0, srcVideoRect.x, srcVideoRect.y);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE1, srcVideoRect.x/2, srcVideoRect.y/2);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE2, srcVideoRect.x/2, srcVideoRect.y/2);
  gl.glVertex3f(currVideoBounds.x, currVideoBounds.y, 1.0f);

  gl.glMultiTexCoord2f(gl.GL_TEXTURE0, srcVideoRect.x+srcVideoRect.width, srcVideoRect.y);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE1, (srcVideoRect.x+srcVideoRect.width)/2, srcVideoRect.y/2);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE2, (srcVideoRect.x+srcVideoRect.width)/2, srcVideoRect.y/2);
  gl.glVertex3f(currVideoBounds.x+currVideoBounds.width, currVideoBounds.y, 1.0f);

  gl.glMultiTexCoord2f(gl.GL_TEXTURE0, srcVideoRect.x+srcVideoRect.width, srcVideoRect.y + srcVideoRect.height);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE1, (srcVideoRect.x+srcVideoRect.width)/2, (srcVideoRect.y + srcVideoRect.height)/2);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE2, (srcVideoRect.x+srcVideoRect.width)/2, (srcVideoRect.y + srcVideoRect.height)/2);
  gl.glVertex3f(currVideoBounds.x+currVideoBounds.width,
      currVideoBounds.y+currVideoBounds.height, 1.0f);

  gl.glMultiTexCoord2f(gl.GL_TEXTURE0, srcVideoRect.x, srcVideoRect.y + srcVideoRect.height);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE1, srcVideoRect.x/2, (srcVideoRect.y + srcVideoRect.height)/2);
  gl.glMultiTexCoord2f(gl.GL_TEXTURE2, srcVideoRect.x/2, (srcVideoRect.y + srcVideoRect.height)/2);
  gl.glVertex3f(currVideoBounds.x, currVideoBounds.y+currVideoBounds.height, 1.0f);
  gl.glEnd();
  gl.glActiveTexture(gl.GL_TEXTURE2);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  gl.glActiveTexture(gl.GL_TEXTURE1);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  gl.glActiveTexture(gl.GL_TEXTURE0);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  gl.glDisable(gl.GL_FRAGMENT_PROGRAM_ARB);
}
 
Example 16
Source File: DrawingPlugin.java    From depan with Apache License 2.0 4 votes vote down vote up
/**
 * Draw a node.
 */
@Override
public boolean apply(NodeRenderingProperty property) {
  if (!property.isVisible) {
    return false;
  }
  GL2 gl = scene.gl;
  gl.glPushMatrix();
  gl.glPushName(property.shapeId);

  // move
  property.shape.setTranslation(property.positionX * GLConstants.FACTOR,
      property.positionY * GLConstants.FACTOR, 0f);

  // scale
  property.shape.setScale(property.size,
      property.size * property.ratio, property.size);

  // fill the shape
  if (property.isFilled) {
    gl.glColor4f(property.fillColor.getRed() / 255f,
        property.fillColor.getGreen() / 255f,
        property.fillColor.getBlue() / 255f,
        property.fillColor.getAlpha() / 255f);
    property.shape.fill(gl);
  }

  // draw the border
  if (property.strokeWidth > 0.0f) {
    gl.glLineWidth(property.strokeWidth);
    gl.glColor4f(property.strokeColor.getRed() / 255f,
        property.strokeColor.getGreen() / 255f,
        property.strokeColor.getBlue() / 255f,
        property.strokeColor.getAlpha() / 255f);
    property.shape.draw(gl);
  }

  Rectangle2D bounds = property.shape.getDrawingBounds();
  updateDrawingBounds(bounds);

  // we don't want the label to be clickable,
  // so we just pop the name before drawing it.
  gl.glPopName();

  // draw the label
  if (property.isTextVisible) {
    paintLabel(property);
  }

  // draw a little "+" on the top right corner of the node if it has
  // nodes collapsed under.
  if (property.hasCollapsedNodeUnder) {
    double centerX = property.positionX+property.size/2;
    double centerY = property.positionY+property.size/2;
    double halfWidth = 0.7;
    double halfHeight = 4;
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor4f(1f, 1f, 1f, 0.5f);
    // vertical line
    gl.glVertex2d(centerX - halfWidth, centerY + halfHeight);
    gl.glVertex2d(centerX + halfWidth, centerY + halfHeight);
    gl.glVertex2d(centerX + halfWidth, centerY - halfHeight);
    gl.glVertex2d(centerX - halfWidth, centerY - halfHeight);
    // left part of horizontal line
    gl.glVertex2d(centerX - halfHeight, centerY + halfWidth);
    gl.glVertex2d(centerX - halfWidth, centerY + halfWidth);
    gl.glVertex2d(centerX - halfWidth, centerY - halfWidth);
    gl.glVertex2d(centerX - halfHeight, centerY - halfWidth);
    // right part.
    gl.glVertex2d(centerX + halfWidth, centerY + halfWidth);
    gl.glVertex2d(centerX + halfHeight, centerY + halfWidth);
    gl.glVertex2d(centerX + halfHeight, centerY - halfWidth);
    gl.glVertex2d(centerX + halfWidth, centerY - halfWidth);
    gl.glVertex3d(0, 0, 0);
    gl.glEnd();
  }

  gl.glPopMatrix();

  return true;
}
 
Example 17
Source File: JCuboid.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable) {

    final GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0f, 0f, -5.0f);

    gl.glRotatef(rotation, 1.0f, 1.0f, 1.0f);

    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(1f, 0f, 0f); //red color  

    //Top  
    gl.glVertex3f(-1f, 0.8f, 0.5f);
    gl.glVertex3f(-0.5f, 0.8f, 0.5f);
    gl.glVertex3f(-1f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);

    //Bottom  
    gl.glVertex3f(-1f, 0.8f, 0.9f);
    gl.glVertex3f(-1f, 0.5f, 0.9f);
    gl.glVertex3f(-0.5f, 0.5f, 0.9f);
    gl.glVertex3f(-0.5f, 0.8f, 0.9f);

    //Front  
    gl.glVertex3f(-0.5f, 0.8f, 0.5f);
    gl.glVertex3f(-1f, 0.8f, 0.5f);
    gl.glVertex3f(-1f, 0.8f, 0.9f);
    gl.glVertex3f(-0.5f, 0.8f, 0.9f);
    //Back  

    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-1f, 0.5f, 0.5f);
    gl.glVertex3f(-1f, 0.5f, 0.9f);
    gl.glVertex3f(-0.5f, 0.5f, 0.9f);

    //Left  
    gl.glVertex3f(-0.5f, 0.8f, 0.9f);
    gl.glVertex3f(-0.5f, 0.8f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, 0.9f);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);

    //Right  
    gl.glVertex3f(-1f, 0.8f, 0.9f);
    gl.glVertex3f(-1f, 0.8f, 0.5f);
    gl.glVertex3f(-1f, 0.5f, 0.5f);
    gl.glVertex3f(-1f, 0.5f, 0.9f);
    gl.glEnd();
    gl.glFlush();

    rotation -= 0.15f;
}
 
Example 18
Source File: JQuad.java    From MeteoInfo with GNU Lesser General Public License v3.0 3 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable) {

    final GL2 gl = drawable.getGL().getGL2();

    gl.glBegin(GL2.GL_QUADS);

    gl.glVertex3f(0.0f, 0.5f, 0);
    gl.glVertex3f(-0.5f, 0f, 0);
    gl.glVertex3f(0f, -0.5f, 0);
    gl.glVertex3f(0.5f, 0f, 0);

    gl.glEnd();

}
 
Example 19
Source File: AWTShape.java    From depan with Apache License 2.0 2 votes vote down vote up
/**
 * Static method that can be used to fill a normal AWT shape.
 * Only simple shapes can be rendered correctly.
 *
 * @param gl
 * @param s the shape to render.
 */
public static void fill(GL2 gl, Shape s) {
  gl.glBegin(GL2.GL_TRIANGLE_FAN);
  drawShape(gl, s);
  gl.glEnd();
}
 
Example 20
Source File: AWTShape.java    From depan with Apache License 2.0 2 votes vote down vote up
/**
 * Static method that can be used to render the path of a normal AWT shape.
 * Only simple shapes can be rendered correctly.
 *
 * @param gl
 * @param s the shape to render.
 */
public static void draw(GL2 gl, Shape s) {
  gl.glBegin(GL2.GL_LINE_STRIP);
  drawShape(gl, s);
  gl.glEnd();
}