public void init(GLAutoDrawable drawable) { drawable.setGL(new DebugGL2(drawable.getGL().getGL2())); final GL2 gl = drawable.getGL().getGL2(); // drawable.getGL().getGL2(); gl.glViewport(0, 0, SCREENW, SCREENH); // Clear color buffer with black // gl.glClearColor(1.0f, 0.5f, 1.0f, 1.0f); gl.glClearColor(.0f, .0f, .0f, 1.0f); gl.glClearDepth(1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glEnable(GL2.GL_DEPTH_TEST); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER); shader.init(gl); int programName = shader.getID(); gl.glBindAttribLocation(programName, Object3D.VERTEXPOSITION, "inposition"); gl.glBindAttribLocation(programName, Object3D.VERTEXCOLOR, "incolor"); gl.glBindAttribLocation(programName, Object3D.VERTEXNORMAL, "innormal"); gl.glBindAttribLocation(programName, Object3D.VERTEXTEXCOORD0, "intexcoord0"); shader.link(gl); uniformMat = gl.glGetUniformLocation(programName, "mat"); uniformLight = gl.glGetUniformLocation(programName, "lightdir"); gl.glUseProgram(programName); gl.glUniform3f(uniformLight, 0f, 10f, -10f); obj.init(gl, mats, programName); gl.glUseProgram(0); }
// ------------------------------------------------------------ // GLEventListener public void init(GLAutoDrawable drawable) { if (debugging) drawable.setGL(new DebugGL(drawable.getGL())); try { // Specify new projection for this window init(drawable.getGL()); } catch (GLException e) { e.printStackTrace(); } }
@Override public void init(GLAutoDrawable drawable) { // uncomment this line to get debugging and tracing drawable.setGL(new DebugGL2(new TraceGL2(drawable.getGL().getGL2(), System.err))); // OR uncomment this line to just get debugging // drawable.setGL(new DebugGL2(drawable.getGL().getGL2())); GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(1.0f, 1.0f, 1.0f, 1f); // White Background }
@Override public void init(GLAutoDrawable drawable) { GL _gl = drawable.getGL(); if (glDebug) { try { _gl = _gl.getContext() .setGL(GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null)); } catch (Exception e) { e.printStackTrace(); } } if (glTrace) { try { // Trace .. _gl = _gl.getContext() .setGL( GLPipelineFactory.create( "javax.media.opengl.Trace", null, _gl, new Object[] {System.err})); } catch (Exception e) { e.printStackTrace(); } } if (glSwapInterval >= 0) { _gl.setSwapInterval(glSwapInterval); } }
public final void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); this.applyCameraAdjustment(gl); long t = System.currentTimeMillis(); long dt = t - tprec; tprec = t; mdx.update(dt); renderReference(gl, ORIGIN, X_AXIS.clone(), Y_AXIS.clone(), Z_AXIS.clone()); renderReferences(gl); gl.glColor3f(1.0f, 1.0f, 1.0f); int[] temp = selector.getGeoOn(); if (temp != null) { for (int i = 0; i < temp.length; ++i) this.renderNonBlending(mdx.getGeoset(temp[i]), gl); for (int i = 0; i < temp.length; ++i) this.renderBlending(mdx.getGeoset(temp[i]), gl); } }
@Override public void init(GLAutoDrawable dr) { GL2 gl = dr.getGL().getGL2(); // Задает цвет фона gl.glClearColor(0f, 0f, 0f, 0f); gl.glClearDepth(1.0f); // Интерполирует цвет, если вершины заданы различным цветом gl.glShadeModel(GL2.GL_SMOOTH); // Удаления невидимых линий и поверхностей gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); // Сглаживание gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // Включение отображения текстур gl.glEnable(GL.GL_TEXTURE_2D); try { model = ModelFactory.createModel("model/globalstar/Globalstar.3ds"); model.setUseLighting(false); } catch (Exception e) { System.out.println("Ошибка загрузки модели"); e.printStackTrace(); System.exit(1); } }
@Override public void init(GLAutoDrawable drawable) { super.init(drawable); drawable.getGL().setSwapInterval(SwapInterval); t0 = Platform.currentTimeMillis(); final Window win = (Window) drawable.getUpstreamWidget(); final MonitorDevice monitor = win.getMainMonitor(); final float[] pixelsPerMM = new float[2]; monitor.getPixelsPerMM(pixelsPerMM); final float[] dotsPerInch = new float[] {pixelsPerMM[0] * 25.4f, pixelsPerMM[1] * 25.4f}; dpiH = dotsPerInch[1]; System.err.println(getFontInfo()); System.err.println( "fontSize " + fontSizeFixed + ", dotsPerMM " + pixelsPerMM[0] + "x" + pixelsPerMM[1] + ", dpi " + dotsPerInch[0] + "x" + dotsPerInch[1] + ", pixelSize " + font.getPixelSize(fontSizeFixed, dotsPerInch[1] /* dpi display */)); }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // double eqn[] = {0.0, 1.0, 0.0, 0.0}; double eqn2[] = {1.0, 0.0, 0.0, 0.0}; gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glPushMatrix(); gl.glTranslatef(0.0f, 0.0f, -5.0f); /* clip lower half -- y < 0 */ gl.glClipPlane(GL2.GL_CLIP_PLANE0, eqn, 0); gl.glEnable(GL2.GL_CLIP_PLANE0); /* clip left half -- x < 0 */ gl.glClipPlane(GL2.GL_CLIP_PLANE1, eqn2, 0); gl.glEnable(GL2.GL_CLIP_PLANE1); gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glut.glutWireSphere(1.0, 20, 16); gl.glPopMatrix(); gl.glFlush(); }
/** * Init the rendering of this canvas. This function is called right before the first rendering * run. Its used to setup everything correctly. * * @param drawable the drawable object used to access the openGL functions */ @Override public void init(final GLAutoDrawable drawable) { if (drawable.getContext() == null) { return; } displayOpenGLStatusInfo(); // drawable.setGL(new DebugGL(drawable.getGL())); setupViewport(drawable); boolean releaseContext = false; if (GLContext.getCurrent() == null) { drawable.getContext().makeCurrent(); releaseContext = true; } final GL gl = drawable.getGL(); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // getContext().setSynchronized(true); gl.setSwapInterval(0); // disable vsync if (releaseContext) { drawable.getContext().release(); } }
public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); glut = new GLUT(); // float ambient[] = new float[] {0.0f, 0.0f, 0.0f, 1.0f}; float diffuse[] = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; float specular[] = new float[] {1.0f, 1.0f, 1.0f, 1.0f}; float position[] = new float[] {0.0f, 3.0f, 3.0f, 0.0f}; float lmodel_ambient[] = new float[] {0.2f, 0.2f, 0.2f, 1.0f}; float local_view[] = new float[] {0.0f}; gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, ambient, 0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, 0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0); gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 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(GL.GL_DEPTH_TEST); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearAccum(0.0f, 0.0f, 0.0f, 0.0f); /* make teapot display list */ teapotList = gl.glGenLists(1); gl.glNewList(teapotList, GL2.GL_COMPILE); glut.glutSolidTeapot(0.5f); gl.glEndList(); }
public void init(GLAutoDrawable drawable) { // Use debug pipeline, all OpenGL error codes will be automatically // converted to GLExceptions as soon as they appear drawable.setGL(new DebugGL2(drawable.getGL().getGL2())); GL2 gl = drawable.getGL().getGL2(); System.out.println("INIT GL2 IS: " + gl.getClass().getName()); // Enable VSync - this limits the rendering FPS to screen refresh rate gl.setSwapInterval(1); // Setup the drawing area and shading mode gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL2.GL_SMOOTH); // try setting this to GL_FLAT and see what happens. }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // 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(); // Move the "drawing cursor" around gl.glTranslatef(-1.5f, 0.0f, -6.0f); // Drawing Using Triangles gl.glBegin(GL2.GL_TRIANGLES); gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right // Finished Drawing The Triangle gl.glEnd(); // Move the "drawing cursor" to another position gl.glTranslatef(3.0f, 0.0f, 0.0f); // Draw A Quad gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue 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(); }
public void init(GLAutoDrawable drawable) { drawable.setAutoSwapBufferMode(false); GL2ES2 gl = drawable.getGL().getGL2ES2(); System.err.println("Entering initialization"); System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); System.err.println("GL_EXTENSIONS:"); System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); pmvMatrix = new PMVMatrix(); pmod.initShaderState(gl); st = ShaderState.getCurrent(); // Push the 1st uniform down the path st.glUseProgram(gl, true); pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); if (!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { throw new GLException("Error setting PMVMatrix in shader: " + st); } // OpenGL Render Settings gl.glClearColor(0, 0, 0, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); st.glUseProgram(gl, false); // Let's show the completed shader state .. System.out.println(st); }
// in pixels. @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.out.println(x + " " + y + " " + width + " " + height); GL2 gl = drawable.getGL().getGL2(); // calculate the aspect ratio of window double aspect = 1.0 * width / height; // in OpenGL terms, we are changing the 'projection' // this will be explained later gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Use the GLU library to compute the new projection GLU glu = new GLU(); // We are wider than high! if (aspect >= 1) { System.out.println("Showing world " + (-aspect) + " to " + (aspect) + " -1 to 1"); glu.gluOrtho2D(-aspect, aspect, -1.0, 1.0); // left, right, top, bottom } else { System.out.println("Showing world from -1 to 1 " + (-1.0 / aspect) + " to " + (1.0 / aspect)); glu.gluOrtho2D(-1, 1, -1.0 / aspect, 1.0 / aspect); // left, right, top, bottom } }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glPushMatrix(); gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f); gl.glPushMatrix(); gl.glTranslatef(-0.75f, 0.5f, 0.0f); gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glut.glutSolidTorus(0.275f, 0.85f, 20, 20); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(-0.75f, -0.5f, 0.0f); gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f); glut.glutSolidCone(1.0f, 2.0f, 20, 20); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(0.75f, 0.0f, -1.0f); glut.glutSolidSphere(1.0f, 20, 20); gl.glPopMatrix(); gl.glPopMatrix(); gl.glFlush(); }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); synchronized (this._camera) { try { gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame. NyARGLDrawUtil.drawBackGround(gl, this._camera.getSourceImage(), 1.0); this._nyar.update(this._camera); if (this._nyar.isExistMarker(this.ids[0])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[0]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } if (this._nyar.isExistMarker(this.ids[1])) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadMatrixd(this._nyar.getGlMarkerMatrix(this.ids[1]), 0); NyARGLDrawUtil.drawColorCube(gl, 40); gl.glPopMatrix(); } Thread.sleep(1); } catch (Exception e) { e.printStackTrace(); } } }
public void init(GLAutoDrawable drawable) { GL gl = drawable.getGL(); System.err.println("INIT GL IS: " + gl.getClass().getName()); gl.setSwapInterval(1); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL.GL_SMOOTH); // try setting this to GL_FLAT and see what happens. }
@Override public void display(GLAutoDrawable glad) { System.out.println("display"); GL3 gl3 = glad.getGL().getGL3(); gl3.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl3.glClear(GL3.GL_COLOR_BUFFER_BIT); programObject.bind(gl3); { programObject.setUniform(gl3, "offset", new float[] {0.5f, 0.5f}, 2); gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, vertexBufferObject[0]); gl3.glEnableVertexAttribArray(0); gl3.glEnableVertexAttribArray(1); { gl3.glVertexAttribPointer(0, 4, GL3.GL_FLOAT, false, 0, 0); gl3.glVertexAttribPointer(1, 4, GL3.GL_FLOAT, false, 0, 36 * 4 * 4); gl3.glDrawArrays(GL3.GL_TRIANGLES, 0, 36); } gl3.glDisableVertexAttribArray(0); gl3.glDisableVertexAttribArray(1); } programObject.unbind(gl3); glad.swapBuffers(); }
/** * Main drawing function. Inside this function the main part of the drawing is done. * * @param drawable the drawable object that is used to trigger the drawing actions */ @Override public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); manager.draw(); }
@Override public void init(GLAutoDrawable glad) { System.out.println("init"); canvas.setAutoSwapBufferMode(false); GL3 gl3 = glad.getGL().getGL3(); buildShaders(gl3); programObject.bind(gl3); { programObject.setUniform(gl3, "frustumScale", new float[] {1.0f}, 1); programObject.setUniform(gl3, "zNear", new float[] {1.0f}, 1); programObject.setUniform(gl3, "zFar", new float[] {3.0f}, 1); } programObject.unbind(gl3); initializeVertexBuffer(gl3); gl3.glGenVertexArrays(1, IntBuffer.wrap(vertexArrayObject)); gl3.glBindVertexArray(vertexArrayObject[0]); gl3.glEnable(GL3.GL_CULL_FACE); gl3.glCullFace(GL3.GL_BACK); gl3.glFrontFace(GL3.GL_CW); }
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-1, 1, -1, 1, 1, 10); }
/** 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 gl.glLoadIdentity(); // reset the model-view matrix gl.glTranslatef(0.0f, 0.0f, -12.0f); gl.glRotatef(rotateAnleX, 1.0f, 0.0f, 0.0f); gl.glRotatef(rotateAnleY, 0.0f, 1.0f, 0.0f); gl.glRotatef(rotateAngleZ, 0.0f, 0.0f, 1.0f); // need to flip the image float textureHeight = textureTop - textureBottom; float x1, y1, x2, y2; // used to break the flag into tiny quads gl.glBegin(GL_QUADS); for (int x = 0; x < numPoints - 1; x++) { for (int y = 0; y < numPoints - 1; y++) { x1 = (float) x / 44.0f; y1 = (float) y / 44.0f; x2 = (float) (x + 1) / 44.0f; y2 = (float) (y + 1) / 44.0f; // Texture need to flip vertically gl.glTexCoord2f(x1, y1 * textureHeight + textureBottom); gl.glVertex3f(points[x][y][0], points[x][y][1], points[x][y][2]); gl.glTexCoord2f(x1, y2 * textureHeight + textureBottom); gl.glVertex3f(points[x][y + 1][0], points[x][y + 1][1], points[x][y + 1][2]); gl.glTexCoord2f(x2, y2 * textureHeight + textureBottom); gl.glVertex3f(points[x + 1][y + 1][0], points[x + 1][y + 1][1], points[x + 1][y + 1][2]); gl.glTexCoord2f(x2, y1 * textureHeight + textureBottom); gl.glVertex3f(points[x + 1][y][0], points[x + 1][y][1], points[x + 1][y][2]); } } gl.glEnd(); if (wiggleCount == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only) for (int y = 0; y < 45; y++) { float tempHold = points[0][y][2]; // Store current value One Left Side Of // Wave for (int x = 0; x < 44; x++) { // Current Wave Value Equals Value To The Right points[x][y][2] = points[x + 1][y][2]; } points[44][y][2] = tempHold; // Last Value Becomes The Far Left Stored // Value } wiggleCount = 0; // Set Counter Back To Zero } wiggleCount++; // update the rotational position after each refresh rotateAnleX += roateSpeedX; rotateAnleY += rotateSpeedY; rotateAngleZ += rotateSpeedZ; }
@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; }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // gl.glClear(GL.GL_COLOR_BUFFER_BIT); if (derefMethod == DRAWARRAY) { gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6); } else if (derefMethod == ARRAYELEMENT) { gl.glBegin(GL2.GL_TRIANGLES); gl.glArrayElement(2); gl.glArrayElement(3); gl.glArrayElement(5); gl.glEnd(); } else if (derefMethod == DRAWELEMENTS) { int indices[] = new int[] {0, 1, 3, 4}; if (indicesBuf == null) { indicesBuf = GLBuffers.newDirectIntBuffer(indices.length); indicesBuf.put(indices); } indicesBuf.rewind(); gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf); } gl.glFlush(); // gl calls from C example's mouse routine are moved here if (setupMethod == INTERLEAVED) setupInterleave(gl); else if (setupMethod == POINTER) setupPointers(gl); }
/** OpenGL drawing function */ @Override public void display(GLAutoDrawable auto_drawable) { // get the GL context final GL gl = auto_drawable.getGL(); // clear the buffers gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // load the identity matrix gl.glLoadIdentity(); // translations so we can see drawing gl.glTranslatef(0, 0, -0.7f); if (LoadTexturePosted == true) { if (LoadGuessModelPosted == null) System.err.println("ERROR: LoadGuessModelPosted is null!"); current_Texture = AnimalTexture.findAnimalTexture(Animal_Tex_Array, LoadGuessModelPosted.getAnimalName()); LoadTexturePosted = false; } // if the current texture is null, load the question texture if (current_Texture == null) question_Texture.bind(); else current_Texture.bind(); // draw the cube gl.glPushMatrix(); gl.glRotatef(yrotate, 0.0f, 1.0f, 0.0f); drawOpenCube(gl); gl.glPopMatrix(); // increase rotation yrotate += 0.05; }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // need a valid GL context for this .. /** OpenGL .. texture.updateSubImage(textureData, 0, 20, 20, 20, 20, 100, 100); */ // Now draw one quad with the texture if (null != texture) { texture.enable(); texture.bind(); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); TextureCoords coords = texture.getImageTexCoords(); gl.glBegin(GL2.GL_QUADS); gl.glTexCoord2f(coords.left(), coords.bottom()); gl.glVertex3f(0, 0, 0); gl.glTexCoord2f(coords.right(), coords.bottom()); gl.glVertex3f(1, 0, 0); gl.glTexCoord2f(coords.right(), coords.top()); gl.glVertex3f(1, 1, 0); gl.glTexCoord2f(coords.left(), coords.top()); gl.glVertex3f(0, 1, 0); gl.glEnd(); texture.disable(); } }
/** * Renders the skybox using VBO * * @param drawable current rendering context */ public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); // Enable arrays gl.glEnableClientState(GL.GL_VERTEX_ARRAY); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); if (nVertices == 0) { createVBO(gl); } // gl.glDisable(GL.GL_CULL_FACE); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glEnable(GL.GL_TEXTURE_2D); texture.load(gl); // Vertex coordinates gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOIds[0]); gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0); gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOIds[1]); gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0); // Render // Draw All Of The Triangles At Once gl.glDrawArrays(GL.GL_TRIANGLES, 0, nVertices); // Disable Vertex Arrays gl.glDisableClientState(GL.GL_VERTEX_ARRAY); gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); // gl.glEnable(GL.GL_CULL_FACE); }
@Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // If you do not add this line // opengl will draw things in the order you // draw them in your program gl.glEnable(GL2.GL_DEPTH_TEST); // By enabling lighting, color is worked out differently. gl.glEnable(GL2.GL_LIGHTING); // When you enable lighting you must still actually // turn on a light such as this default light. gl.glEnable(GL2.GL_LIGHT0); // Light property vectors. float lightAmb[] = {0.0f, 0.0f, 0.0f, 1.0f}; float lightDifAndSpec[] = {1.0f, 1.0f, 1.0f, 1.0f}; // float lightPos[] = { 0.0f, 1.5f, 3.0f, 1.0f }; float globAmb[] = {0.2f, 0.2f, 0.2f, 1.0f}; // float globAmb[] = {0.5f,0.5f,0.5f,1f}; // Light properties. gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, lightAmb, 0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, lightDifAndSpec, 0); gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, lightDifAndSpec, 0); // gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPos,0); gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL2.GL_BLEND); }
public final void init(final GLAutoDrawable drawable) { Debug.print(); final GL gl = drawable.getGL(); gl.glEnable(GL.GL_DEPTH_TEST); TextureManager.clear(); }
@Override public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int width, int height) { GL2 gl = drawable.getGL().getGL2(); // Computing the aspect ratio float aspect = (float) width / height; // Setting the viewport, the area that is displayed, to cover the whole window gl.glViewport(0, 0, width, height); // Setting the perspective projection with an aspect that matches that of the viewport // Choose Projection Matrix gl.glMatrixMode(GL_PROJECTION); // Resets the Projection Matrix gl.glLoadIdentity(); // gluPerspective(fovy, aspect, zNear, zFar); // Instructions taken from http://www.opengl.org/sdk/docs/man2/xhtml/glTranslate.xml // fovy : Specifies the field of view angle, in degrees, in the y direction. // aspect : Specifies the aspect ratio that determines the field of view in the x direction. The // aspect ratio is the ratio of x (width) to y (height). // zNear : Specifies the distance from the viewer to the near clipping plane (always positive). // zFar : Specifies the distance from the viewer to the far clipping plane (always positive). glu.gluPerspective(45.0, aspect, 0.1, 100.0); gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); }