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

The following examples show how to use com.jogamp.opengl.GL2#glClear() . 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: JRotation.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.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    // Clear The Screen And The Depth Buffer   
    gl.glLoadIdentity();  // Reset The View       

    //triangle rotation        
    gl.glRotatef(rotation, 0.0f, 1.0f, 0.0f);

    gl.glBegin(GL2.GL_TRIANGLES);
    //Green Color  
    gl.glColor3f(0.0f, 1.0f, 0.0f);
    gl.glVertex2d(0, 0.5);
    gl.glVertex2d(-0.5, -0.5);
    gl.glVertex2d(0.5, -0.5);

    gl.glEnd();

    gl.glFlush();
    //Assign the angle  
    rotation += 0.6f;
}
 
Example 2
Source File: CubeTexture.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.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();                       // Reset The View
    gl.glTranslatef(0f, 0f, -5.0f);
    gl.glRotatef(xrot, 1.0f, 1.0f, 1.0f);
    gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f);
    
    //drawImage(gl);
    this.drawBoxGridsTicksLabels(gl);        
    drawImage(gl);
    
    gl.glFlush();
    //change the speeds here  
    xrot += .1f;
    yrot += .1f;
    zrot += .1f;
}
 
Example 3
Source File: OpenGLGFXCMD.java    From sagetv with Apache License 2.0 6 votes vote down vote up
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
  GL2 gl;
  System.out.println("reshape "+x+","+y+" "+width+","+height);
  gl = drawable.getGL().getGL2();
  newosdwidth=width;
  newosdheight=height;
  gl.glViewport(0, 0, newosdwidth, newosdheight);
  gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(0,newosdwidth,newosdheight,0,-1.0,1.0);
  gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
  gl.glLoadIdentity();
  gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
  gl.glClear( gl.GL_COLOR_BUFFER_BIT);
  synchronized(newpbufferlock)
  {
    newpbuffer=true;
  }
  myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight()));
}
 
Example 4
Source File: KeystoneHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings ("restriction")
public void beginRenderToTexture() {
	final GL2 gl = getGL();
	gl.glClearColor(0, 0, 0, 1.0f);
	gl.glClear(GL2.GL_STENCIL_BUFFER_BIT | GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
	if (fboScene == null) {
		fboScene = new FrameBufferObject(gl, getViewWidth(), getViewHeight());
	}
	// redirect the rendering to the fbo_scene (will be rendered later, as a texture)
	fboScene.bindFrameBuffer();

}
 
Example 5
Source File: JPaddle.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(GL2.GL_COLOR_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0f, 0f, -2.0f);
    gl.glRotatef(rotation, 1f, 0f, 0f);

    gl.glColor3f(1f, 0f, 0f);
    gl.glBegin(GL2.GL_POLYGON);
    gl.glVertex3d(-0.5, 0.3, 0.8);
    gl.glVertex3d(0.5, 0.3, 0.8);
    gl.glVertex3d(0.8, 0.7, 0.8);
    gl.glVertex3d(-0.8, 0.7, 0.8);
    gl.glEnd();

    int paddles = 40;
    for (int i = 0; i < paddles; i++) {
        gl.glRotated(360.0 / paddles, 1, 0, 0);
        gl.glBegin(GL2.GL_POLYGON);
        gl.glVertex3d(-0.5, 0.3, 0.8);
        gl.glVertex3d(0.5, 0.3, 0.8);
        gl.glVertex3d(0.8, 0.7, 0.8);
        gl.glVertex3d(-0.8, 0.7, 0.8);

        gl.glEnd();

    }

    rotation -= 0.2f;

}
 
Example 6
Source File: JLight.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable) {

    final GL2 gl = drawable.getGL().getGL2();
    gl.glColor3f(1f, 0f, 0f);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glRotatef(rotation, 1.0f, 1.0f, 0.0f);

    gl.glBegin(GL2.GL_TRIANGLES);

    gl.glVertex2d(0, 0.5);

    gl.glVertex2d(-0.5, -0.5);

    gl.glVertex2d(0.5, -0.5);

    gl.glEnd();

    gl.glFlush();
    //Angle  
    rotation += 0.6f;

    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_DEPTH_TEST);

    float[] ambientLight = {0f, 0f, 1f, 0f};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambientLight, 0);

    float[] specularLight = {1f, 0f, 0f, 0f};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, specularLight, 0);

    float[] diffuseLight = {1f, 0f, 0f, 0f};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuseLight, 0);
}
 
Example 7
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 8
Source File: OneTriangle.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static void render( GL2 gl2, int width, int height ) {
    gl2.glClear( GL.GL_COLOR_BUFFER_BIT );

    // draw a triangle filling the window
    gl2.glLoadIdentity();
    gl2.glBegin( GL.GL_TRIANGLES );
    gl2.glColor3f( 1, 0, 0 );
    gl2.glVertex2f( 0, 0 );
    gl2.glColor3f( 0, 1, 0 );
    gl2.glVertex2f( width, 0 );
    gl2.glColor3f( 0, 0, 1 );
    gl2.glVertex2f( width / 2, height );
    gl2.glEnd();
}
 
Example 9
Source File: ViewCubeEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void render(GL2 gl2) {
	RobotOverlord ro = (RobotOverlord)getRoot();
	ViewportEntity cameraView = ro.viewport;
	
	gl2.glClear(GL2.GL_DEPTH_BUFFER_BIT);

	gl2.glEnable(GL2.GL_DEPTH_TEST);
	gl2.glEnable(GL2.GL_CULL_FACE);
	
	gl2.glBlendFunc(GL2.GL_SRC_ALPHA,GL2.GL_ONE_MINUS_SRC_ALPHA);

   	gl2.glMatrixMode(GL2.GL_PROJECTION);
	gl2.glPushMatrix();
	cameraView.renderOrtho(gl2,1);
	gl2.glMatrixMode(GL2.GL_MODELVIEW);
	
	gl2.glPushMatrix();			
		double c = cubeSize.get();			
		PoseEntity camera = cameraView.getAttachedTo();
		Matrix4d m = camera.getPoseWorld();
		Vector3d p = camera.getPosition();
		Vector3d vx = MatrixHelper.getXAxis(m);
		Vector3d vy = MatrixHelper.getYAxis(m);
		Vector3d vz = MatrixHelper.getZAxis(m);
	
		vz.scale(-100);
		vx.scale(cameraView.getCanvasWidth() /10 -c*2);
		vy.scale(cameraView.getCanvasHeight()/10 -c*2);
		p.add(vx);
		p.add(vy);
		p.add(vz);
		
		gl2.glTranslated(p.x, p.y, p.z);
		gl2.glScaled(c,c,c);

		model.render(gl2);

		gl2.glDisable(GL2.GL_LIGHTING);
		gl2.glDisable(GL2.GL_COLOR_MATERIAL);
		gl2.glDisable(GL2.GL_TEXTURE_2D);
		
		// the big lines
		gl2.glLineWidth(4);
		gl2.glPushMatrix();
			gl2.glTranslated(-1.05,-1.05,-0.95);
			gl2.glBegin(GL2.GL_LINES);
			gl2.glColor3d(1, 0, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(2.5, 0, 0);
			gl2.glColor3d(0, 1, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, 2.5, 0);
			gl2.glColor3d(0, 0, 1);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, 0, 2.5);
			gl2.glEnd();
		gl2.glPopMatrix();
		gl2.glLineWidth(1);
					
	gl2.glPopMatrix();

   	gl2.glMatrixMode(GL2.GL_PROJECTION);
	gl2.glPopMatrix();
	gl2.glMatrixMode(GL2.GL_MODELVIEW);
}
 
Example 10
Source File: Tessellation.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    gl.glColor3f(1.0f, 1.0f, 1.0f);
    
    /*
 * jogl specific addition for tessellation
     */
    tessellCallBack tessCallback = new tessellCallBack(gl, glu);

    double rect[][] = new double[][]{ // [4][3] in C; reverse here
        {50.0, 50.0, 0.0},
        {200.0, 50.0, 0.0},
        {200.0, 200.0, 0.0},
        {50.0, 200.0, 0.0}};
    double tri[][] = new double[][]{// [3][3]
        {75.0, 75.0, 0.0},
        {125.0, 175.0, 0.0},
        {175.0, 75.0, 0.0}};
    double star[][] = new double[][]{// [5][6]; 6x5 in java
        {250.0, 50.0, 0.0, 1.0, 0.0, 1.0},
        {325.0, 200.0, 0.0, 1.0, 1.0, 0.0},
        {400.0, 50.0, 0.0, 0.0, 1.0, 1.0},
        {250.0, 150.0, 0.0, 1.0, 0.0, 0.0},
        {400.0, 150.0, 0.0, 0.0, 1.0, 0.0}};

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    startList = gl.glGenLists(2);

    GLUtessellator tobj = glu.gluNewTess();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback);// glVertex3dv);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback);// beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback);// endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback);// errorCallback);

    /* rectangle with triangular hole inside */
    gl.glNewList(startList, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_FLAT);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, rect[0], 0, rect[0]);
    glu.gluTessVertex(tobj, rect[1], 0, rect[1]);
    glu.gluTessVertex(tobj, rect[2], 0, rect[2]);
    glu.gluTessVertex(tobj, rect[3], 0, rect[3]);
    glu.gluTessEndContour(tobj);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, tri[0], 0, tri[0]);
    glu.gluTessVertex(tobj, tri[1], 0, tri[1]);
    glu.gluTessVertex(tobj, tri[2], 0, tri[2]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback);// vertexCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback);// beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback);// endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback);// errorCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_COMBINE, tessCallback);// combineCallback);

    /* smooth shaded, self-intersecting star */
    gl.glNewList(startList + 1, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_SMOOTH);
    glu.gluTessProperty(tobj, //
            GLU.GLU_TESS_WINDING_RULE, //
            GLU.GLU_TESS_WINDING_POSITIVE);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, star[0], 0, star[0]);
    glu.gluTessVertex(tobj, star[1], 0, star[1]);
    glu.gluTessVertex(tobj, star[2], 0, star[2]);
    glu.gluTessVertex(tobj, star[3], 0, star[3]);
    glu.gluTessVertex(tobj, star[4], 0, star[4]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();
    glu.gluDeleteTess(tobj);
    
    gl.glCallList(startList);
    gl.glCallList(startList + 1);
    gl.glFlush();
}
 
Example 11
Source File: OpenGLGFXCMD.java    From sagetv with Apache License 2.0 4 votes vote down vote up
private void initpbuffer()
{
  GL2 gl;
  System.out.println("initpbuffer");
  osdwidth=newosdwidth;
  osdheight=newosdheight;
  GLCapabilities caps = new GLCapabilities(null);
  caps.setHardwareAccelerated(true);
  caps.setDoubleBuffered(false);
  caps.setAlphaBits(8);
  caps.setRedBits(8);
  caps.setGreenBits(8);
  caps.setBlueBits(8);
  caps.setDepthBits(0);
  caps.setFBO(false);
  System.out.println("initpbuffer2");
  if (!GLDrawableFactory.getFactory(caps.getGLProfile()).canCreateGLPbuffer(null, caps.getGLProfile()))
  {
    throw new GLException("pbuffers unsupported");
  }
  if(pbuffer!=null) pbuffer.destroy();
  System.out.println("initpbuffer3");
  pbuffer = GLDrawableFactory.getFactory(caps.getGLProfile()).createOffscreenAutoDrawable(null,
      caps,
      null,
      osdwidth,
      osdheight
      );
  pbuffer.setContext(pbuffer.createContext(c.getContext()), true);
  //pbuffer.setContext(c.getContext(), false);
  System.out.println("initpbuffer4: pbuffers is null? " + (pbuffer==null));
  if(pbuffer.getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)
  {
    System.out.println("Couldn't make pbuffer current?");
    return;
  }
  System.out.println("initpbuffer5");
  gl = pbuffer.getGL().getGL2();

  gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);

  gl.glClear( gl.GL_COLOR_BUFFER_BIT);

  gl.glViewport(0, 0, osdwidth, osdheight);
  gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
  gl.glLoadIdentity();
  gl.glOrtho(0,osdwidth,0,osdheight,-1.0,1.0);
  gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
  gl.glLoadIdentity();

  // TODO: look into reusing same texture like OSX version...
  if(osdt!=null) gl.glDeleteTextures(1, osdt, 0);
  osdt = new int[1];
  byte img[] = new byte[osdwidth*osdheight*4];
  gl.glGenTextures(1, osdt, 0);
  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,osdt[0]);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
  gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
  gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 4, osdwidth, osdheight, 0,
      gl.GL_BGRA, bigendian ? gl.GL_UNSIGNED_INT_8_8_8_8_REV : gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));

  gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
  gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, osdt[0]);
  gl.glCopyTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, 0, 0, osdwidth, osdheight);
  gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  System.out.println("initpbuffer6");
  pbuffer.getContext().release();
  System.out.println("initpbuffer7");
}
 
Example 12
Source File: OpenGLVideoRenderer.java    From sagetv with Apache License 2.0 4 votes vote down vote up
public boolean drawVideo(GL2 gl, java.awt.Rectangle srcVideoRect, java.awt.Rectangle currVideoBounds)
{
  if(activevideo && pureNativeMode) {
    try {
      drawVideo0(srcVideoRect, currVideoBounds);
    } catch(Throwable t) {}
    return true;
  } else if(activevideo && videot!=null && currVideoBounds!=null)
  {
    if (srcVideoRect == null)
      srcVideoRect = new java.awt.Rectangle(0, 0, videowidth, videoheight);
    if(videoMode==0)
    {
      String rndrStr = gl.glGetString(gl.GL_RENDERER).toUpperCase();
      String vendrStr = gl.glGetString(gl.GL_VENDOR).toUpperCase();
      if(gl.isExtensionAvailable("GL_ARB_fragment_program"))
      {
        System.out.println("Using fragment program mode\n");
        videoMode=1;
        initFragmentProgram(gl);
      }
      // JFT: those are not supported anymore in recent jogl
      /*else if(gl.isExtensionAvailable("GL_ATI_text_fragment_shader"))
		{
			System.out.println("Using ATI mode\n");
			videoMode=2;
			initATIFragmentProgram(gl);
		}
		else if(gl.isExtensionAvailable("GL_NV_register_combiners"))
		{
			System.out.println("Using  NV_register_combiners mode\n");
			videoMode=3;
			initNVCombiner(gl);
		}*/
      else
      {
        System.out.println("Couldn't find fragment program extension? No video will be shown\n");
        videoMode=9;
      }
    }
    switch(videoMode)
    {
      case 0:
        gl.glClear( gl.GL_COLOR_BUFFER_BIT);
        break;
      case 1:
        renderFragmentProgram(gl, srcVideoRect, currVideoBounds);
        break;
        /*case 2:
			renderATIFragmentProgram(gl, srcVideoRect, currVideoBounds);
			break;
		case 3:
			renderNVCombiner(gl, srcVideoRect, currVideoBounds);
			break;*/
      case 9:
        gl.glClear( gl.GL_COLOR_BUFFER_BIT);
        break;
    }
    return true;
  }
  else
  {
    gl.glClear(gl.GL_COLOR_BUFFER_BIT);
    return false;
  }
}
 
Example 13
Source File: JCudaDriverVolumeRendererJOGL.java    From jcuda-samples with MIT License 4 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable)
{
    GL2 gl = drawable.getGL().getGL2();

    // Use OpenGL to build view matrix
    float modelView[] = new float[16];
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glRotatef(-simpleInteraction.getRotationDegX(), 1.0f, 0.0f, 0.0f);
    gl.glRotatef(-simpleInteraction.getRotationDegY(), 0.0f, 1.0f, 0.0f);
    gl.glTranslatef(
        -simpleInteraction.getTranslationX(), 
        -simpleInteraction.getTranslationY(), 
        -simpleInteraction.getTranslationZ());
    gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelView, 0);
    gl.glPopMatrix();

    // Build the inverted view matrix
    invViewMatrix[0] = modelView[0];
    invViewMatrix[1] = modelView[4];
    invViewMatrix[2] = modelView[8];
    invViewMatrix[3] = modelView[12];
    invViewMatrix[4] = modelView[1];
    invViewMatrix[5] = modelView[5];
    invViewMatrix[6] = modelView[9];
    invViewMatrix[7] = modelView[13];
    invViewMatrix[8] = modelView[2];
    invViewMatrix[9] = modelView[6];
    invViewMatrix[10] = modelView[10];
    invViewMatrix[11] = modelView[14];

    // Copy the inverted view matrix to the global variable that
    // was obtained from the module. The inverted view matrix
    // will be used by the kernel during rendering.
    cuMemcpyHtoD(c_invViewMatrix, Pointer.to(invViewMatrix),
        invViewMatrix.length * Sizeof.FLOAT);

    // Render and fill the PBO with pixel data
    render();

    // Draw the image from the PBO
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glDisable(GL.GL_DEPTH_TEST);
    gl.glRasterPos2i(0, 0);
    gl.glBindBuffer(GL2.GL_PIXEL_UNPACK_BUFFER, pbo);
    gl.glDrawPixels(width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 0);
    gl.glBindBuffer(GL2.GL_PIXEL_UNPACK_BUFFER, 0);

    // Update FPS information in main frame title
    step++;
    long currentTime = System.nanoTime();
    if (prevTimeNS == -1)
    {
        prevTimeNS = currentTime;
    }
    long diff = currentTime - prevTimeNS;
    if (diff > 1e9)
    {
        double fps = (diff / 1e9) * step;
        String t = "JCuda 3D texture volume rendering sample - ";
        t += String.format("%.2f", fps)+" FPS";
        frame.setTitle(t);
        prevTimeNS = currentTime;
        step = 0;
    }

}
 
Example 14
Source File: Renderer.java    From Ultraino with MIT License 4 votes vote down vote up
public void render(GL2 gl, int w, int h){
       preRender(gl);
       
       gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );
       
       Matrix4f projection = scene.getCamera().getProjection();
       
       Matrix4f view = new Matrix4f();
       scene.getCamera().getTransform().copyTo(view);
       view.invertLocal();
    
       TempVars tv = TempVars.get();
       
       gl.glEnable(GL2.GL_CULL_FACE); cullFace = true;
gl.glEnable(GL2.GL_DEPTH_TEST); depthTest = true;
gl.glDisable(GL2.GL_BLEND); blend = false;
       gl.glDisable(GL2.GL_TEXTURE_2D); texture2d = false;
       gl.glDisable(GL2.GL_TEXTURE_3D); texture3d = false;
       gl.glColorMask(true, true, true, true); writeColor = true;

       Texture lastTexture = null;
Shader lastShader = null;
Matrix4f model = tv.tempMat4;
       Matrix4f viewModel = tv.tempMat42;
       Matrix4f projectionViewModel = tv.tempMat43;

       synchronized (form) {
           calcDistanceToCameraOfEntities();
           sortEntities();
           
           for (MeshEntity me : scene.getEntities()) {

               if (!me.isVisible()) {
                   continue;
               }

               me.getTransform().copyTo(model);

               int shaderId = me.getShader();
               Shader currentShader = Resources.get().getShader(shaderId);
               if (currentShader == null) {
                   continue;
               }
               if (lastShader != currentShader) {
                   lastShader = currentShader;
                   gl.glUseProgram(lastShader.shaderProgramID);
                   gl.glUniform1i(lastShader.texDiffuse, 0);
               }
               if(lastShader != null) { lastShader.changeGLStatus(gl, this, form.getSimulation(), me); }

               if (lastTexture != me.getTexture()) {
                   lastTexture = me.getTexture();
                   if (lastTexture != null) {
                       gl.glBindTexture(GL2.GL_TEXTURE_2D, lastTexture.getId());
                   } else {
                       gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
                   }
               }

               //check for negative scale
               boolean usesCull = true;
               boolean needReverseCulling = usesCull && (model.get(0, 0) * model.get(1, 1) * model.get(2, 2) < 0);

               if (needReverseCulling) {
                   //gl.glCullFace(GL2.GL_FRONT);
               }

               view.mult(model, viewModel);
               projection.mult(viewModel, projectionViewModel);

               lastShader.bindAttribs(gl, form.getSimulation(), me);

               lastShader.bindUniforms(gl, scene, this, form.getSimulation(), me, projectionViewModel, viewModel, model, tv.floatBuffer16);

               lastShader.render(gl, form.getSimulation(), me);

               lastShader.unbindAttribs(gl, form.getSimulation(), me);

               if (needReverseCulling) {
                   //gl.glCullFace(GL2.GL_BACK);
               }

           }
       }

       tv.release();

       postRender(gl);
   }
 
Example 15
Source File: J3DTriangle.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();
    // Move triangle  
    gl.glTranslatef(-0.5f, 0.0f, -6.0f);
    gl.glRotatef(rotation, 0.0f, 1.0f, 0.0f);
    gl.glBegin(GL2.GL_TRIANGLES);

    // Front  
    gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow  
    gl.glVertex3f(1.5f, 2f, 0.0f); // Top Of Triangle   

    gl.glColor3f(0.0f, 1.5f, 0.0f); // Green  
    gl.glVertex3f(-1.5f, -1.5f, 1.5f); // Left Of Triangle   

    gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple  
    gl.glVertex3f(1.5f, -1.5f, 1.5f); // Right Of Triangle   

    // Right  
    gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow  
    gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle   

    gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple  
    gl.glVertex3f(1.5f, -1.5f, 1.5f); // Left Of Triangle   

    gl.glColor3f(0.0f, 1.0f, 0.0f); // Green  
    gl.glVertex3f(1.5f, -1.5f, -1.5f); // Right Of Triangle   

    // Back  
    gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow  
    gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle   

    gl.glColor3f(0.0f, 1.0f, 0.0f); // Green  
    gl.glVertex3f(1.5f, -1.5f, -1.5f); // Left Of Triangle   

    gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple  
    gl.glVertex3f(-1.5f, -1.5f, -1.5f); // Right Of Triangle   

    //left  
    gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow  
    gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle   

    gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple  
    gl.glVertex3f(-1.5f, -1.5f, -1.5f); // Left Of Triangle   

    gl.glColor3f(0.0f, 1.0f, 0.0f); // Green  
    gl.glVertex3f(-1.5f, -1.5f, 1.5f); // Right Of Triangle   

    gl.glEnd();
    gl.glFlush();
    rotation += 0.6f;
}
 
Example 16
Source File: J3DCube.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, -2.0f);

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

    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0f, 0f, 1f); //Blue color  
    //Top Quadrilateral  
    gl.glVertex3f(0.5f, 0.5f, -0.5f); //Upper Right  
    gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Left  
    gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left  
    gl.glVertex3f(0.5f, 0.5f, 0.5f); // Bottom Right  
    //Below Quadrilateral  
    gl.glColor3f(1f, 0f, 0f); //Red color  
    gl.glVertex3f(0.5f, -0.5f, 0.5f); // Upper Right   
    gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Upper Left   
    gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Left   
    gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Right   
    //Front Quadrilateral  
    gl.glColor3f(0f, 1f, 0f); //Green color  
    gl.glVertex3f(0.5f, 0.5f, 0.5f); // Upper Right   
    gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Upper Left   
    gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Left   
    gl.glVertex3f(0.5f, -0.5f, 0.5f); // Bottom Right  
    //Back Quadrilateral  
    gl.glColor3f(1f, 1f, 0f); //Yellow  
    gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Left   
    gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Right   
    gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Right   
    gl.glVertex3f(0.5f, 0.5f, -0.5f); // Upper Left   
    //Left Quadrilateral  
    gl.glColor3f(1f, 0f, 1f); //Purple  
    gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Upper Right  
    gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Left   
    gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Left   
    gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Right   
    //Right Quadrilateral  
    gl.glColor3f(0f, 1f, 1f); //Cyan  
    gl.glVertex3f(0.5f, 0.5f, -0.5f); // Upper Right   
    gl.glVertex3f(0.5f, 0.5f, 0.5f); // Upper Left   
    gl.glVertex3f(0.5f, -0.5f, 0.5f); // Bottom Left   
    gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Right   
    gl.glEnd();
    gl.glFlush();

    rotation += 0.6f;
}
 
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;
}