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

The following examples show how to use com.jogamp.opengl.GL2#glGetIntegerv() . 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: Cuboid.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public void render(GL2 gl2) {
	gl2.glPushMatrix();
		//MatrixHelper.applyMatrix(gl2, poseWorld);

		IntBuffer depthFunc = IntBuffer.allocate(1);
		gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc);
		gl2.glDepthFunc(GL2.GL_ALWAYS);
		
		boolean isLit = gl2.glIsEnabled(GL2.GL_LIGHTING);
		gl2.glDisable(GL2.GL_LIGHTING);
		
		gl2.glColor3d(255,255,255);
		PrimitiveSolids.drawBoxWireframe(gl2, getBoundsBottom(),getBoundsTop());

		if (isLit) gl2.glEnable(GL2.GL_LIGHTING);
		
		gl2.glDepthFunc(depthFunc.get());
	gl2.glPopMatrix();
}
 
Example 2
Source File: ViewportEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public void renderPick(GL2 gl2,double pickX,double pickY) {
       gl2.glMatrixMode(GL2.GL_PROJECTION);
       gl2.glLoadIdentity();
       
       // get the current viewport dimensions to set up the projection matrix
       int[] viewportDimensions = new int[4];
	gl2.glGetIntegerv(GL2.GL_VIEWPORT,viewportDimensions,0);

	GLU glu = GLU.createGLU(gl2);
       
	// Set up a tiny viewport that only covers the area behind the cursor. 
	// Tiny viewports are faster.
	glu.gluPickMatrix(pickX, canvasHeight-pickY, 5.0, 5.0, viewportDimensions,0);

	if(drawOrtho.get()) {
		renderOrtho(gl2);
	} else {
		renderPerspective(gl2);
	}
	
	renderShared(gl2);
}
 
Example 3
Source File: PickingHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * First pass prepare select buffer for select mode by clearing it, prepare openGL to select mode and tell it where
 * should draw object by using gluPickMatrix() method
 * 
 * @return if returned value is true that mean the picking is enabled
 */
public void beginPicking() {
	final GL2 gl = getGL();
	final OpenGL openGL = getOpenGL();
	final CameraHelper camera = getRenderer().getCameraHelper();
	final GLU glu = GLU.createGLU();
	// 1. Selecting buffer
	selectBuffer.clear(); // prepare buffer for new objects
	gl.glSelectBuffer(selectBuffer.capacity(), selectBuffer);
	// Pass below is very similar to refresh method in GLrenderer
	// 2. Take the viewport attributes,
	final int viewport[] = new int[4];
	gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
	// 3. Prepare openGL for rendering in select mode
	gl.glRenderMode(GL2.GL_SELECT);
	/*
	 * The application must redefine the viewing volume so that it renders only a small area around the place where
	 * the mouse was clicked. In order to do that it is necessary to set the matrix mode to GL_PROJECTION.
	 * Afterwards, the application should push the current matrix to save the normal rendering mode settings. Next
	 * initialise the matrix
	 */
	openGL.pushIdentity(GL2.GL_PROJECTION);
	/*
	 * Define the viewing volume so that rendering is done only in a small area around the cursor. gluPickMatrix
	 * method restrict the area where openGL will drawing objects
	 *
	 */
	glu.gluPickMatrix(camera.getMousePosition().x, viewport[3] - camera.getMousePosition().y, 4, 4, viewport, 0);
	// JOGLRenderer r = getRenderer();
	// FIXME Why do we have to call updatePerspective() here ?
	openGL.updatePerspective();
	openGL.matrixMode(GL2.GL_MODELVIEW);
}
 
Example 4
Source File: OpenGL.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reshapes the GL world to comply with a new view size and computes the resulting ratios between pixels and world
 * coordinates
 *
 * @param newGL
 *            the (possibly new) GL2 context
 * @param width
 *            the width of the view (in pixels)
 * @param height
 *            the height of the view (in pixels)
 * @return
 */
public void reshape(final GL2 newGL, final int width, final int height) {
	setGL2(newGL);
	newGL.glViewport(0, 0, width, height);
	viewWidth = width;
	viewHeight = height;
	resetMatrix(GL2.GL_MODELVIEW);
	resetMatrix(GL2.GL_PROJECTION);
	updatePerspective();
	newGL.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
	newGL.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, mvmatrix, 0);
	newGL.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projmatrix, 0);

	final double[] pixelSize = new double[4];
	glu.gluProject(getWorldWidth(), 0, 0, mvmatrix, 0, projmatrix, 0, viewport, 0, pixelSize, 0);
	final double initialEnvWidth = pixelSize[0];
	final double initialEnvHeight = pixelSize[1];
	final double envWidthInPixels = 2 * pixelSize[0] - width;
	final double envHeightInPixels = 2 * pixelSize[1] - height;
	final double windowWidthInModelUnits = getWorldWidth() * width / envWidthInPixels;
	final double windowHeightInModelUnits = getWorldHeight() * height / envHeightInPixels;
	final double xRatio = width / windowWidthInModelUnits / getData().getZoomLevel();
	final double yRatio = height / windowHeightInModelUnits / getData().getZoomLevel();
	if (DEBUG.IS_ON()) {
		debugSizes(width, height, initialEnvWidth, initialEnvHeight, envWidthInPixels, envHeightInPixels,
				getData().getZoomLevel(), xRatio, yRatio);
	}
	ratios.setLocation(xRatio, yRatio, 0d);
}
 
Example 5
Source File: PoseEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void renderLineage(GL2 gl2) {
	boolean isTex = gl2.glIsEnabled(GL2.GL_TEXTURE_2D);
	gl2.glDisable(GL2.GL_TEXTURE_2D);

	// save the lighting mode
	boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_LIGHTING);

	IntBuffer depthFunc = IntBuffer.allocate(1);
	gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc);
	gl2.glDepthFunc(GL2.GL_ALWAYS);
	//boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
	//gl2.glDisable(GL2.GL_DEPTH_TEST);

	gl2.glColor4d(1,1,1,1);
	gl2.glBegin(GL2.GL_LINES);
	// connection to children
	for(Entity e : children ) {
		if(e instanceof PoseEntity) {					
			Vector3d p = ((PoseEntity)e).getPosition();
			gl2.glVertex3d(0, 0, 0);
			gl2.glVertex3d(p.x,p.y,p.z);
		}
	}
	gl2.glEnd();

	//if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST);
	gl2.glDepthFunc(depthFunc.get());
	// restore lighting
	if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING);
	if(isTex) gl2.glDisable(GL2.GL_TEXTURE_2D);
}
 
Example 6
Source File: OpenGLVideoRenderer.java    From sagetv with Apache License 2.0 4 votes vote down vote up
public void initFragmentProgram(GL2 gl)
{
  int[] fragProgTmp = new int[1];
  gl.glGenProgramsARB(1, fragProgTmp, 0);
  fragProg = fragProgTmp[0];
  //	  R = Y + 1.371 (Cr - 128)
  //	  G = Y - 0.698 (Cr - 128) - 0.336 (Cb - 128)
  //	  B = Y + 1.732 (Cb - 128)
  String combineFragProg =
      "!!ARBfp1.0\n" +
          "TEMP texSamp0, texSamp1, texSamp2;\n" +
          "PARAM half = { 0.5, 0.5, 0.5, 0.5 };\n" +
          "PARAM mulY = { 1.0, 1.0, 1.0, 0.0 };\n" +
          "PARAM mulCr = { 1.371, -0.698, 0.0, 0.0 };\n" +
          "PARAM mulCb = { 0.0, -0.336, 1.732, 0.0 };\n" +
          "TEX texSamp0, fragment.texcoord[0], texture[0], RECT;\n" +
          "TEX texSamp1, fragment.texcoord[1], texture[1], RECT;\n" +
          "TEX texSamp2, fragment.texcoord[2], texture[2], RECT;\n" +
          "SUB texSamp1, texSamp1, half;\n" +
          "SUB texSamp2, texSamp2, half;\n" +
          "MUL texSamp0, texSamp0, mulY;\n" +
          "MAD texSamp0, texSamp1, mulCr, texSamp0;\n" +
          "MAD texSamp0, texSamp2, mulCb, texSamp0;\n" +
          "MOV result.color, texSamp0;\n" +
          "END";

  gl.glBindProgramARB  (gl.GL_FRAGMENT_PROGRAM_ARB, fragProg);
  gl.glProgramStringARB(gl.GL_FRAGMENT_PROGRAM_ARB, gl.GL_PROGRAM_FORMAT_ASCII_ARB,
      combineFragProg.length(), combineFragProg);
  int[] errPos = new int[1];
  gl.glGetIntegerv(gl.GL_PROGRAM_ERROR_POSITION_ARB, errPos, 0);
  if (errPos[0] >= 0)
  {
    System.out.println("Fragment program failed to load:");
    String errMsg = gl.glGetString(gl.GL_PROGRAM_ERROR_STRING_ARB);
    if (errMsg == null)
    {
      System.out.println("[No error message available]");
    }
    else
    {
      System.out.println("Error message: \"" + errMsg + "\"");
    }
    System.out.println("Error occurred at position " + errPos[0] + " in program:");
    int endPos = errPos[0];
    while (endPos < combineFragProg.length() && combineFragProg.charAt(endPos) != '\n')
    {
      ++endPos;
    }
    System.out.println(combineFragProg.substring(errPos[0], endPos));
  }
}
 
Example 7
Source File: OpenGLHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
static public int drawAtopEverythingStart(GL2 gl2) {
	IntBuffer depthFunc = IntBuffer.allocate(1);
	gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc);
	gl2.glDepthFunc(GL2.GL_ALWAYS);
	return depthFunc.get();
}
 
Example 8
Source File: DHBuilderApp.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void render(GL2 gl2) {
	gl2.glPushMatrix();
		MatrixHelper.applyMatrix(gl2, pose);
		anchor.render(gl2);
		
		if(!inTest) {
			for( int i=0;i<BONE_NAMES.length;++i) {
				models[i].render(gl2);
			}
		} else {
			links.get(0).render(gl2);
		}
		
		boolean showBones=false;
		if(showBones==true) {
			Vector3d p0 = MatrixHelper.getPosition(this.getPoseWorld());
			for( int i=0;i<BONE_NAMES.length;++i) {
				Matrix4d m = links.get(i).getPoseWorld();
				Vector3d p1 = MatrixHelper.getPosition(m);

				IntBuffer depthFunc = IntBuffer.allocate(1);
				gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc);
				gl2.glDepthFunc(GL2.GL_ALWAYS);
				gl2.glDisable(GL2.GL_TEXTURE_2D);
				gl2.glDisable(GL2.GL_LIGHTING);
				
				gl2.glPushMatrix();
				gl2.glColor3d(1, 1, 1);
				gl2.glBegin(GL2.GL_LINES);
				gl2.glVertex3d(p0.x,p0.y,p0.z);
				gl2.glVertex3d(p1.x,p1.y,p1.z);
				gl2.glEnd();
				p0=p1;
				gl2.glDepthFunc(depthFunc.get());
				
				MatrixHelper.applyMatrix(gl2, m);
				PrimitiveSolids.drawStar(gl2, 15);
				gl2.glPopMatrix();
			}
		}
	gl2.glPopMatrix();
	
	// don't call super.render()
}
 
Example 9
Source File: DragBallEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void render(GL2 gl2) {
	if(subject==null) return;

	gl2.glDisable(GL2.GL_TEXTURE_2D);

	RobotOverlord ro = (RobotOverlord)getRoot();
	ro.viewport.renderChosenProjection(gl2);

	gl2.glPushMatrix();
	
		/*if(isBallHit) {
			Vector3d dp = this.getPosition();
			
			ViewportEntity cameraView = ro.viewport;
			Ray ray = cameraView.rayPick();
			Vector3d dr = ray.getPoint(100);

			gl2.glBegin(GL2.GL_LINES);
			gl2.glColor3d(1, 1, 1);
			gl2.glVertex3d(ray.start.x, ray.start.y, ray.start.z);
			gl2.glVertex3d(dr.x, dr.y, dr.z);

			gl2.glVertex3d(dp.x,dp.y,dp.z);
			gl2.glVertex3d(pickPointOnBall.x, pickPointOnBall.y, pickPointOnBall.z);
			gl2.glEnd();
			
			PrimitiveSolids.drawStar(gl2, dp,10);
			PrimitiveSolids.drawStar(gl2, pickPointOnBall,10);
		}//*/
		
		IntBuffer depthFunc = IntBuffer.allocate(1);
		gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc);
		gl2.glDepthFunc(GL2.GL_ALWAYS);
		//boolean isDepth=gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
		//gl2.glDisable(GL2.GL_DEPTH_TEST);

		boolean isLit = gl2.glIsEnabled(GL2.GL_LIGHTING);
		gl2.glDisable(GL2.GL_LIGHTING);


		IntBuffer lineWidth = IntBuffer.allocate(1);
		gl2.glGetIntegerv(GL2.GL_LINE_WIDTH, lineWidth);
		gl2.glLineWidth(2);

		gl2.glPushMatrix();

			renderOutsideCircle(gl2);

			MatrixHelper.applyMatrix(gl2, FOR);
			gl2.glScaled(ballSize.get(),ballSize.get(),ballSize.get());

			if(isRotateMode()) {
				renderRotation(gl2);
			} else {
				renderTranslation(gl2);
			}
			
		gl2.glPopMatrix();

		// set previous line width
		gl2.glLineWidth(lineWidth.get());
		
		if (isLit) gl2.glEnable(GL2.GL_LIGHTING);

		//if(isDepth) gl2.glEnable(GL2.GL_DEPTH_TEST);
		gl2.glDepthFunc(depthFunc.get());
		
	gl2.glPopMatrix();
}