0
$\begingroup$

I'm trying to apply a texture to 4 different triangle strips using JOGL (OpenGL/Java). I'm trying to make a 1000×1000 path in a square, where the path is 100 wide. The texture should be stamped 10 times on each side (though the corner pieces will have a diagonal discontinuity). I'm making 4 trapezoids here:

float[] positions = { /* S,W,N,E */ 500,-50,500, 400,-50,400, -500,-50,500, -400,-50,400, -500,-50,500, -400,-50,400, -500,-50,-500, -400,-50,-400, -500,-50,-500, -400,-50,-400, 500,-50,-500, 400,-50,-400, 500,-50,-500, 400,-50,-400, 500,-50,500, 400,-50,400 }; float[] textureCoords = { 0f,0f, 1f,1f, 0f,10f, 1f,9f, 0f,0f, 1f,1f, 0f,10f, 1f,9f, 0f,0f, 1f,1f, 0f,10f, 1f,9f, 0f,0f, 1f,1f, 0f,10f, 1f,9f }; 

I then get this data into VBOs, and every frame I draw with the following code:

gl.glActiveTexture(GL_TEXTURE0); gl.glBindTexture(GL_TEXTURE_2D, textureIDs[0]); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); for (int i=0; i<4; i++) gl.glDrawArrays(GL_TRIANGLE_STRIP, i*4, 4); 

Texture smeared out

The texture appears to be loading fine. You can see that it looks okay in one triangle of the trapezoid, within the range (0,0 -> 1,1). But as soon as my interpolated (s,t) values leave that range, it just smears things. I'm very confused by this--isn't it supposed to tile, when I have texture coordinates beyond 1.0? Does this have something to do with using GL_TRIANGLE_STRIP to draw?

$\endgroup$

1 Answer 1

3
$\begingroup$

You are on the right track with setting GL_TEXTURE_WRAP_S to GL_REPEAT. However, GL_TEXTURE_WRAP_S affects only the first texture coordinate, called $ s $. In your code, you are trying to use the second coordinate, $ t $, to repeat the texture. For that, you need to set GL_TEXTURE_WRAP_T:

gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 

Also, note that you do not necessarily need to set these texture parameters every frame. You can just set them once when creating the texture.


* Texture coordinates are also often labelled $ u $ and $ v $, but OpenGL labels them $ s $ and $ t $.

$\endgroup$
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.