com.jogamp.opengl.fixedfunc.GLMatrixFunc Java Examples
The following examples show how to use
com.jogamp.opengl.fixedfunc.GLMatrixFunc.
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: JOGLOffscreenRenderer.java From cineast with MIT License | 6 votes |
/** * Changes the positionCamera of the camera. * * @param ex x Position of the Camera * @param ey y Position of the Camera * @param ez z Position of the Camera * @param cx x Position of the object of interest (i.e. the point at which the camera looks). * @param cy y Position of the object of interest (i.e. the point at which the camera looks). * @param cz z Position of the object of interest (i.e. the point at which the camera looks). * @param upx x-direction of the camera's UP position. * @param upy y-direction of the camera's UP position. * @param upz z-direction of the camera's UP position. */ @Override public final void positionCamera(double ex, double ey, double ez, double cx, double cy, double cz, double upx, double upy, double upz) { /* Check context. */ if (!this.checkContext()) { return; } /* Switch matrix mode to projection. */ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); /* Set default perspective. */ glu.gluPerspective(45.0f, this.aspect, 0.01f, 100.0f); /* Update camera position. */ glu.gluLookAt(ex,ey,ez,cx,cy,cz,upx,upy,upz); }
Example #2
Source File: TestTextRendererNEWT10.java From jogl-samples with MIT License | 6 votes |
void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) { final int height = drawable.getSurfaceHeight(); int dx = 0; int dy = height; if(0>row) { row = lastRow + 1; } final AABBox textBox = font.getMetricBounds(text, fontSize); dx += font.getAdvanceWidth('X', fontSize) * column; dy -= (int)textBox.getHeight() * ( row + 1 ); final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(dx, dy, z0); textRenderUtil.drawString3D(gl, renderer, font, fontSize, text, null, sampleCount); lastRow = row; }
Example #3
Source File: TestTextRendererNEWTBugXXXX.java From jogl-samples with MIT License | 6 votes |
void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final Font font, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) { final int height = drawable.getSurfaceHeight(); int dx = 0; int dy = height; if(0>row) { row = lastRow + 1; } final AABBox textBox = font.getMetricBounds(text, fontSize); dx += font.getAdvanceWidth('X', fontSize) * column; dy -= (int)textBox.getHeight() * ( row + 1 ); final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(dx, dy, z0); textRenderUtil.drawString3D(gl, renderer, font, fontSize, text, null, sampleCount); lastRow = row; }
Example #4
Source File: UIGLListener01.java From jogl-samples with MIT License | 6 votes |
@Override public void display(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final int[] sampleCount = { 4 }; final float[] translate = button.getTranslate(); final RegionRenderer regionRenderer = getRegionRenderer(); final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZoom()); pmv.glRotatef(getAngle(), 0, 1, 0); pmv.glTranslatef(translate[0], translate[1], 0); button.drawShape(gl, regionRenderer, sampleCount); }
Example #5
Source File: SceneUIController.java From jogl-samples with MIT License | 6 votes |
private boolean windowToShapeCoordsImpl(final UIShape activeShape, final int glWinX, final int glWinY, final float[] objPos) { final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glPushMatrix(); transformShape(pmv, activeShape); boolean res = false; final float[] ctr = activeShape.getBounds().getCenter(); if( pmv.gluProject(ctr[0], ctr[1], ctr[2], viewport, 0, dpyTmp1V3, 0) ) { // System.err.printf("winToShapeCoords.0: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", shapeId, ctr[0], ctr[1], ctr[2], dpyTmp1V3[0], dpyTmp1V3[1], dpyTmp1V3[2]); if( pmv.gluUnProject(glWinX, glWinY, dpyTmp1V3[2], viewport, 0, objPos, 0) ) { // System.err.printf("winToShapeCoords.1: shape %d: win [%d, %d, %f] -> obj [%f, %f, %f]%n", shapeId, glWinX, glWinY, dpyTmp1V3[2], objPos[0], objPos[1], objPos[2]); res = true; } } pmv.glPopMatrix(); return res; }
Example #6
Source File: GPURegionGLListener02.java From jogl-samples with MIT License | 6 votes |
public void display(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final RegionRenderer regionRenderer = getRenderer(); final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZTran()); pmv.glRotatef(getAngle(), 0, 1, 0); if( weight != regionRenderer.getRenderState().getWeight() ) { regionRenderer.getRenderState().setWeight(weight); } region.draw(gl, regionRenderer, getSampleCount()); }
Example #7
Source File: GPURegionGLListener01.java From jogl-samples with MIT License | 6 votes |
public void display(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final RegionRenderer regionRenderer = getRenderer(); final PMVMatrix pmv = regionRenderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(getXTran(), getYTran(), getZTran()); pmv.glRotatef(getAngle(), 0, 1, 0); if( weight != regionRenderer.getRenderState().getWeight() ) { regionRenderer.getRenderState().setWeight(weight); } region.draw(gl, regionRenderer, getSampleCount()); }
Example #8
Source File: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 6 votes |
void drawString(String text, int x, int y, java.awt.Color color, GL2 gl, com.jogamp.opengl.util.awt.TextRenderer tr) { //System.out.println("drawString "+ text + " x: "+x+" y: "+y); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); //System.out.println("glOrtho(0,"+ c.getWidth() + ","+c.getHeight()+",0,-1.0,1.0)"); gl.glOrtho(0,c.getWidth(),0,c.getHeight(),-1.0,1.0); tr.begin3DRendering(); tr.setColor(color); tr.draw3D(text, x, c.getHeight()-y, 0, 1); tr.end3DRendering(); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); }
Example #9
Source File: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 6 votes |
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 #10
Source File: OneTriangle.java From clearvolume with GNU Lesser General Public License v3.0 | 6 votes |
protected static void setup(GL pGL, int width, int height) { pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_PROJECTION); pGL.getGL2().glLoadIdentity(); // coordinate system origin at lower left with width and height same as // the // window final GLU glu = new GLU(); glu.gluOrtho2D(0.0f, width, 0.0f, height); pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pGL.getGL2().glLoadIdentity(); pGL.glViewport(0, 0, width, height); }
Example #11
Source File: JOGLOffscreenRenderer.java From cineast with MIT License | 6 votes |
/** * */ @Override public void render() { /* Clear context. */ gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Switch matrix mode to modelview. */ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glEnable(GL_DEPTH_TEST); gl.glDepthFunc(GL_LESS); gl.glLoadIdentity(); gl.glPolygonMode(GL_FRONT_AND_BACK, this.polygonmode); /* Call list. */ for (Integer handle : this.objects) { gl.glCallList(handle); } }
Example #12
Source File: SceneUIController.java From jogl-samples with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void display(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); final Object[] shapesS = shapes.toArray(); Arrays.sort(shapesS, (Comparator)shapeZAscComparator); renderer.enable(gl, true); //final int shapeCount = shapes.size(); final int shapeCount = shapesS.length; for(int i=0; i<shapeCount; i++) { // final UIShape uiShape = shapes.get(i); final UIShape uiShape = (UIShape)shapesS[i]; // System.err.println("Id "+i+": "+uiShape); if( uiShape.isEnabled() ) { uiShape.validate(gl, renderer); pmv.glPushMatrix(); transformShape(pmv, uiShape); uiShape.drawShape(gl, renderer, sampleCount); pmv.glPopMatrix(); } } renderer.enable(gl, false); }
Example #13
Source File: SceneUIController.java From jogl-samples with MIT License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private UIShape pickShapeImpl(final int glWinX, final int glWinY, final float[] objPos) { final float winZ0 = 0f; final float winZ1 = 0.3f; /** final FloatBuffer winZRB = Buffers.newDirectFloatBuffer(1); gl.glReadPixels( x, y, 1, 1, GL2ES2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, winZRB); winZ1 = winZRB.get(0); // dir */ final PMVMatrix pmv = renderer.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); final Ray ray = new Ray(); final Object[] shapesS = shapes.toArray(); Arrays.sort(shapesS, (Comparator)shapeZAscComparator); for(int i=shapesS.length-1; i>=0; i--) { final UIShape uiShape = (UIShape)shapesS[i]; if( uiShape.isEnabled() ) { pmv.glPushMatrix(); transformShape(pmv, uiShape); final boolean ok = pmv.gluUnProjectRay(glWinX, glWinY, winZ0, winZ1, viewport, 0, ray); pmv.glPopMatrix(); if( ok ) { final AABBox sbox = uiShape.getBounds(); if( sbox.intersectsRay(ray) ) { // System.err.printf("Pick.0: shape %d, [%d, %d, %f/%f] -> %s%n", i, glWinX, glWinY, winZ0, winZ1, ray); if( null == sbox.getRayIntersection(objPos, ray, FloatUtil.EPSILON, true, dpyTmp1V3, dpyTmp2V3, dpyTmp3V3) ) { throw new InternalError("Ray "+ray+", box "+sbox); } // System.err.printf("Pick.1: shape %d @ [%f, %f, %f], within %s%n", i, objPos[0], objPos[1], objPos[2], uiShape.getBounds()); return uiShape; } } } } return null; }
Example #14
Source File: GPURendererListenerBase01.java From jogl-samples with MIT License | 5 votes |
@Override public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) { final PMVMatrix pmv = renderer.getMatrix(); renderer.reshapePerspective(45.0f, width, height, zNear, zFar); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); System.err.printf("Reshape: zNear %f, zFar %f%n", zNear, zFar); System.err.printf("Reshape: Frustum: %s%n", pmv.glGetFrustum()); { final float orthoDist = 1f; final float[] obj00Coord = new float[3]; final float[] obj11Coord = new float[3]; final float[] winZ = new float[1]; final int[] view = new int[] { 0, 0, width, height }; mapWin2ObjectCoords(pmv, view, zNear, zFar, 0f, 0f, orthoDist, winZ, obj00Coord); System.err.printf("Reshape: mapped.00: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", 0f, 0f, orthoDist, winZ[0], obj00Coord[0], obj00Coord[1], obj00Coord[2]); mapWin2ObjectCoords(pmv, view, zNear, zFar, width, height, orthoDist, winZ, obj11Coord); System.err.printf("Reshape: mapped.11: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", (float)width, (float)height, orthoDist, winZ[0], obj11Coord[0], obj11Coord[1], obj11Coord[2]); nearPlane1Box.setSize( obj00Coord[0], // lx obj00Coord[1], // ly obj00Coord[2], // lz obj11Coord[0], // hx obj11Coord[1], // hy obj11Coord[2] );// hz System.err.printf("Reshape: dist1Box: %s%n", nearPlane1Box); } dumpMatrix(); // System.err.println("Reshape: "+renderer.getRenderState()); }
Example #15
Source File: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 4 votes |
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 #16
Source File: SceneUIController.java From jogl-samples with MIT License | 4 votes |
@Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { viewport[0] = x; viewport[1] = y; viewport[2] = width; viewport[3] = height; final PMVMatrix pmv = renderer.getMatrix(); renderer.reshapePerspective(45.0f, width, height, zNear, zFar); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); System.err.printf("Reshape: zNear %f, zFar %f%n", zNear, zFar); System.err.printf("Reshape: Frustum: %s%n", pmv.glGetFrustum()); { final float orthoDist = 1f; final float[] obj00Coord = new float[3]; final float[] obj11Coord = new float[3]; final float[] winZ = new float[1]; mapWin2ObjectCoords(pmv, viewport, zNear, zFar, 0f, 0f, orthoDist, winZ, obj00Coord); System.err.printf("Reshape: mapped.00: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", 0f, 0f, orthoDist, winZ[0], obj00Coord[0], obj00Coord[1], obj00Coord[2]); mapWin2ObjectCoords(pmv, viewport, zNear, zFar, width, height, orthoDist, winZ, obj11Coord); System.err.printf("Reshape: mapped.11: [%f, %f, %f], winZ %f -> [%f, %f, %f]%n", (float)width, (float)height, orthoDist, winZ[0], obj11Coord[0], obj11Coord[1], obj11Coord[2]); nearPlane1Box.setSize( obj00Coord[0], // lx obj00Coord[1], // ly obj00Coord[2], // lz obj11Coord[0], // hx obj11Coord[1], // hy obj11Coord[2] );// hz System.err.printf("Reshape: dist1Box: %s%n", nearPlane1Box); } scenePlaneOrigin[0] = nearPlane1Box.getMinX() * sceneDist; scenePlaneOrigin[1] = nearPlane1Box.getMinY() * sceneDist; scenePlaneOrigin[2] = nearPlane1Box.getMinZ() * sceneDist; sceneScale[0] = ( nearPlane1Box.getWidth() * sceneDist ) / width; sceneScale[1] = ( nearPlane1Box.getHeight() * sceneDist ) / height; sceneScale[2] = 1f; System.err.printf("Scene Origin [%f, %f, %f]%n", scenePlaneOrigin[0], scenePlaneOrigin[1], scenePlaneOrigin[2]); System.err.printf("Scene Scale %f * [%f x %f] / [%d x %d] = [%f, %f, %f]%n", sceneDist, nearPlane1Box.getWidth(), nearPlane1Box.getHeight(), width, height, sceneScale[0], sceneScale[1], sceneScale[2]); pmv.glTranslatef(scenePlaneOrigin[0], scenePlaneOrigin[1], scenePlaneOrigin[2]); pmv.glScalef(sceneScale[0], sceneScale[1], sceneScale[2]); }
Example #17
Source File: TextRendererGLELBase.java From jogl-samples with MIT License | 4 votes |
private void renderStringImpl(final GLAutoDrawable drawable, final Font font, final float pixelSize, final String text, final int column, final int row, final float tx, final float ty, final float tz, final boolean cacheRegion, final GLRegion region) { if( null != renderer ) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); float dx = tx; float dy; if( !exclusivePMVMatrix ) { dy = 1f-ty; } else { final int height = drawable.getSurfaceHeight(); dy = height-ty; } final int newLineCount = TextRegionUtil.getCharCount(text, '\n'); final float lineHeight = font.getLineHeight(pixelSize); dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column; dy -= pixelScale * lineHeight * ( row + 1 ); final PMVMatrix pmvMatrix = rs.getMatrix(); pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); if( !exclusivePMVMatrix ) { pmvMatrix.glPushMatrix(); } else { pmvMatrix.glLoadIdentity(); } pmvMatrix.glTranslatef(dx, dy, tz); if( flipVerticalInGLOrientation && drawable.isGLOriented() ) { pmvMatrix.glScalef(pixelScale, -1f*pixelScale, 1f); } else if( 1f != pixelScale ) { pmvMatrix.glScalef(pixelScale, pixelScale, 1f); } renderer.enable(gl, true); if( cacheRegion ) { textRenderUtil.drawString3D(gl, renderer, font, pixelSize, text, null, vbaaSampleCount); } else if( null != region ) { TextRegionUtil.drawString3D(gl, region, renderer, font, pixelSize, text, null, vbaaSampleCount, textRenderUtil.tempT1, textRenderUtil.tempT2); } else { TextRegionUtil.drawString3D(gl, renderModes, renderer, font, pixelSize, text, null, vbaaSampleCount, textRenderUtil.tempT1, textRenderUtil.tempT2); } renderer.enable(gl, false); if( !exclusivePMVMatrix ) { pmvMatrix.glPopMatrix(); } lastRow = row + newLineCount; } }