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

The following examples show how to use com.jogamp.opengl.GL2#glViewport() . 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: JCuboid.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    final GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) {
        height = 1;
    }

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
 
Example 2
Source File: J3DCube.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    final GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) {
        height = 1;
    }

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    glu.gluLookAt(0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
 
Example 3
Source File: J3DTriangle.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    final GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) {
        height = 1;
    }

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
 
Example 4
Source File: J3DBasic.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) {
        height = 1;
    }

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(40.0f, h, 1.5, 18.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

}
 
Example 5
Source File: JCudaDriverVolumeRendererJOGL.java    From jcuda-samples with MIT License 6 votes vote down vote up
/**
 * Set up a default view for the given GLAutoDrawable
 * 
 * @param drawable The GLAutoDrawable to set the view for
 */
private void setupView(GLAutoDrawable drawable)
{
    GL2 gl = drawable.getGL().getGL2();

    int w = drawable.getSurfaceWidth();
    int h = drawable.getSurfaceHeight();
    gl.glViewport(0, 0, w, h);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
}
 
Example 6
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 7
Source File: Tessellation.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(0.0, (double) w, 0.0, (double) h);
}
 
Example 8
Source File: BasicLine1.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glViewport(0, 0, width, height);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(-2f, 2f, -2f, 2f, 0.0f, 1.0f);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
 
Example 9
Source File: CubeTexture.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    final GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) {
        height = 1;
    }
    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(45.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
 
Example 10
Source File: OneTriangle.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static void setup( GL2 gl2, int width, int height ) {
    gl2.glMatrixMode( GL2.GL_PROJECTION );
    gl2.glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the window
    GLU glu = new GLU();
    glu.gluOrtho2D( 0.0f, width, 0.0f, height );

    gl2.glMatrixMode( GL2.GL_MODELVIEW );
    gl2.glLoadIdentity();

    gl2.glViewport( 0, 0, width, height );
}
 
Example 11
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 12
Source File: Renderer.java    From Ultraino with MIT License 4 votes vote down vote up
public void reshape(GL2 gl, int w, int h){
    gl.glViewport( 0, 0, w, h );
    
    //set camera
    scene.getCamera().updateProjection(w/(float)h);
}
 
Example 13
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");
}