PDA

View Full Version : OpenG Texture on wheel



jamesK
12-20-2016, 03:43 AM
I am trying to place texture on a circle but when I do, the texture appears on the circle four times instead of once. Is there something I am missing? I am using the bmp format for the image in the initscene

This is what I am doing in the render scene to set the texture on the wheel

GL11.glPushMatrix();
{
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D,circleTextur es.getTextureID());

GL11.glTranslatef(0.0f, 0.0f, -10.0f);
drawWheel();
}
GL11.glPopMatrix();
This creates the circle

void drawCircle()
{
GL11.glBegin(GL11.GL_POLYGON);
for(int i =0; i <= 400; i++){
double angle = (2 * Math.PI * i / 300);
double x = Math.cos(angle);
double y = Math.sin(angle);
GL11.glTexCoord2d(x, y);
GL11.glVertex2d(x,y);

}
GL11.glEnd();
}

john_connor
12-20-2016, 04:10 AM
texture coordinates begin at 0 and end with 1
if your coordinates go from -1 to 1 (as your code suggests), you either end up with a distorted texture or with a repetitive texture, depending on the texture parameters you've set

GL_REPEAT is likely what you've got, if a texture coordinate exceeds the [0;1] limits, the texture repeats itself

instead of
tex.x = cos(angle)
tex.y = sin(angle)

do this
tex.x = 0.5f * (1 + cos(angle))
tex.y = 0.5f * (1 + sin(angle))

jamesK
12-20-2016, 04:31 AM
Hi, that worked. Thank you


texture coordinates begin at 0 and end with 1
if your coordinates go from -1 to 1 (as your code suggests), you either end up with a distorted texture or with a repetitive texture, depending on the texture parameters you've set

GL_REPEAT is likely what you've got, if a texture coordinate exceeds the [0;1] limits, the texture repeats itself

instead of
tex.x = cos(angle)
tex.y = sin(angle)

do this
tex.x = 0.5f * (1 + cos(angle))
tex.y = 0.5f * (1 + sin(angle))