我有一段代码可以获得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);
}
}
这是问题所在:
//旋转纹理,但不起作用
静态浮动角度= 1;
if(角度<200)
角+ = 2;
其他
angle = 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);
我想旋转纹理,但不起作用,所以
有人可以帮帮我吗?非常感谢你!
答案 0 :(得分:0)
使用wrap设置为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);