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(); if (w <= (h * 3)) gl.glOrtho( -6.0, 6.0, -2.0 * ((float) h * 3) / (float) w, 2.0 * ((float) h * 3) / (float) w, 0.0, 10.0); else gl.glOrtho( -6.0 * (float) w / ((float) h * 3), // 6.0 * (float) w / ((float) h * 3), -2.0, 2.0, 0.0, 10.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
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); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { GL2 gl = gLDrawable.getGL().getGL2(); final float aspect = (float) width / (float) height; gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); final float fh = 0.5f; final float fw = fh * aspect; gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); }
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.gluPerspective(45.0, 1.0, 0.25, 25.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); }
public void configureGL(GL2 gl) { gl.glEnable(GL2.GL_FOG); gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_LINEAR); gl.glFogf(GL2.GL_FOG_DENSITY, 0.25f); gl.glFogf(GL2.GL_FOG_START, Math.max(getNearClippingPlane(), fadeOut * 1.0f)); gl.glFogf(GL2.GL_FOG_END, Math.max(1.1f, fadeOut * 1.1f * getSpawnDistance())); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustumf(-1, 1, -man.vheight(), man.vheight(), getNearClippingPlane(), 128.0f); gl.glScalef(2.0f, 2.0f, 1); gl.glTranslatef(-0.5f, -man.vheight() / 2.0f, 0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void display(GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glClear(GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); // rotate about the three axes gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f); gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f); gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f); // Draw A Quad gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left // Done Drawing The Quad gl.glEnd(); // increasing rotation for the next iteration rotateT += 0.2f; }
/** * Call-back handler for window re-size event. Also called when the drawable is first set to * visible. */ @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context if (height == 0) height = 1; // prevent divide by zero float aspect = (float) width / height; // Set the view port (display area) to cover the entire window gl.glViewport(0, 0, width, height); // Setup perspective projection, with aspect ratio matches viewport gl.glMatrixMode(GL_PROJECTION); // choose projection matrix gl.glLoadIdentity(); // reset projection matrix glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, zFar // Enable the model-view transform gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); // reset }
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(); if (w <= h) gl.glOrtho(-3.5, 3.5, -3.5 * (float) h / (float) w, 3.5 * (float) h / (float) w, -3.5, 3.5); else gl.glOrtho( -3.5 * (float) w / (float) h, // 3.5 * (float) w / (float) h, -3.5, 3.5, -3.5, 3.5); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
public void draw() { // Clear GL state gl.glDisable(GL_LIGHTING); gl.glDisable(GL_DEPTH); gl.glMatrixMode(GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f); gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); gl.glPointSize(1.0f); // Set the viewport glu.gluOrtho2D(xMin, xMax, yMin, yMax); gl.glBegin(GL_POINTS); for (int x = (int) (xMin); x < xMax; x++) for (int y = (int) (yMin); y < yMax; y++) { gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b); gl.glVertex2d(x + 0.5, y + 0.5); } gl.glEnd(); // Restore state gl.glMatrixMode(GL_MODELVIEW); gl.glPopMatrix(); gl.glMatrixMode(GL_PROJECTION); gl.glPopMatrix(); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_DEPTH); }
@Override public void init(GLAutoDrawable glAutoDrawable) { gl = glAutoDrawable.getGL().getGL2(); glu = new GLU(); glut = new GLUT(); gl.glClearColor(0.549f, 0.675f, 0.227f, 0.0f); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(left, right, bottom, top); gl.glViewport((int) bottom, (int) left, (int) top, (int) right); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glColor3f(.357f, .184f, .478f); maxFrames = 50 * ifsFiles.size() + 1000; base = gl.glGenLists(maxFrames); currentDrawList = base; ifsfile = "CS371/assignments/assignment02/tri.ifs"; loadifs(); }
protected void applyBackground( DrawContext dc, WWIcon icon, Vec4 screenPoint, double width, double height, double pedestalSpacing, double pedestalScale) { GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. double backgroundScale; backgroundScale = icon.getBackgroundScale(); if (icon.getBackgroundTexture() != null) { if (icon.getBackgroundTexture().bind(dc)) { TextureCoords texCoords = icon.getBackgroundTexture().getTexCoords(); gl.glPushMatrix(); gl.glLoadIdentity(); double bgwidth = backgroundScale * width; double bgheight = backgroundScale * height; // Offset the background for the highlighted scale. // if (icon.isHighlighted()) // { // gl.glTranslated(0d, height * (icon.getHighlightScale() - 1) / 2, 0d); // } // Offset the background for the pedestal height. gl.glTranslated(0d, (pedestalScale * height) + pedestalSpacing, 0d); // Place the background centered behind the icon. gl.glTranslated(screenPoint.x - bgwidth / 2, screenPoint.y - (bgheight - height) / 2, 0d); // Scale to the background image dimension. gl.glScaled(bgwidth, bgheight, 1d); dc.drawUnitQuad(texCoords); gl.glPopMatrix(); } } }
/** Called back by the animator to perform rendering. */ @Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers for (int i = 0; i < stars.length; i++) { // Reset the view (x, y, z axes back to normal) gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, z); // The stars are texture quad square drawn on x-y plane and // distributed on on x-z plane around the y-axis // Initial 90 degree tile in the x-axis, y-axis pointing out of screen gl.glRotatef(tilt, 1.0f, 0.0f, 0.0f); // Rotate about y-axis (pointing out of screen), initial angle is 0 gl.glRotatef(stars[i].angle, 0.0f, 1.0f, 0.0f); // Translate about the x-axis (pointing right) to its current distance gl.glTranslatef(stars[i].distance, 0.0f, 0.0f); // The stars have initial angle of 0, and initial distance linearly // distributed between 0 and 5.0f // Rotate the axes back, so that z-axis is again facing us, to ensure that // the quad (with texture) on x-y plane is facing us gl.glRotatef(-stars[i].angle, 0.0f, 1.0f, 0.0f); gl.glRotatef(-tilt, 1.0f, 0.0f, 0.0f); // Take note that without the two rotations and undo, there is only one // translation along the x-axis // Matrix operation is non-commutative. That is, AB != BA. // Hence, ABCB'A' != C // Draw the star, which spins on the z axis (pointing out of the screen) gl.glRotatef(starSpinAngle, 0.0f, 0.0f, 1.0f); // Set the star's color using bytes (why bytes? not float or int?) gl.glColor4ub(stars[i].r, stars[i].g, stars[i].b, (byte) 255); gl.glBegin(GL_QUADS); // draw a square on x-y plane gl.glTexCoord2f(textureCoordLeft, textureCoordBottom); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glTexCoord2f(textureCoordRight, textureCoordBottom); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glTexCoord2f(textureCoordRight, textureCoordTop); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glTexCoord2f(textureCoordLeft, textureCoordTop); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glEnd(); // If twinkling, overlay with another drawing of an arbitrary color if (twinkleOn) { // Assign a color using bytes gl.glColor4ub( stars[(numStars - i) - 1].r, stars[(numStars - i) - 1].g, stars[(numStars - i) - 1].b, (byte) 255); gl.glBegin(GL_QUADS); // draw a square on x-y plane gl.glTexCoord2f(textureCoordLeft, textureCoordBottom); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glTexCoord2f(textureCoordRight, textureCoordBottom); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glTexCoord2f(textureCoordRight, textureCoordTop); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glTexCoord2f(textureCoordLeft, textureCoordTop); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glEnd(); } // Update for the next refresh // The star spins about the z-axis (pointing out of the screen), and spiral // inwards and collapse towards the center, by increasing the angle on x-y // plane and reducing the distance. starSpinAngle += 0.01f; // used to spin the stars about the z-axis // spiral pattern stars[i].angle += (float) i / numStars; // changes the angle of a star // collapsing the star to the center stars[i].distance -= 0.01f; // changes the distance of a star // re-bone at the edge if (stars[i].distance < 0.0f) { // Is the star collapsed to the center? stars[i].distance += 5.0f; // move to the outer ring stars[i].setRandomRGB(); // choose a random color for the star } } }
protected Vec4 drawIcon(DrawContext dc, OrderedIcon uIcon) { if (uIcon.point == null) { String msg = Logging.getMessage("nullValue.PointIsNull"); Logging.logger().severe(msg); // Record feedback data for this WWIcon if feedback is enabled. if (uIcon.icon != null) this.recordFeedback(dc, uIcon.icon, null, null); return null; } WWIcon icon = uIcon.icon; if (dc.getView().getFrustumInModelCoordinates().getNear().distanceTo(uIcon.point) < 0) { // Record feedback data for this WWIcon if feedback is enabled. this.recordFeedback(dc, icon, uIcon.point, null); return null; } final Vec4 screenPoint = dc.getView().project(uIcon.point); if (screenPoint == null) { // Record feedback data for this WWIcon if feedback is enabled. this.recordFeedback(dc, icon, uIcon.point, null); return null; } double pedestalScale; double pedestalSpacing; if (this.pedestal != null) { pedestalScale = this.pedestal.getScale(); pedestalSpacing = pedestal.getSpacingPixels(); } else { pedestalScale = 0d; pedestalSpacing = 0d; } GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. this.setDepthFunc(dc, uIcon, screenPoint); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); Dimension size = icon.getSize(); double width = size != null ? size.getWidth() : icon.getImageTexture().getWidth(dc); double height = size != null ? size.getHeight() : icon.getImageTexture().getHeight(dc); gl.glTranslated( screenPoint.x - width / 2, screenPoint.y + (pedestalScale * height) + pedestalSpacing, 0d); if (icon.isHighlighted()) { double heightDelta = this.pedestal != null ? 0 : height / 2; // expand only above the pedestal gl.glTranslated(width / 2, heightDelta, 0); gl.glScaled(icon.getHighlightScale(), icon.getHighlightScale(), icon.getHighlightScale()); gl.glTranslated(-width / 2, -heightDelta, 0); } Rectangle rect = new Rectangle( (int) (screenPoint.x - width / 2), (int) (screenPoint.y), (int) width, (int) (height + (pedestalScale * height) + pedestalSpacing)); if (dc.isPickingMode()) { // If in picking mode and pick clipping is enabled, check to see if the icon is within the // pick volume. if (this.isPickFrustumClippingEnabled() && !dc.getPickFrustums().intersectsAny(rect)) { // Record feedback data for this WWIcon if feedback is enabled. this.recordFeedback(dc, icon, uIcon.point, rect); return screenPoint; } else { java.awt.Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); this.pickSupport.addPickableObject(colorCode, icon, uIcon.getPosition(), false); gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); } } if (icon.getBackgroundTexture() != null) this.applyBackground(dc, icon, screenPoint, width, height, pedestalSpacing, pedestalScale); if (icon.getImageTexture().bind(dc)) { TextureCoords texCoords = icon.getImageTexture().getTexCoords(); gl.glScaled(width, height, 1d); dc.drawUnitQuad(texCoords); } if (this.pedestal != null && this.pedestal.getImageTexture() != null) { gl.glLoadIdentity(); gl.glTranslated(screenPoint.x - (pedestalScale * (width / 2)), screenPoint.y, 0d); gl.glScaled(width * pedestalScale, height * pedestalScale, 1d); if (this.pedestal.getImageTexture().bind(dc)) { TextureCoords texCoords = this.pedestal.getImageTexture().getTexCoords(); dc.drawUnitQuad(texCoords); } } // Record feedback data for this WWIcon if feedback is enabled. this.recordFeedback(dc, icon, uIcon.point, rect); return screenPoint; }