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

The following examples show how to use com.jogamp.opengl.GL2#glDisable() . 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: TextureEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public void render(GL2 gl2) {
	if(textureDirty) {
		// texture has changed, load the new texture.
		if(t == null || t.length()==0) texture = null;
		else {
			try {
				texture = TextureIO.newTexture(FileAccess.open(t), false, t.substring(t.lastIndexOf('.')+1));
			} catch(IOException e) {
				//e.printStackTrace();
				Log.error("I can't load "+t);
			}
			textureDirty=false;
		}
	}
    if(texture==null) {
		gl2.glDisable(GL2.GL_TEXTURE_2D);
    } else {
		gl2.glEnable(GL2.GL_TEXTURE_2D);
    	texture.bind(gl2);
    }
}
 
Example 2
Source File: MaterialEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public void render(GL2 gl2) {
	gl2.glColor4d(diffuse.getR(),diffuse.getG(),diffuse.getB(),diffuse.getA());
	gl2.glMaterialfv(GL2.GL_FRONT, GL2.GL_DIFFUSE, diffuse.getFloatArray(),0);
    gl2.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, specular.getFloatArray(),0);
    gl2.glMaterialfv(GL2.GL_FRONT, GL2.GL_EMISSION, emission.getFloatArray(),0);
    gl2.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, ambient.getFloatArray(),0);
    gl2.glMaterialf(GL2.GL_FRONT, GL2.GL_SHININESS, shininess.get().floatValue());
    gl2.glColorMaterial(GL2.GL_FRONT,GL2.GL_AMBIENT_AND_DIFFUSE );
    
    boolean isColorEnabled = gl2.glIsEnabled(GL2.GL_COLOR_MATERIAL);
	gl2.glDisable(GL2.GL_COLOR_MATERIAL);
	
	gl2.glShadeModel(GL2.GL_SMOOTH);
	
    if(isLit()) gl2.glEnable(GL2.GL_LIGHTING);
    else gl2.glDisable(GL2.GL_LIGHTING);

    texture.render(gl2);
    
    if(isColorEnabled) gl2.glEnable(GL2.GL_COLOR_MATERIAL);
}
 
Example 3
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 4
Source File: DelaunayTriangulationExample.java    From delaunay-triangulator with MIT License 6 votes vote down vote up
public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glDisable(GL.GL_CULL_FACE);
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(COLOR_BACKGROUND.getRed() / 255.0f, COLOR_BACKGROUND.getGreen() / 255.0f,
            COLOR_BACKGROUND.getBlue() / 255.0f, 1);
    gl.glClearDepth(1.0f);
    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glDepthFunc(GL.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

    gl.setSwapInterval(1);
    gl.glDisable(GL2.GL_CULL_FACE);

    delaunayTriangulator = new DelaunayTriangulator(pointSet);
}
 
Example 5
Source File: GridEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void render(GL2 gl2) {
	gl2.glPushMatrix();
	MatrixHelper.applyMatrix(gl2, pose);
	gl2.glDisable(GL2.GL_TEXTURE_2D);
	gl2.glDisable(GL2.GL_LIGHTING);
	gl2.glColor4d(color.getR(), color.getG(), color.getB(), color.getA());
	PrimitiveSolids.drawGrid(gl2,width.get(),height.get(),1);
	gl2.glPopMatrix();
}
 
Example 6
Source File: Renderer.java    From Ultraino with MIT License 5 votes vote down vote up
void enableCullFace(GL2 gl, boolean enabled){
    if (enabled != cullFace){
        if (enabled){
            gl.glEnable(GL2.GL_CULL_FACE);
        }else{
            gl.glDisable(GL2.GL_CULL_FACE);
        }
        cullFace = enabled;
    }
}
 
Example 7
Source File: Renderer.java    From Ultraino with MIT License 5 votes vote down vote up
void enableDepthTest(GL2 gl, boolean enabled){
    if (enabled != depthTest){
        if (enabled){
            gl.glEnable(GL2.GL_DEPTH_TEST);
        }else{
            gl.glDisable(GL2.GL_DEPTH_TEST);
        }
        depthTest = enabled;
    }
}
 
Example 8
Source File: Renderer.java    From Ultraino with MIT License 5 votes vote down vote up
void enableBlend(GL2 gl, boolean enabled){
    if (enabled != blend){
        if (enabled){
            gl.glEnable(GL2.GL_BLEND);
            gl.glBlendFunc (GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
        }else{
            gl.glDisable(GL2.GL_BLEND);
        }
        blend = enabled;
    }
}
 
Example 9
Source File: Renderer.java    From Ultraino with MIT License 5 votes vote down vote up
void enableTexture2D(GL2 gl, boolean enabled){
    if (enabled != texture2d){
        if (enabled){
            gl.glEnable(GL2.GL_TEXTURE_2D);
        }else{
            gl.glDisable(GL2.GL_TEXTURE_2D);
        }
        texture2d = enabled;
    }
}
 
Example 10
Source File: LightEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void setupLight(GL2 gl2) {
	int i = GL2.GL_LIGHT0+lightIndex;
	if(!enabled.get()) {
		gl2.glDisable(i);
		return;
	}
	gl2.glEnable(i);
	
	position[0]=(float)poseWorld.m03;
	position[1]=(float)poseWorld.m13;
	position[2]=(float)poseWorld.m23;
	position[3]=isDirectional.get()?1:0;
	gl2.glLightfv(i, GL2.GL_POSITION, position,0);
	
    gl2.glLightfv(i, GL2.GL_AMBIENT, ambient.getFloatArray(),0);
    gl2.glLightfv(i, GL2.GL_DIFFUSE, diffuse.getFloatArray(),0);
    gl2.glLightfv(i, GL2.GL_SPECULAR, specular.getFloatArray(),0);

    // z axis of the matrix is the light direction
    spotDirection[0]=(float)poseWorld.m02;
    spotDirection[1]=(float)poseWorld.m12;
    spotDirection[2]=(float)poseWorld.m22;
	gl2.glLightfv(i, GL2.GL_SPOT_DIRECTION, spotDirection,0);
    
    gl2.glLightf(i, GL2.GL_SPOT_CUTOFF, cutoff.get().floatValue());
    gl2.glLightf(i, GL2.GL_SPOT_EXPONENT, exponent.get().floatValue());
    
    // falloff/fade out
    gl2.glLightf(i, GL2.GL_CONSTANT_ATTENUATION,attenuationConstant.get().floatValue());
    gl2.glLightf(i, GL2.GL_LINEAR_ATTENUATION,attenuationLinear.get().floatValue());
    gl2.glLightf(i, GL2.GL_QUADRATIC_ATTENUATION,attenuationQuadratic.get().floatValue());
	
	super.render(gl2);
}
 
Example 11
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 12
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 13
Source File: ScreenSelector.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
protected void drawOrderedRenderable( DrawContext dc ) {
    int attrs = GL2.GL_COLOR_BUFFER_BIT // For blend enable, alpha
                                        // enable, blend func, alpha
                                        // func.
            | GL2.GL_CURRENT_BIT // For current color.
            | GL2.GL_DEPTH_BUFFER_BIT; // For depth test disable.

    Rectangle viewport = dc.getView().getViewport();
    Rectangle selection = this.getSelection();

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2
                                  // compatibility.
    this.BEogsh.pushAttrib(gl, attrs);
    this.BEogsh.pushClientAttrib(gl, GL2.GL_VERTEX_ARRAY);
    try {
        // Configure the modelview-projection matrix to transform vertex
        // points from screen rectangle
        // coordinates to clip coordinates without any perspective
        // transformation. We offset the rectangle by
        // 0.5 pixels to ensure that the line loop draws a line without
        // a 1-pixel gap between the line's
        // beginning and its end. We scale by (width - 1, height - 1) to
        // ensure that only the actual selected
        // area is filled. If we scaled by (width, height), GL line
        // rasterization would fill one pixel beyond
        // the actual selected area.
        this.BEogsh.pushProjectionIdentity(gl);
        gl.glOrtho(0, viewport.getWidth(), 0, viewport.getHeight(), -1, 1); // l,
                                                                            // r,
                                                                            // b,
                                                                            // t,
                                                                            // n,
                                                                            // f
        this.BEogsh.pushModelviewIdentity(gl);
        gl.glTranslated(0.5, 0.5, 0.0);
        gl.glTranslated(selection.getX(), viewport.getHeight() - selection.getY(), 0);
        gl.glScaled(selection.getWidth() - 1, selection.getHeight() - 1, 1);

        // Disable the depth test and enable blending so this screen
        // rectangle appears on top of the existing
        // framebuffer contents.
        gl.glDisable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_BLEND);
        OGLUtil.applyBlending(gl, false); // SelectionRectangle does not
                                          // use pre-multiplied colors.

        // Draw this screen rectangle's interior as a filled
        // quadrilateral.
        Color c = this.getInteriorColor() != null ? this.getInteriorColor() : DEFAULT_INTERIOR_COLOR;
        gl.glColor4ub((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue(), (byte) c.getAlpha());
        dc.drawUnitQuad();

        // Draw this screen rectangle's border as a line loop. This
        // assumes the default line width of 1.0.
        c = this.getBorderColor() != null ? this.getBorderColor() : DEFAULT_BORDER_COLOR;
        gl.glColor4ub((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue(), (byte) c.getAlpha());
        dc.drawUnitQuadOutline();
    } finally {
        this.BEogsh.pop(gl);
    }
}
 
Example 14
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 15
Source File: OpenGLVideoRenderer.java    From sagetv with Apache License 2.0 4 votes vote down vote up
private void updateVideo(int frametype)
{
  if(owner.isInFrame() || (owner.getPbuffer().getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT))
  {
    if(!owner.isInFrame())
    {
      System.out.println("Couldn't make pbuffer current?");
      return;
    }
    else
    {
      System.out.println("update video while already in frame");
    }
  }
  GL2 gl = owner.getPbuffer().getGL().getGL2();

  if(pureNativeMode) {
    try {
      updateVideo0();
    } catch(Throwable t) {}
  } else {
    //System.out.println("20,20 pixel: "+videobuffer.get(20*720+20));
    //System.out.println(" width: "+videowidth+" height: "+videoheight);
    gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[0]);
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videoy);
    gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth, videoheight,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer);

    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[1]);
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videou);
    gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth/2, videoheight/2,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer);

    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[2]);
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videov);
    gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth/2, videoheight/2,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer);
    gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, 0);
    gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
    gl.glFlush();
  }
  if(!owner.isInFrame()) owner.getPbuffer().getContext().release();
}
 
Example 16
Source File: OpenGLVideoRenderer.java    From sagetv with Apache License 2.0 4 votes vote down vote up
private void createVideo()
{
  //System.out.println("createvideo");
  if(owner.isInFrame() || (owner.getPbuffer().getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT))
  {
    if(!owner.isInFrame())
    {
      System.out.println("Couldn't make pbuffer current?");
      return;
    }
    else
    {
      System.out.println("Create video while already in frame");
    }
  }
  GL2 gl = owner.getPbuffer().getGL().getGL2();
  System.out.println("createvideo width: "+videowidth+" height: "+videoheight);
  if(videot!=null) gl.glDeleteTextures(3, videot, 0);
  //		try {
  //			closeVideo0();
  //		} catch(Throwable t) {}

  if(pureNativeMode) {
    videot = null;
    videoMode = 0; // release resources and force reallocation when we leave native mode
    try {
      createVideo0(videowidth, videoheight);
    } catch(Throwable t) {}
  } else {
    byte img[] = new byte[videowidth*videoheight*2];
    videot = new int[3];
    gl.glGenTextures(3, videot, 0);
    gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[0]);
    if(MiniClient.MAC_OS_X) {
      gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/);
      gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE);
    }
    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, 1, videowidth, videoheight, 0,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));
    gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
    gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[1]);
    if(MiniClient.MAC_OS_X) {
      gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/);
      gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE);
    }
    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, 1, videowidth/2, videoheight/2, 0,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));
    gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
    gl.glEnable(gl.GL_TEXTURE_RECTANGLE);
    gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[2]);
    if(MiniClient.MAC_OS_X) {
      gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/);
      gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE);
    }
    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, 1, videowidth/2, videoheight/2, 0,
        gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img));
    gl.glDisable(gl.GL_TEXTURE_RECTANGLE);
  }
  if(!owner.isInFrame()) owner.getPbuffer().getContext().release();
}
 
Example 17
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 18
Source File: ViewportEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void showPickingTest(GL2 gl2) {
	renderChosenProjection(gl2);
	gl2.glPushMatrix();

	Ray r = rayPick();

	double cx=cursorX;
	double cy=cursorY;
       int w = canvasWidth;
       int h = canvasHeight;
       setCursor(0,0);        Ray tl = rayPick();
       setCursor(w,0);        Ray tr = rayPick();
       setCursor(0,h);        Ray bl = rayPick();
       setCursor(w,h);        Ray br = rayPick();
	cursorX=cx;
	cursorY=cy;

       double scale=20;
       tl.direction.scale(scale);
       tr.direction.scale(scale);
       bl.direction.scale(scale);
       br.direction.scale(scale);
       r.direction .scale(scale);
       
       Vector3d tl2 = new Vector3d(tl.direction);
       Vector3d tr2 = new Vector3d(tr.direction);
       Vector3d bl2 = new Vector3d(bl.direction);
       Vector3d br2 = new Vector3d(br.direction);
       Vector3d r2  = new Vector3d(r.direction );
       
       tl2.add(tl.start);
       tr2.add(tr.start);
       bl2.add(bl.start);
       br2.add(br.start);
       r2.add(r.start);
       
       gl2.glDisable(GL2.GL_TEXTURE_2D);
	gl2.glDisable(GL2.GL_LIGHTING);
	
       gl2.glColor3d(1, 0, 0);
	gl2.glBegin(GL2.GL_LINES);
	gl2.glVertex3d(tl.start.x, tl.start.y, tl.start.z);		gl2.glVertex3d(tl2.x, tl2.y, tl2.z);
	gl2.glVertex3d(tr.start.x, tr.start.y, tr.start.z);		gl2.glVertex3d(tr2.x, tr2.y, tr2.z);
	gl2.glVertex3d(bl.start.x, bl.start.y, bl.start.z);		gl2.glVertex3d(bl2.x, bl2.y, bl2.z);
	gl2.glVertex3d(br.start.x, br.start.y, br.start.z);		gl2.glVertex3d(br2.x, br2.y, br2.z);

       gl2.glColor3d(1, 1, 1);
	gl2.glVertex3d(r.start.x, r.start.y, r.start.z);		gl2.glVertex3d(r2.x,r2.y,r2.z);
	gl2.glEnd();
       gl2.glColor3d(0, 1, 0);
	gl2.glBegin(GL2.GL_LINE_LOOP);
	gl2.glVertex3d(tl2.x, tl2.y, tl2.z);
	gl2.glVertex3d(tr2.x, tr2.y, tr2.z);
	gl2.glVertex3d(br2.x, br2.y, br2.z);
	gl2.glVertex3d(bl2.x, bl2.y, bl2.z);
	gl2.glEnd();
       gl2.glColor3d(0, 0, 1);
	gl2.glBegin(GL2.GL_LINE_LOOP);
	gl2.glVertex3d(tl.start.x, tl.start.y, tl.start.z);
	gl2.glVertex3d(tr.start.x, tr.start.y, tr.start.z);
	gl2.glVertex3d(br.start.x, br.start.y, br.start.z);
	gl2.glVertex3d(bl.start.x, bl.start.y, bl.start.z);
	gl2.glEnd();
	
	PrimitiveSolids.drawStar(gl2,r2,5);
	gl2.glPopMatrix();
}
 
Example 19
Source File: Lighting.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Stop light
 * @param gl GL2
 */
public void stop(GL2 gl) {
    gl.glDisable(GL2.GL_LIGHTING);
    gl.glDisable(GL2.GL_LIGHT0);
}
 
Example 20
Source File: OpenGLUtil.java    From haxademic with MIT License 3 votes vote down vote up
public static void setFog(PGraphics pg, boolean isEnabled) {
		GL2 gl = ((PJOGL)pg.beginPGL()).gl.getGL2();
		// Turn On Fog
//		float[] FogCol = {0.0f,0.8f,0.8f};  // define a nice light grey

		if(isEnabled)
			gl.glEnable(GL2.GL_FOG);
		else
			gl.glDisable(GL2.GL_FOG);
		
//		gl.glEnable(GL2.GL_FOG);
//		gl.glFogfv(GL2.GL_FOG_COLOR, FogCol, 1); // Set the fog color
//		gl.glFogf(GL2.GL_FOG_DENSITY,0.9f);  // Thin the fog out a little
//		gl.glFogf(GL2.GL_FOG_MODE, GL2.GL_LINEAR); // GL_LINEAR, GL_EXP, or GL_EXP2
//		gl.glFogf(GL2.GL_FOG_START, 0); 
//		gl.glFogf(GL2.GL_FOG_END, 1000);
		
		
		

	    float[] Fog_colour = {0,0,1f,0};


	    gl.glHint(GL2.GL_FOG_HINT, GL2.GL_NICEST);

	    //gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_EXP);
	    gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_EXP2);
	    //gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_LINEAR);

	    gl.glFogf(GL2.GL_FOG_DENSITY, 0.005f);
	    gl.glFogfv(GL2.GL_FOG_COLOR, Fog_colour, 0);
	    gl.glFogf(GL2.GL_FOG_START, 300 - 30);
	    gl.glFogf(GL2.GL_FOG_END, 300);


		
	}