/** * Called back immediately after the OpenGL context is initialized. Can be used * to perform one-time initialization. Run only once. * GLEventListener method. */ @Override public void init(GLAutoDrawable drawable) { logger.log(Level.INFO, "Initializing OpenGL context."); generateObject(); this.fpsCounter = new FPSCounter(drawable, new Font("SansSerif", Font.BOLD, 12)); this.overlay = new Overlay(drawable, new Font("SansSerif", Font.BOLD, 12)); this.overlay.setColor(127, 127, 127, 100); this.overlay.setTextLocation(Overlay.LOWER_LEFT); // Parse random gcode file and generate something to draw. GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context glu = new GLU(); // get GL Utilities gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color gl.glClearDepth(1.0f); // set clear depth value to farthest gl.glEnable(GL_DEPTH_TEST); // enables depth testing gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting }
@Override public void display(GLAutoDrawable glautodrawable) { FocusOMeterGLRenderer.render(glautodrawable.getGL().getGL2(), glautodrawable.getSurfaceWidth(), glautodrawable.getSurfaceHeight()); } });
glcanvas.addGLEventListener(new GLEventListener() { @Override public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) { GL2 gl = glautodrawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Resets any previous projection matrices gl.glOrtho(0, width, 0, height, 1, -1); gl.glMatrixMode(GL2.GL_MODELVIEW); } ... Other methods }
GL2 gl = drawable.getGL().getGL2(); && gl.isFunctionAvailable( "glGenBuffers" ) && gl.isFunctionAvailable( "glBindBuffer" ) && gl.isFunctionAvailable( "glBufferData" ) && gl.isFunctionAvailable( "glDeleteBuffers" ) ) {
public void display(GLAutoDrawable drawable) { System.out.println(what+": display"); GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glColor3f(1.0f,1.0f,0.0f); gl.glBegin(GL2.GL_POLYGON); gl.glVertex3f(0.25f,0.25f,0.00f); gl.glVertex3f(0.75f,0.25f,0.00f); gl.glVertex3f(0.75f,0.75f,0.00f); gl.glVertex3f(0.25f,0.75f,0.00f); gl.glEnd(); gl.glFlush(); } public void dispose(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2(); gl.glDisable(GL_DEPTH_TEST); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(-0.51*this.aspectRatio,0.51*this.aspectRatio,-0.51,0.51,-10,10);
@Override public boolean run(final GLAutoDrawable drawable) { drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); // drawable.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); return false; } });
private void renderAxes(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glBegin(GL_LINES); gl.glColor3f( 1, 0, 0 ); gl.glVertex3f( 0, 0, 0 ); gl.glVertex3f( 50, 0, 0 );
/** * Draws a tool at the current work coordinates. */ private void renderTool(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glLineWidth(8.0f); byte []color; color = VisualizerUtils.Color.YELLOW.getBytes(); int verts = 0; int colors = 0; gl.glBegin(GL_LINES); gl.glColor3ub(color[0], color[1], color[2]); gl.glVertex3d(this.workCoord.x, this.workCoord.y, this.workCoord.z); gl.glColor3ub(color[0], color[1], color[2]); gl.glVertex3d(this.workCoord.x, this.workCoord.y, this.workCoord.z+(1.0/this.scaleFactor)); gl.glEnd(); }
final GL2 gl = drawable.getGL().getGL2(); gl.glScaled(this.scaleFactor, this.scaleFactor, this.scaleFactor); gl.glRotated(this.rotation.x, 0.0, 1.0, 0.0); gl.glRotated(this.rotation.y, 1.0, 0.0, 0.0); gl.glTranslated(-this.eye.x - this.center.x, -this.eye.y - this.center.y, -this.eye.z - this.center.z); } else {
@Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); this.textRenderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 32), true, false); gl.setSwapInterval(0); float[] components = otfVisConfig.getBackgroundColor().getColorComponents(new float[4]); gl.glClearColor(components[0], components[1], components[2], components[3]); gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); if (!glInited) { // This method can (and will) be called several times. // (Gl contexts can change without notice.) float minEasting = (float)clientQ.getMinEasting(); float minNorthing = (float)clientQ.getMinNorthing(); float maxNorthing = (float)clientQ.getMaxNorthing(); double aspectRatio = (double) drawable.getSurfaceWidth() / (double) drawable.getSurfaceHeight(); double pixelRatio = (double) drawable.getSurfaceHeight() / (double) (maxNorthing-minNorthing); this.scale = 1.0f / (float) pixelRatio; this.viewBounds = new QuadTree.Rect(minEasting, minNorthing, minEasting + (maxNorthing - minNorthing) * aspectRatio, maxNorthing); if (otfVisConfig.isMapOverlayMode()) { setScale(nearestPowerOfTwo(this.scale)); } int time = this.hostControlBar.getSimTime(); QuadTree.Rect rect = new QuadTree.Rect((float)clientQ.getMinEasting(), (float)clientQ.getMinNorthing(), (float)clientQ.getMaxEasting(), (float)clientQ.getMaxNorthing()); this.currentSceneGraph = this.clientQ.getSceneGraph(time, rect); } marker = GLUtils.createTexture(gl, MatsimResource.getAsInputStream("otfvis/marker.png")); currentSceneGraph.glInit(); glInited = true; }
@Override public void display(GLAutoDrawable glAutoDrawable) { GL2 gl = (GL2) glAutoDrawable.getGL(); for(OTFFeature feature : featureList) { gl.glColor4f(feature.color[0],feature.color[1],feature.color[2],feature.color[3]); gl.glBegin(feature.glType); for (int i = 0; i < feature.npoints; i++) { gl.glVertex3d(feature.xpoints[i], feature.ypoints[i], 0); } gl.glEnd(); } }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); float[] backgroundColor = vizController.getVizModel().getBackgroundColorComponents(); gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], transparentBackground ? 0f : 1f); engine.display(gl, GLU); }
protected GL2 getGL2(GLAutoDrawable drawable) { LOGGER.info("GL context : " + drawable.getContext()); LOGGER.info("GL profile : " + drawable.getGLProfile()); LOGGER.info("GL impl : " + drawable.getGL().getClass().getSimpleName()); LOGGER.info("isGL : " + drawable.getGL().isGL()); LOGGER.info("isGL2 : " + drawable.getGL().isGL2()); LOGGER.info("isGLES1 : " + drawable.getGL().isGL2ES1()); LOGGER.info("isGLES2 : " + drawable.getGL().isGL2ES2()); LOGGER.info("isGLES3 : " + drawable.getGL().isGL2ES3()); LOGGER.info("isGL2GL3 : " + drawable.getGL().isGL2GL3()); LOGGER.info("isGL3 : " + drawable.getGL().isGL3()); LOGGER.info("isGL3core : " + drawable.getGL().isGL3core()); LOGGER.info("isGL3ES3 : " + drawable.getGL().isGL3ES3()); LOGGER.info("isGL4 : " + drawable.getGL().isGL4()); LOGGER.info("isGL4bc : " + drawable.getGL().isGL4bc()); if (drawable.getGL() instanceof GL4bcImpl) { return drawable.getGL().getGL3().getGL2();//(GL2)drawable;//drawable.getGL().getGL2();//getGL3().getGL2(); } else { return (GL2)drawable;//drawable.getGL().getGL2(); } }
@Override public void display(GLAutoDrawable glAutoDrawable) { GL2 gl = (GL2) glAutoDrawable.getGL(); OTFClientControl.getInstance().getMainOTFDrawer().setFrustrum(gl); float[] backgroundColor = OTFClientControl.getInstance().getOTFVisConfig().getBackgroundColor().getColorComponents(new float[4]); gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]); gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); float[] networkColor = OTFClientControl.getInstance().getOTFVisConfig().getNetworkColor().getColorComponents(new float[4]); gl.glColor4d(networkColor[0], networkColor[1], networkColor[2], networkColor[3]); checkNetList(glAutoDrawable); gl.glCallList(netDisplList); }
public void init(GLAutoDrawable drawable) { System.out.println(what+": init"); GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.0f,0.0f,0.0f,0.0f); } public void reshape(
GL2 gl2 = drawable.getGL().getGL2(); double wcoordFar[] = new double[4]; gl2.glGetIntegerv(GL.GL_VIEWPORT, viewPort, 0); gl2.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelViewMatrix, 0); gl2.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projectionMatrix, 0);
public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.setSwapInterval(1); // Sync to VBlank if (inverseGamma != 1.0) { // Yeah baby, gamma correction in hardware! Gamma.setDisplayGamma(drawable, (float)inverseGamma, 0, 1); } gl.glGenFramebuffers(1, params, 0); frameBuffer = params[0]; } public void dispose(GLAutoDrawable drawable) {
/** * Call-back handler for window re-size event. Also called when the drawable is * first set to visible. * GLEventListener method. */ @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { logger.log(Level.INFO, "Reshaping OpenGL context."); if (!isDrawable) return; this.xSize = width; this.ySize = height; GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context if (height == 0){ height = 1; } // prevent divide by zero this.aspectRatio = (float)width / height; this.scaleFactorBase = VisualizerUtils.findScaleFactor(this.xSize, this.ySize, this.objectMin, this.objectMax, 0.9); this.scaleFactor = this.scaleFactorBase * this.zoomMultiplier; this.panMultiplierX = VisualizerUtils.getRelativeMovementMultiplier(this.objectMin.x, this.objectMax.x, this.xSize); this.panMultiplierY = VisualizerUtils.getRelativeMovementMultiplier(this.objectMin.y, this.objectMax.y, this.ySize); // Set the view port (display area) to cover the entire window gl.glViewport(0, 0, width, height); }