@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.out.println("reshape"); GL3 gl3 = drawable.getGL().getGL3(); /** Just the glViewport for this sample, normally here you update your projection matrix. */ gl3.glViewport(x, y, width, height); }
/* * Initialize z-buffer, projection matrix, light source, and lighting model. * Do not specify a material property here. */ public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); glut = new GLUT(); // float position[] = {0.0f, 3.0f, 3.0f, 0.0f}; float local_view[] = {0.0f}; gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LESS); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0); gl.glLightModelfv(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, local_view, 0); gl.glFrontFace(GL.GL_CW); gl.glEnable(GL2.GL_LIGHTING); gl.glEnable(GL2.GL_LIGHT0); gl.glEnable(GL2.GL_AUTO_NORMAL); gl.glEnable(GL2.GL_NORMALIZE); gl.glEnable(GL2.GL_FOG); { float fogColor[] = {0.5f, 0.5f, 0.5f, 1.0f}; fogMode = GL2.GL_EXP; gl.glFogi(GL2.GL_FOG_MODE, fogMode); gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0); gl.glFogf(GL2.GL_FOG_DENSITY, 0.35f); gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE); gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); } }
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(); }
@Override public void init(GLAutoDrawable glad) { GL3 gl3 = glad.getGL().getGL3(); try { shaders.add( GLSLHelpers.createShader(gl3, getClass(), GL3.GL_VERTEX_SHADER, "glsl/simple_vs")); shaders.add( GLSLHelpers.createShader(gl3, getClass(), GL3.GL_FRAGMENT_SHADER, "glsl/simple_fs")); program = GLSLHelpers.createProgram(gl3, shaders); gl3.glGenVertexArrays(1, VAO, 0); gl3.glBindVertexArray(VAO[0]); gl3.glGenBuffers(1, VBO, 0); gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]); FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(TRIANGLE); gl3.glBufferData(GL3.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GL3.GL_STATIC_DRAW); gl3.glEnableVertexAttribArray(0); gl3.glVertexAttribPointer(0, 2, GL3.GL_FLOAT, false, 0, 0); gl3.glBindVertexArray(0); } catch (Throwable t) { t.printStackTrace(); } }
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); }
public final void display(GLAutoDrawable drawable) { try { if (this._is_setup_done) { this.draw(drawable.getGL()); } } catch (Exception e) { e.printStackTrace(); } }
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(); }
@Override public void dispose(GLAutoDrawable glad) { GL3 gl3 = glad.getGL().getGL3(); gl3.glDeleteVertexArrays(1, VAO, 0); gl3.glDeleteBuffers(1, VBO, 0); for (int shader : shaders) gl3.glDeleteShader(shader); gl3.glDeleteProgram(program); }
@Override public void draw(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glLineWidth(lineWidth); // call before glBegin gl.glBegin(GL.GL_LINES); gl.glColor3f(1.0f, 0.51f, 0.98f); // #FF83FA gl.glVertex2f(x1, y); // start point gl.glVertex2f(x2, y); // end point gl.glEnd(); }
@Override public void dispose(GLAutoDrawable drawable) { System.out.println("dispose"); GL3 gl3 = drawable.getGL().getGL3(); gl3.glDeleteProgram(programName); gl3.glDeleteVertexArrays(1, vertexArrayName); gl3.glDeleteBuffers(Buffer.MAX, bufferName); System.exit(0); }
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(30.0, (double) width / (double) height, 1.0, 300.0); // 視点位置と視線方向 // glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);//コメントアウト gl.glMatrixMode(GL_MODELVIEW); }
public final void init(GLAutoDrawable drawable) { try { GL gl = drawable.getGL(); this.setup(gl); Animator animator = new Animator(drawable); animator.start(); this._is_setup_done = true; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return; }
@Override public void init(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println("GL_VENDOR " + gl.glGetString(GL.GL_VENDOR)); System.err.println("GL_RENDERER " + gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION " + gl.glGetString(GL.GL_VERSION)); if (useVBO) { gl.glGenBuffers(1, vboName, 0); if (0 == vboName[0]) { throw new GLException("glGenBuffers didn't return valid VBO name"); } } }
@Override public void display(final GLAutoDrawable drawable) { final GL2ES1 gl = drawable.getGL().getGL2ES1(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); // draw a triangle filling the window gl.glLoadIdentity(); if (useVBO) { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboName[0]); gl.glBufferData(GL.GL_ARRAY_BUFFER, bufferAll.limit(), bufferAll, GL.GL_STATIC_DRAW); if (useArrayData) { arrayV.setVBOName(vboName[0]); arrayC.setVBOName(vboName[0]); } } gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); if (useArrayData) { gl.glVertexPointer(arrayV); } else { if (useVBO) { gl.glVertexPointer(3, GL.GL_FLOAT, 0, bufferVOffset); } else { gl.glVertexPointer(3, GL.GL_FLOAT, 0, bufferV); } } gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY); if (useArrayData) { gl.glColorPointer(arrayC); } else { if (useVBO) { gl.glColorPointer(3, GL.GL_FLOAT, 0, bufferCOffset); } else { gl.glColorPointer(3, GL.GL_FLOAT, 0, bufferC); } } if (useVBO) { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); } gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3); gl.glFlush(); gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY); gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY); }
public void init(final GLAutoDrawable drawable) { super.init(drawable); final GL2ES2 gl = drawable.getGL().getGL2ES2(); final RenderState rs = getRenderer().getRenderState(); gl.setSwapInterval(1); gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); rs.setColorStatic(0.0f, 0.0f, 0.0f, 1.0f); createTestOutline(); }
@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(FOV, h, 1.0, 4000.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void draw(GLAutoDrawable glAutoDrawable, MatrixStack mvStack, Matrix3D pMat) { GL4 gl = (GL4) glAutoDrawable.getGL(); mvStack.pushMatrix(); // push translate translate(dxTranslate, dyTranslate, dzTranslate); mvStack.multMatrix(getTranslation()); mvStack.pushMatrix(); // push rotate rotate(dxRotate, dyRotate, dzRotate); mvStack.multMatrix(getRotation()); mvStack.multMatrix(getScale()); gl.glUniformMatrix4fv(IdentityLocs.getMvLoc(), 1, false, mvStack.peek().getFloatValues(), 0); gl.glUniformMatrix4fv(IdentityLocs.getProjLoc(), 1, false, pMat.getFloatValues(), 0); gl.glUniformMatrix4fv( IdentityLocs.getnlocation(), 1, false, (mvStack.peek().inverse().transpose().getFloatValues()), 0); // bind vertex values gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index]); gl.glVertexAttribPointer(0, 3, GL.GL_FLOAT, false, 0, 0); gl.glEnableVertexAttribArray(0); // bind normal values gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index + 2]); gl.glVertexAttribPointer(1, 3, GL.GL_FLOAT, false, 0, 0); gl.glEnableVertexAttribArray(1); // bind texture values gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[index + 1]); gl.glVertexAttribPointer(2, 2, GL.GL_FLOAT, false, 0, 0); gl.glEnableVertexAttribArray(2); gl.glActiveTexture(gl.GL_TEXTURE0); gl.glBindTexture(gl.GL_TEXTURE_2D, texture); gl.glEnable(GL_CULL_FACE); gl.glFrontFace(GL_CCW); gl.glEnable(GL_DEPTH_TEST); gl.glDepthFunc(GL_LEQUAL); // draw arrays gl.glDrawArrays(GL_TRIANGLES, 0, myShape.getIndices().length); mvStack.popMatrix(); // pop rotate mvStack.popMatrix(); // pop translate }
@Override public void reshape( final GLAutoDrawable gLDrawable, final int x, final int y, final int w, final int h) { final GL2 gl = gLDrawable.getGL().getGL2(); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); if (w <= h) { gl.glOrtho(-3.5, 3.5, -3.5 * h / w, 3.5 * h / w, -3.5, 3.5); } else { gl.glOrtho(-3.5 * w / h, 3.5 * w / h, -3.5, 3.5, -3.5, 3.5); } gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void display(GLAutoDrawable glad) { GL3 gl3 = glad.getGL().getGL3(); gl3.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl3.glClear(GL3.GL_COLOR_BUFFER_BIT); gl3.glUseProgram(program); gl3.glBindVertexArray(VAO[0]); gl3.glDrawArrays(GL3.GL_TRIANGLES, 0, 3); gl3.glBindVertexArray(0); gl3.glUseProgram(0); }
@Override public void dispose(final GLAutoDrawable drawable) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); if (null != texture) { texture.disable(gl); texture.destroy(gl); } if (null != textureData) { textureData.destroy(); } pmvMatrixUniform = null; pmvMatrix = null; st.destroy(gl); st = null; }
@Override public void init(GLAutoDrawable drawable) { System.out.println("init"); GL3 gl3 = drawable.getGL().getGL3(); initBuffers(gl3); initVertexArray(gl3); initProgram(gl3); gl3.glEnable(GL_DEPTH_TEST); start = System.currentTimeMillis(); }
@Override public void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { final GL2ES1 gl = drawable.getGL().getGL2ES1(); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window glu.gluOrtho2D(0.0f, width, 0.0f, height); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); gl.glViewport(0, 0, width, height); }
@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(); }
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()); }
@Override public void display(GLAutoDrawable drawable) { // System.out.println("display"); GL3 gl3 = drawable.getGL().getGL3(); /** * We set the clear color and depth (although depth is not necessary since it is 1 by default). */ gl3.glClearColor(0f, .33f, 0.66f, 1f); gl3.glClearDepthf(1f); gl3.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); { // update matrix based on time now = System.currentTimeMillis(); float diff = (float) (now - start) / 1000; /** * Here we build the matrix that will multiply our original vertex positions. We scale, * halving it, and rotate it. */ scale = FloatUtil.makeScale(scale, true, 0.5f, 0.5f, 0.5f); zRotazion = FloatUtil.makeRotationEuler(zRotazion, 0, 0, 0, diff); modelToClip = FloatUtil.multMatrix(scale, zRotazion); } gl3.glUseProgram(programName); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glUniformMatrix4fv(modelToClipMatrixUL, 1, false, modelToClip, 0); gl3.glDrawElements(GL_TRIANGLES, elementSize, GL_UNSIGNED_SHORT, 0); /** * The following line binds VAO and program to the default values, this is not a cheaper * binding, it costs always as a binding. Every binding means additional validation and * overhead, this may affect your performances. So you should avoid these calls, but remember * that OpenGL is a state machine, so what you left bound remains bound! */ // gl3.glBindVertexArray(0); // gl3.glUseProgram(0); /** * Check always any GL error, but keep in mind this is an implicit synchronization between CPU * and GPU, so you should use it only for debug purposes. */ checkError(gl3, "display"); }
/* * 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(); }
@Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // java.nio.IntBuffer maxlights = Buffers.newDirectIntBuffer(1); int[] maxlights = new int[1]; gl.glGetIntegerv(GL2.GL_MAX_LIGHTS, maxlights, 0); System.out.println(maxlights[0]); // 背景を白く塗りつぶす. gl.glClearColor(1f, 1f, 1f, 1.0f); gl.glEnable(GL_DEPTH_TEST); gl.glEnable(GL_CULL_FACE); gl.glCullFace(GL_FRONT); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_LIGHT0); gl.glEnable(GL_LIGHT1); // gl.glLightfv(GL_LIGHT1, GL_DIFFUSE, green, 0); // gl.glLightfv(GL_LIGHT1, GL_SPECULAR, green, 0); }
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); // gl.glViewport(0, 0, width, height); //(3) Jogl内部で実行済みなので、不要。(APIDOCに書いてある) // gl.glMatrixMode(GL_PROJECTION); // gl.glLoadIdentity(); // System.out.printf("x:%d, y:%d, w:%d, h:%d, %n", x, y, width, height); // これによりウィンドウをリサイズしても中の図形は大きさが維持される。 // また、第3、第4引数を入れ替えることによりGLWindowの座標系(左上隅が原点)とデバイス座標系(左下隅が原点)の違いを吸収している。 // gl.glOrthof(x, x + width, y + height, y, -1.0f, 1.0f); //(4) // gl.glOrthof(x/300, (x + width)/300, (y + height)/300, y/300, -1.0f, 1.0f); //(4) // gl.glOrthof(x/400, (x + width)/400, (y + height)/400, y/400, -1.0f, 1.0f); //(4) // gl.glOrthof(x/400, (x + width)/400, (y + height)/400, y/400, -1.0f, 1.0f); //(4) // gl.glOrthof(x/300, (x/300) + width, (y/300) + height, y/300, -1.0f, 1.0f); //(4) // gl.glOrthof(x , x + width/300, y + height/300, y, -1.0f, 1.0f); //(4) // gl.glMatrixMode(GL_MODELVIEW); // gl.glLoadIdentity(); }
/* (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 dispose(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); if (0 != vboName[0]) { gl.glDeleteBuffers(1, vboName, 0); vboName[0] = 0; } }