我在opengles中获得纹理,现在我想旋转纹理,但失败了
我有一段代码可以获得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);
}
}这里是问题://旋转纹理,但没有工作static float angle = 1;
如果(角度<200)角度+ = 2; 其他角度= 1; glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(角度,.0,0.0,1.0); 的glTranslatef(0.0,0.0,0.0); 的glTranslatef(-0.5,-0.5,0.0); glMatrixMode(GL_MODELVIEW); 我想旋转纹理,但不起作用,所以有人可以帮助我? 谢谢你多谢!
使用包装设置为GL_CLAMP的方法试试这个代替你的代码。 你应该能够看到纹理旋转。
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/33901.html
上一篇: i get the texture in opengles,now i want to rotate the texture,but failed