i get the texture in opengles,now i want to rotate the texture,but failed
I have a piece of code that get the texture of opengles
-(void)textureFromName:(UIImage *)name
{
CGImageRef brushImage;
CGContextRef brushContext;
GLubyte *brushData;
size_t width, height;
GLuint texId;
brushImage = [name CGImage];
// Get the width and height of the image
width = CGImageGetWidth(brushImage)*4;
height = CGImageGetHeight(brushImage);
// Make sure the image exists
if(brushImage) {
// Allocate memory needed for the bitmap context
brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
// Use the bitmatp creation function provided by the Core Graphics framework.
brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the image to the context.
CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(brushContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &texId);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, texId);
**/*************************************************/
//rotate the texture,but didn't work
static float angle = 1;
if(angle < 200)
angle+=2;
else
angle = 1;
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(angle,.0,0.0,1.0);
glTranslatef(0.0,0.0,0.0);
glTranslatef(-0.5,-0.5,0.0);
glMatrixMode(GL_MODELVIEW);
/*************************************************/**
// Set the texture parameters to use a minifying filter and a linear filer (weighted average)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Specify a 2D texture image, providing the a pointer to the image data in memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);
// Release the image data; it's no longer needed
free(brushData);
}
} here is the problem: //rotate the texture,but didn't work static float angle = 1;
if(angle < 200) angle+=2; else angle = 1; glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(angle,.0,0.0,1.0); glTranslatef(0.0,0.0,0.0); glTranslatef(-0.5,-0.5,0.0); glMatrixMode(GL_MODELVIEW); i want to rotate the texture,but doesn't work,so someone can help me ? thank you evry much!
Try this instead of your code with the wrap set to GL_CLAMP. You should be able to see the texture rotate.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5,0.5,0.0);
glRotatef(angle,.0,0.0,1.0);
glTranslatef(-0.5,-0.5,0.0);
glMatrixMode(GL_MODELVIEW);
链接地址: http://www.djcxy.com/p/33902.html
上一篇: GLSL着色器呈现纹理不保存alpha值