Complete code:
- import javax.media.opengl.GL2;
- import processing.opengl.Texture;
- import java.nio.ByteBuffer;
- GL2 gl;
- PGraphicsOpenGL pgl;
- PImage resource;
- void setup() {
- size( 1280, 768, OPENGL);
- pgl = (PGraphicsOpenGL) g; // g may change
- gl = pgl.beginPGL().gl.getGL2();
- resource = loadImage( "/.../texture.png" );
- resource.loadPixels();
- }
- void draw() {
- background( 0 );
- loadMatrix();
- pgl.beginPGL();
- gl.glTranslatef(width/2, height/2, 0);
- gl.glColor4f( 1,1,1,1 );
- gl.glEnable( gl.GL_TEXTURE_2D );
- gl.glBindTexture( gl.GL_TEXTURE_2D, 1 );
- float r = frameCount * 0.001f;
- if ( r > 0.5f )
- r = 0.5f;
- gl.glBegin( gl.GL_QUADS );
- gl.glColor4f( 1,1,1,1 );
- gl.glTexCoord2f( r, r );
- gl.glVertex3f(-100,-100,0);
- gl.glTexCoord2f( r, r*2 );
- gl.glVertex3f(100,-100,0);
- gl.glColor4f( 1,0,0,1 );
- gl.glTexCoord2f( r*2,r*2 );
- gl.glVertex3f(100,100,0);
- gl.glTexCoord2f( r*2,r );
- gl.glVertex3f(-100,100,0);
- gl.glEnd();
- gl.glDisable( gl.GL_TEXTURE_2D );
- pgl.endPGL();
- }