Xer
YaBB Newbies
Offline
Posts: 25
Re: Texture in 'pure' openGL
Reply #12 - Apr 29th , 2008, 3:23pm
I have modified the code to the following. if I set the org_opengl to false, it seems fine; however, if I set the org_opengl to ture, the texture is distorted. Is the processing bug??? Plz help ======================================================= import processing.opengl.*; import javax.media.opengl.*; import com.sun.opengl.util.texture.*; boolean org_opengl=true; Texture tex; PImage ti; void setup() { size(480,320, OPENGL); if(org_opengl) { ti = loadImage("test.png"); textureMode(NORMALIZED); } else { try { tex=TextureIO.newTexture(new File(dataPath("test.png")),true); } catch(Exception e) { println(e); } } } void draw() { background(0); // the texture size is 300x300 if(org_opengl) { beginShape(); texture(ti); vertex(290, 160, 1, 0.5); vertex(265, 205, 236.0/300.0, 1); vertex(215, 205, 64.0/300.0, 1); vertex(190, 160, 0, 0.5); vertex(215, 115, 64.0/300.0, 0); vertex(265, 115, 236.0/300.0, 0); endShape(); } else { PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; GL gl = pgl.beginGL(); tex.bind(); tex.enable(); gl.glBegin(GL.GL_POLYGON); gl.glNormal3f( 0.0f, 0.0f, 1.0f); gl.glTexCoord2f(1, 0.5); gl.glVertex2f(290, 160); gl.glTexCoord2f(236.0/300.0, 1); gl.glVertex2f(265, 205); gl.glTexCoord2f(64.0/300.0, 1); gl.glVertex2f(215, 205); gl.glTexCoord2f(0, 0.5); gl.glVertex2f(190, 160); gl.glTexCoord2f(64.0/300.0, 0); gl.glVertex2f(215, 115); gl.glTexCoord2f(236.0/300.0, 0); gl.glVertex2f(265, 115); gl.glEnd(); tex.disable(); pgl.endGL(); } }