1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| In reshape: gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(0, GL_WIDTH, GL_HEIGHT, 0, -1, 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity();
In draw: gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); gl.glClear(GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_COLOR_BUFFER_BIT);
gl.glEnable(GL2.GL_TEXTURE_2D); gl.glEnable(GL2.GL_BLEND); gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glEnableClientState(GL2.GL_COLOR_ARRAY); gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); gl.glLoadIdentity();
final Texture mTest = TextureIO.newTexture(getClass().getResource("/images/glass.png"), false, TextureIO.PNG); final float[] coordData = { 0, 0, 0, 1, 1, 0, 1, 1, }; final float[] vertices = { 0.0f, 0.0f, 0, 0.0f, 128, 0, 128, 0.0f, 0, 128, 128, 0 }; verts = Buffers.newDirectFloatBuffer(vertices.length); verts.put(vertices).position(0);
coords = Buffers.newDirectFloatBuffer(coordData.length); coords.put(coordData).position(0);
mTest.enable(gl); mTest.bind(gl); gl.glLoadIdentity(); gl.glTranslatef(100, 100, 0); gl.glVertexPointer(3, GL2.GL_FLOAT, 0, verts); gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, coords); gl.glDrawArrays(GL2.GL_TRIANGLE_STRIP, 0, 4); |