/** * Implement stereo using the stereo-enabled graphics device. The mode has an effect only if the * display device implements stereo. * * @param dc the current draw context. */ protected void doDrawToStereoDevice(DrawContext dc) { GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. View dcView = dc.getView(); // Draw the left eye if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT); else gl.glDrawBuffer(GL2.GL_BACK_LEFT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); // Move the view to the right eye Angle viewHeading = dcView.getHeading(); dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle())); dcView.apply(dc); // Draw the right eye try { if (this.isSwapEyes()) gl.glDrawBuffer(GL2.GL_BACK_LEFT); else gl.glDrawBuffer(GL2.GL_BACK_RIGHT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); } finally { // Restore the original view heading dcView.setHeading(viewHeading); dcView.apply(dc); } }
/** * Implement no stereo ("Mono") while using a stereo device. * * <p>Note that this method draws the image twice, once to each of the left and right eye buffers, * even when stereo is not in effect. This is to prevent the stereo device from drawing blurred * scenes. * * @param dc the current draw context. */ protected void doDrawStereoNone(DrawContext dc) { // If running on a stereo device but want to draw a normal image, both buffers must be filled or // the // display will be blurry. GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. gl.glDrawBuffer(GL2.GL_BACK_LEFT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); gl.glDrawBuffer(GL2.GL_BACK_RIGHT); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glCallList(startList); gl.glCallList(startList + 1); gl.glFlush(); }
/** * Implement stereo using the red-blue anaglyph technique. * * @param dc the current draw context. */ protected void doDrawStereoRedBlue(DrawContext dc) { GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility. View dcView = dc.getView(); // Draw the left eye if (this.isSwapEyes()) { if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT); gl.glColorMask(false, true, true, true); // right eye in green/blue } else { if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT); gl.glColorMask(true, false, false, true); // left eye in red only } if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); // Move the view to the right eye Angle viewHeading = dcView.getHeading(); dcView.setHeading(dcView.getHeading().subtract(this.getFocusAngle())); dcView.apply(dc); // Draw the right eye frame green and blue only try { gl.glClear(GL.GL_DEPTH_BUFFER_BIT); if (this.isSwapEyes()) { if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_RIGHT); gl.glColorMask(true, false, false, true); // right eye in red only } else { if (this.isHardwareStereo()) gl.glDrawBuffer(GL2.GL_BACK_LEFT); gl.glColorMask(false, true, true, true); // right eye in green/blue } if (this.isHardwareStereo()) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); super.draw(dc); } finally { // Restore the original view heading dcView.setHeading(viewHeading); dcView.apply(dc); gl.glColorMask(true, true, true, true); } }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); // gl.glColor3f(1.0f, 0.0f, 0.0f); //ここは削除 gl.glRotatef(25f, 0f, 1f, 0f); gl.glBegin(GL_POLYGON); gl.glColor3f(1.0f, 0.0f, 0.0f); // 赤 gl.glVertex2f(-0.9f, -0.9f); gl.glColor3f(0.0f, 1.0f, 0.0f); // 緑 gl.glVertex2f(0.9f, -0.9f); gl.glColor3f(0.0f, 0.0f, 1.0f); // 青 gl.glVertex2f(0.9f, 0.9f); gl.glColor3f(1.0f, 1.0f, 0.0f); // 黄 gl.glVertex2f(-0.9f, 0.9f); gl.glEnd(); }
/* * display() draws 5 teapots at different z positions. */ public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // if (fogMode == GL2.GL_EXP2) { gl.glFogf(GL2.GL_FOG_START, 1.0f); gl.glFogf(GL2.GL_FOG_END, 5.0f); } gl.glFogi(GL2.GL_FOG_MODE, fogMode); renderRedTeapot(gl, -4.0f, -0.5f, -1.0f); renderRedTeapot(gl, -2.0f, -0.5f, -2.0f); renderRedTeapot(gl, 0.0f, -0.5f, -3.0f); renderRedTeapot(gl, 2.0f, -0.5f, -4.0f); renderRedTeapot(gl, 4.0f, -0.5f, -5.0f); gl.glFlush(); }
/* (non-Javadoc) * @see com.jogamp.opengl.GLEventListener#display(com.jogamp.opengl.GLAutoDrawable) */ @Override public void display(GLAutoDrawable glDrawable) { // get the OpenGL context GL2 gl = glDrawable.getGL().getGL2(); // clear the screen gl.glClear(GL.GL_COLOR_BUFFER_BIT); // switch to the model view matrix gl.glMatrixMode(GL2.GL_MODELVIEW); // initialize the matrix (0,0) is in the center of the window gl.glLoadIdentity(); // render the scene this.render(gl); // perform other operations at the end (it really // doesn't matter if its done at the start or end) this.update(); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // GL_DEPTH_BUFFER_BITを追加 gl.glLoadIdentity(); // 視点位置と視線方向 glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); // 光源の位置設定 // gl.glLightfv(GL_LIGHT0, GL_POSITION, light0pos, 0); // gl.glLightfv(GL_LIGHT1, GL_POSITION, light1pos, 0); // 図形の回転 gl.glTranslatef(0.5f, 0.5f, 0.5f); gl.glRotatef(r, 0.0f, 1.0f, 0.0f); gl.glTranslatef(-0.5f, -0.5f, -0.5f); // 図形の色 (赤) // gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red, 0);//追加 // gl.glColor3f(0.0f, 0.0f, 0.0f); // 図形の描画 gl.glBegin(GL_QUADS); for (int j = 0; j < 6; ++j) { // gl.glColor3fv(color[j], 0); //追加 // gl.glNormal3fv(normal[j], 0); for (int i = 0; i < 4; ++i) { gl.glNormal3fv(vertex[face[j][i]], 0); gl.glVertex3fv(vertex[face[j][i]], 0); } } gl.glEnd(); // 一周回ったら回転角を 0 に戻す if (r++ >= 360.0f) r = 0; System.out.println("anim:" + animator.isAnimating() + ", r:" + r); if (willAnimatorPause) { animator.pause(); System.out.println("animoator paused:"); willAnimatorPause = false; } }
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); applyMovementAndRotation(gl); applyLight(gl); // enableTransparency(gl); for (Shape el : s) { el.draw(gl, glu); } for (ModelShape el : ms) { el.draw(gl); } gl.glFlush(); }
@Override public void display(final GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); enableStates(gl, true); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glPushMatrix(); gl.glRotatef(angleZ, 0.0f, 1.0f, 0.0f); gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f); glut.glutSolidTeapot(2.0f); gl.glPopMatrix(); gl.glFlush(); if (angleZ >= 180.0f) { rotDir = -1.0f; } else if (angleZ <= 0.0f) { rotDir = +1.0f; } angleZ += rotIncr * rotDir; enableStates(gl, false); }
@Override public void display(GLAutoDrawable pDrawable) { if (error) { return; } countFps(); simpleMoveAnimator.updateState(); GL2 gl = pDrawable.getGL().getGL2(); // System.err.println("INIT GL IS: " + gl.getClass().getName()); GLU glu = new GLU(); lightRender.draw(gl); // _direction_ // gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, // this.lightPos, 0); // // Clear the drawing area // gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); // // // // // // Reset the current matrix to the "identity" // gl.glLoadIdentity(); // // gl.glMatrixMode(GL2.GL_MODELVIEW); // gl.glLoadIdentity(); // clear color and depth buffers gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); setCamera(gl, glu, simpleMoveAnimator); gl.glEnable(GL.GL_MULTISAMPLE); skyBox.draw(gl, simpleMoveAnimator.getPoint()); ground.draw(gl, simpleMoveAnimator.getPoint()); if (modelRender.isDebugging()) { axisLabels.draw(gl); floor.draw(gl); // drawTextInfo(gl, simpleMoveAnimator.info()); } renderJosm.draw(gl, simpleMoveAnimator); // selectionDrawUtil.draw(gl, objectSelectionListener, // simpleMoveAnimator); drawCompass(gl); // Flush all drawing operations to the graphics card gl.glFlush(); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl2 = drawable.getGL().getGL2(); GLU glu = GLU.createGLU(); gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl2.glEnable(GL2.GL_DEPTH_TEST); gl2.glDisable(GL2.GL_CULL_FACE); gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); glu.gluPerspective(60, drawable.getSurfaceWidth() / drawable.getSurfaceHeight(), 0.1f, 100); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); camera_.apply(gl2, glu); light_.apply(gl2, glu); terrain_.draw(gl2, glu); Runnable triangle = () -> { gl2.glBegin(GL2.GL_TRIANGLES); { gl2.glColor3f(1, 1, 1); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0, 0, 1); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(1, 1, 1); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f); gl2.glVertex3f(0, 0, -0.75f); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(1, 1, 1); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(0, 1, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f); gl2.glVertex3f(0, 0, -0.75f); gl2.glColor3f(0, 0, 1); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(0.87f, -0.5f, 0); gl2.glColor3f(1, 0, 0); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(-0.87f, -0.5f, 0); gl2.glColor3f(0, 1, 0); gl2.glNormal3f(0, -1.305f, -0.87f); gl2.glVertex3f(0, 0, -0.75f); } gl2.glEnd(); }; gl2.glPushMatrix(); { gl2.glPushMatrix(); gl2.glTranslatef(0, 0, 0); gl2.glRotatef(angle__, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); gl2.glPushMatrix(); gl2.glTranslatef(0, 3.2f, 0); gl2.glRotatef(angle__ + 30, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); gl2.glPushMatrix(); gl2.glTranslatef(3.2f, 0, 0); gl2.glRotatef(angle__ + 60, 0, 1, 0); triangle.run(); gl2.glPopMatrix(); } gl2.glPopMatrix(); angle__ += 1; gl2.glPushMatrix(); gl2.glTranslatef(0.05f, -1.5f, 5); gl2.glScalef(0.05f, 0.05f, 0.05f); for (Face face : glock3__.faces) { gl2.glBegin(GL2.GL_POLYGON); for (FaceVertex vertex : face.vertices) { gl2.glColor3f(1, 1, 1); gl2.glNormal3f(vertex.n.x, vertex.n.y, vertex.n.z); gl2.glVertex3f(vertex.v.x, vertex.v.y, vertex.v.z); } gl2.glEnd(); } gl2.glPopMatrix(); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glShadeModel(GL2.GL_SMOOTH); // Enable Smooth Shading (Gouraud) // Display the scene according to the current trackball orientation, scale the scene to fit // better tbc.prepareForDisplay(drawable); gl.glScaled(3, 3, 3); // Add a light int lightNumber = 0; float[] position = {lightPos.x, lightPos.y, lightPos.z, 1}; float[] colour = { lightColR.getFloatValue(), lightColG.getFloatValue(), lightColB.getFloatValue(), 1 }; float[] acolour = { colour[0] * ambient.getFloatValue(), colour[1] * ambient.getFloatValue(), colour[2] * ambient.getFloatValue() }; gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_SPECULAR, colour, 0); gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_DIFFUSE, colour, 0); gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_AMBIENT, acolour, 0); gl.glLightfv( GL2.GL_LIGHT0 + lightNumber, GL2.GL_POSITION, position, 0); // transformed by the modelview matrix when glLight is called gl.glEnable(GL2.GL_LIGHT0 + lightNumber); // Determine which shader to display the scene with ShaderState customShader = null; if (viewingMode == 1) { stateCheckerboard.useProgram(gl, false); stateWoodcut.useProgram(gl, false); stateToon.useProgram(gl, false); statePerFragment.useProgram(gl, usePerFragment); if (usePerFragment) customShader = statePerFragment; else customShader = null; } else if (viewingMode == 2) { statePerFragment.useProgram(gl, false); stateWoodcut.useProgram(gl, false); stateToon.useProgram(gl, false); stateCheckerboard.useProgram(gl, useCheckerboard); if (useCheckerboard) customShader = stateCheckerboard; else customShader = null; } else if (viewingMode == 3) { statePerFragment.useProgram(gl, false); stateCheckerboard.useProgram(gl, false); stateToon.useProgram(gl, false); stateWoodcut.useProgram(gl, useWoodcut); if (useWoodcut) customShader = stateWoodcut; else customShader = null; } else if (viewingMode == 4) { statePerFragment.useProgram(gl, false); stateCheckerboard.useProgram(gl, false); stateWoodcut.useProgram(gl, false); stateToon.useProgram(gl, useToon); if (useToon) customShader = stateToon; else customShader = null; } // Setup the uniform values that may be used within the current shader if (customShader != null) { // Blinn-Phong uniforms int specExponentUniformLocation = customShader.getUniformLocation(gl, "shininess"); gl.glUniform1f(specExponentUniformLocation, shininess.getFloatValue()); int ambientUniformLocation = customShader.getUniformLocation(gl, "ambient"); gl.glUniform1f(ambientUniformLocation, ambient.getFloatValue()); // Checkerboard uniforms int colour1UniformLocation = customShader.getUniformLocation(gl, "Color1"); float[] colour1 = {col1R.getFloatValue(), col1G.getFloatValue(), col1B.getFloatValue()}; gl.glUniform3fv(colour1UniformLocation, 1, colour1, 0); int colour2UniformLocation = customShader.getUniformLocation(gl, "Color2"); float[] colour2 = {col2R.getFloatValue(), col2G.getFloatValue(), col2B.getFloatValue()}; gl.glUniform3fv(colour2UniformLocation, 1, colour2, 0); int avgColourUniformLocation = customShader.getUniformLocation(gl, "AvgColor"); float[] avgColour = { (colour1[0] + colour2[0]) / 2, (colour1[1] + colour2[1]) / 2, (colour1[2] + colour2[2]) / 2 }; gl.glUniform3fv(avgColourUniformLocation, 1, avgColour, 0); int frequencyUniformLocation = customShader.getUniformLocation(gl, "Frequency"); double frequencyValue = frequency.getValue(); frequencyValue = useIntFrequency.getValue() ? Math.round(frequencyValue) : frequencyValue; gl.glUniform1f(frequencyUniformLocation, (float) frequencyValue); int useAveragingUniformLocation = customShader.getUniformLocation(gl, "UseAveraging"); gl.glUniform1i(useAveragingUniformLocation, useAveraging.getValue() ? 1 : 0); int useSmoothStepUniformLocation = customShader.getUniformLocation(gl, "UseSmoothStep"); gl.glUniform1i(useSmoothStepUniformLocation, useSmoothStep.getValue() ? 1 : 0); // Woodcut uniforms int timeUniformLocation = customShader.getUniformLocation(gl, "Time"); gl.glUniform1f(timeUniformLocation, time.getFloatValue()); int lightPositionUniformLocation = customShader.getUniformLocation(gl, "LightPosition"); float[] lightPosition = {lightPos.x, lightPos.y, lightPos.z}; gl.glUniform3fv(lightPositionUniformLocation, 1, lightPosition, 0); // Toon uniforms int threshHighUniformLocation = customShader.getUniformLocation(gl, "ThresholdHigh"); gl.glUniform1f(threshHighUniformLocation, thresholdHigh.getFloatValue()); int threshMedUniformLocation = customShader.getUniformLocation(gl, "ThresholdMedium"); gl.glUniform1f(threshMedUniformLocation, thresholdMedium.getFloatValue()); int threshLowUniformLocation = customShader.getUniformLocation(gl, "ThresholdLow"); gl.glUniform1f(threshLowUniformLocation, thresholdLow.getFloatValue()); } // Draw teapot gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, new float[] {1, 1, 0, 1}, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, new float[] {1, 1, 1, 1}, 0); gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 50); glut.glutSolidTeapot(1); // Draw table gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, new float[] {0, 1, 1, 1}, 0); gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, new float[] {1, 1, 1, 1}, 0); gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 50); gl.glPushMatrix(); gl.glTranslated(0, -0.8, 0); gl.glBegin(GL2.GL_TRIANGLE_FAN); gl.glNormal3d(0, 1, 0); gl.glTexCoord2d(0, 0); gl.glVertex3d(-10, 0, -10); gl.glTexCoord2d(0, 1); gl.glVertex3d(-10, 0, 10); gl.glTexCoord2d(1, 1); gl.glVertex3d(10, 0, 10); gl.glTexCoord2d(1, 0); gl.glVertex3d(10, 0, -10); gl.glEnd(); gl.glPopMatrix(); }