Y
Y
YaroslavTkach2014-01-14 18:55:57
Graphic arts
YaroslavTkach, 2014-01-14 18:55:57

How to rotate a texture by a certain degree without rotating the polygon on which the texture is applied?

How to rotate a texture by a certain degree without rotating the polygon on which the texture is applied? Graphic editors are not allowed.

glBegin(GL_QUADS);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(0.001f * (sin(PI*60.0f/180.0f)), 1.0f *  cos(PI*60.0f/180.0f));
    glVertex3f(-2.0f, 1.0f, -2.5f);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(1.0f  * (sin(PI*60.0f/180.0f)), 1.0f *  cos(PI*60.0f/180.0f)); glVertex3f(2.0f, 1.0f, -2.5f);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(1.0f  * (sin(PI*60.0f/180.0f)), 0.001f *  cos(PI*60.0f/180.0f)); glVertex3f(2.0f, 1.0f, 2.5f);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(0.001f * (sin(PI*60.0f/180.0f)), 0.001f *  cos(PI*60.0f/180.0f)); glVertex3f(-2.0, 1.0f, 2.5f);
  glEnd();
}

Any ideas for this command glTexCoord2f(0.001f * (sin(PI*60.0f/180.0f)), 1.0f * cos(PI*60.0f/180.0f));
but the results are not what you want. Please fix or suggest an alternative.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kerman, 2014-01-14
@Kerman

Actually, no way.
But if you really want to:
1. You need to make a texture that is larger than the polygon at any angle of rotation. Then rotate the texture coordinates about the center.
2. If the texture is made "to the edge" of the polygon and it is "looped" during rotation, then only rendering to textures will help here

Y
YaroslavTkach, 2014-01-14
@YaroslavTkach

Kerman, In general, you can rotate by changing the coordinates! but here I need a hitch at a certain angle and not from a lantern!

K
Kerman, 2014-01-15
@Kerman

I'll post what is probably the best solution in a separate answer:

//Переключаемся в режим матрицы текстур
glMatrixMode(GL_TEXTURE);
//Получаем матрицу по умолчанию
glLoadIdentity();
//Смещаемся в центр, вокруг которого будет вращение
glTranslatef(0.5,0.5,0.0);
//вращаем
glRotatef(angle,0.0,0.0,1.0);
//возвращаем центр на место
glTranslatef(-0.5,-0.5,0.0);
//возвращаем режим матрицы назад
glMatrixMode(GL_MODELVIEW);

After that, you can draw a square. After drawing the square, you need to reset the texture matrix so that the rest of the textures do not rotate:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question