moka
Junior Member
Offline
Posts: 66
Texture GL_QUADS: texture does not fit.
Apr 13th , 2008, 11:37am
I am currently simply trying to translate some of my processing programs to native openGL and have a simple problem which I still could not fix: When I try to draw a simple quad with a texture, the texture always does not texture the whole quad. Its propably a simple thing I just don't see right now. Here is the code. I first draw a filled quad and afterwards a textured one to see if they match. Apparently they dont: import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.*; import processing.opengl.*; import java.nio.*; PGraphicsOpenGL pgl; // g may change GL gl; // always use the GL object returned by beginGL GLU glu; PImage test; void setup() { size(640, 480, OPENGL); hint(ENABLE_OPENGL_4X_SMOOTH); colorMode(RGB, 1.0, 1.0, 1.0); pgl = (PGraphicsOpenGL) g; gl = pgl.beginGL(); glu = ( (PGraphicsOpenGL) g ).glu; test = loadImage("test.jpg"); } void draw(){ background(0); pgl.beginGL(); gl.glDisable(GL.GL_DEPTH_TEST); gl.glDepthMask(false); gl.glTranslatef(width/2, height/2, 0); gl.glBegin(GL.GL_QUADS); gl.glColor4f(1.0, 0.5, 1.0, 1.0); gl.glVertex2f (0.0, 0.0); gl.glVertex2f (frameCount, 0.0); gl.glVertex2f (frameCount, frameCount); gl.glVertex2f (0.0, frameCount); gl.glEnd(); gl.glEnable(GL.GL_TEXTURE_2D); pgl.bindTexture(test); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0.0,0.0); gl.glVertex2f (0.0, 0.0); gl.glTexCoord2f(1.0,0.0); gl.glVertex2f (frameCount, 0.0); gl.glTexCoord2f(1.0,1.0); gl.glVertex2f (frameCount, frameCount); gl.glTexCoord2f(0.0,1.0); gl.glVertex2f (0.0, frameCount); gl.glEnd(); gl.glDisable(GL.GL_TEXTURE_2D); gl.glEnable(GL.GL_DEPTH_TEST); pgl.endGL(); }