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

The following examples show how to use com.jogamp.opengl.GL2#glBindTexture() . 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: Renderer.java    From Ultraino with MIT License 5 votes vote down vote up
public void dispose(GL2 gl){
    //deatach shader
    gl.glUseProgram(0);
    
    //deattach textures
    gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
    gl.glBindTexture(GL2.GL_TEXTURE_3D, 0);
    
    //relase shaders and textures
    Resources.get().releaseResources(gl);
}
 
Example 2
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 3
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 4
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 5
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 6
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 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");
}