Skip to main content
gamedev.net
🔒 Locked

Texture rotation problem

Started by meeshoo Nov 15, 2004 at 5:38 PM 9 replies 1.3k views
Original Post
meeshoo
meeshoo
hi there. well, here is my problem. let's say i have a planar mesh made up of severel triangles, with the righ texture coordinates(meaning that, when i apply a texture, it applies to my mesh like to a single quad, with mesh corners to texture corners). now i'm trying to rotate the texture around the mesh middle point, so i write; glMatrixMode(GL_TEXTURE); glTranslate(0.5, 0.5, 0); glRotate(myAngle, 0.0, 0.0, 1.0); glTranslate(-0.5, -0.5, 0); glMatrixMode(GL_MODELVIEW); the texture is rotating indeed, but an unwanted efect appears, it is getting skewed really bad. to test it, there is a little rectangle drawn in the middle of the texture. when the texture is rotating, the rectangle becames a parallelogram, then a long rectangle(crossing textures' borders) then another parallelogram and then the normal rectangle. i pretty understood that this is a normal thing to happen, but can anyone tell me how to avoid it?
meeshoo
meeshoo
common, guys, isn't there anyone who can tell me how to rotate a texture without distortion?should i try to rotate the texture coordinates too?
Zakwayda
Zakwayda
Are you pushing and popping the texture matrix every time you render? Otherwise you might get some strange results.
Dave Hunt
Dave Hunt
It sounds like you want Orthogonal Projection. Take a look at glOrtho().
meeshoo
meeshoo
hi there. thanks for looking to my problem. so a few answers first:
1.yes, i am pushing and popping the texture matrix
2.no, GL_REPEAT, GL_CLAMP and all other modes are doing the same result
3.no, is not about parallel projection

4.some screenshots, as you request

1.initial state

2.after aprox.80-90 degrees of rotation

3.after aprox 200 degrees of rotation


that's it. i hop it helps
_DarkWIng_
_DarkWIng_
A bit offtopic: You actualy have to put images on some server to show them. You can't just link to C:\image.jpg.
You should never let your fears become the boundaries of your dreams.
meeshoo
meeshoo
sorry about that, i will correct this later, now i'm not at home.

[Edited by - meeshoo on November 17, 2004 2:31:43 AM]
Enigma
Enigma
This works fine for me:
#include <GL/glut.h>#include "Texture.h"float angle = 0;void reshape(int width, int height){	if (height == 0)	{		height = 1;	}	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glViewport(0, 0, width, height);	gluPerspective(45.0f, GLfloat(width) / GLfloat(height), 0.1f, 50.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}Texture tex;void display(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();	glTranslatef(0, 0, -25);	glMatrixMode(GL_TEXTURE);	glLoadIdentity();	glTranslatef(0.5, 0.5, 0);	glRotatef(angle, 0, 0, 1);	glTranslatef(-0.5, -0.5, 0);	angle += 1;	glMatrixMode(GL_MODELVIEW);	glBegin(GL_QUADS);		glTexCoord2f(0, 0);		glVertex2f(-5, -5);		glTexCoord2f(1, 0);		glVertex2f(5, -5);		glTexCoord2f(1, 1);		glVertex2f(5, 5);		glTexCoord2f(0, 1);		glVertex2f(-5, 5);	glEnd();	glutSwapBuffers();}int main(int argc, char** argv){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);	glutInitWindowPosition(0, 0);	glutInitWindowSize(512,512);	glutCreateWindow("Texture Rotation Test");	glutReshapeFunc(reshape);	glutDisplayFunc(display);	glutIdleFunc(display);	tex.loadBmp("img3.bmp");	glEnable(GL_TEXTURE_2D);	glutMainLoop();	return 0;}


Enigma
meeshoo
meeshoo
hi there. well, i have the exactly transforming code and the texture is still skewed. i forgot to mention the app is in opengl es, so that might be the problem. dont't know but i've managed to implement the efect anyway. sorry for disturbing and happy coding.
carb
carb
Texture matrix stacks are only 2 levels deep in OpenGL ES. Meaning you can't push more than once without a pop. Don't know if that's of any help.

- carb
Ben

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.