/** * Render the fragment data. * * @param gl */ public void render( GL gl ) { if ( !isEnabled() ) { LOG.warn( "Current fragment is not enabled, discarding it." ); return; } gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glBufferObjectIds[0] ); gl.glVertexPointer( 3, GL.GL_FLOAT, 0, 0 ); gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glBufferObjectIds[1] ); gl.glNormalPointer( normalGLType, 0, 0 ); gl.glBindBufferARB( GL.GL_ELEMENT_ARRAY_BUFFER_ARB, glBufferObjectIds[2] ); gl.glDrawElements( GL.GL_TRIANGLES, data.getNumTriangles() * 3, GL.GL_UNSIGNED_SHORT, 0 ); }
/** * Enable this Fragment texture by generating a buffer object in the given context. * * @param gl * to generate the buffer object to. */ public void enable( GL gl ) { if ( textureID == -1 ) { // will return -1 if the texture was not loaded on the gpu textureID = texture.enable( gl, this.fragment.getId() ); } // System.out.println( "Fragment bound to: " + fragment.getId() + "| gl texture id: " + textureID ); if ( textureID != -1 ) { if ( glBufferObjectIds == null ) { // generateTexCoordsBuffer( xOffset, yOffset ); glBufferObjectIds = new int[1]; gl.glGenBuffersARB( 1, glBufferObjectIds, 0 ); // bind vertex buffer object (vertex coordinates) gl.glBindBufferARB( GL.GL_ELEMENT_ARRAY_BUFFER_ARB, glBufferObjectIds[0] ); gl.glBufferDataARB( GL.GL_ELEMENT_ARRAY_BUFFER_ARB, texCoordsBuffer.capacity() * 4, texCoordsBuffer, GL.GL_STATIC_DRAW_ARB ); } } }
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glBufferObjectIds[0] ); gl.glBufferDataARB( GL.GL_ARRAY_BUFFER_ARB, vertexBuffer.capacity() * 4, vertexBuffer, GL.GL_STATIC_DRAW_ARB ); gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glBufferObjectIds[1] ); if ( normalsBuffer instanceof ByteBuffer ) { normalGLType = GL.GL_BYTE; gl.glBindBufferARB( GL.GL_ELEMENT_ARRAY_BUFFER_ARB, glBufferObjectIds[2] ); gl.glBufferDataARB( GL.GL_ELEMENT_ARRAY_BUFFER_ARB, indexBuffer.capacity() * 2, indexBuffer, GL.GL_STATIC_DRAW_ARB );
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, 0 );
gl.glEnable( GL.GL_TEXTURE_2D ); gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY ); gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glVCB ); gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, 0 ); gl.glBindTexture( GL.GL_TEXTURE_2D, tId ); gl.glEnable( GL.GL_TEXTURE_2D ); gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY ); gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, glVCB ); gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, 0 );