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

The following examples show how to use com.jogamp.opengl.GL2#glClearColor() . 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: CubeTexture.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void init(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glDepthFunc(GL2.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
    gl.glEnable(GL2.GL_TEXTURE_2D);
    
    try {
        File im = new File("D:\\Temp\\image\\lenna.jpg ");
        //File im = new File("D:\\Temp\\Map\\GLOBALeb3colshade.jpg");
        BufferedImage image = ImageIO.read(im);
        Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true);
        //Texture t = TextureIO.newTexture(im, true);
        texture = t.getTextureObject(gl);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
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 3
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 4
Source File: CubeSample2.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public void init(GLAutoDrawable drawable) {
//		animator = new FPSAnimator(drawable, 30, true);
//		animator.add(glWindow);
//		animator.start();
//		animator.pause();

		GL2 gl = drawable.getGL().getGL2();
		//背景を白く塗りつぶす.
		gl.glClearColor(1f, 1f, 1f, 1.0f);

		System.out.println("auto swap:" + drawable.getAutoSwapBufferMode());
		drawable.setAutoSwapBufferMode(false);
	}
 
Example 5
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 6
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 7
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 8
Source File: Renderer.java    From Ultraino with MIT License 3 votes vote down vote up
public void init(GL2 gl, int w, int h){

        Resources.init(gl, true);
        
        gl.glClearColor(0, 0, 0.0f, 1);
        //gl.glClearColor(1, 1, 1, 1);
        
        
        //set camera
        reshape(gl, w, h);
    }