0

我有一段代码可以获取 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); 我想旋转纹理,但不起作用,所以有人可以帮助我吗?非常感谢你!

4

1 回答 1

0

试试这个,而不是你的代码,将包装设置为 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);
于 2013-11-14T12:08:56.890 回答