gpt4 book ai didi

iPhone OpenGL : Tiling textures

转载 作者:行者123 更新时间:2023-12-03 19:45:29 25 4
gpt4 key购买 nike

我有点卡在平铺纹理上。基本上我想在变换对象时平铺纹理。因此,当我将 glScale 缩放到 20、20、20 时,我希望将纹理平铺到 1x1x1 的正方形。纹理设置为 1x1,

    - (void)loadTextures:(NSString *)textureName andWithIndex:(int)index { 

// load image as a CG ref
CGImageRef textureImage = [UIImage imageNamed:textureName].CGImage;
// if failed, bail
if (!textureImage) {
NSLog(@"Error: failed to load texture");
return;
}


// figure out the width and height
int texWidth = CGImageGetWidth(textureImage);
int texHeight = CGImageGetHeight(textureImage);

// alloc space for the texture
GLubyte *textureData = (GLubyte *)malloc(texWidth * texHeight * 4);

// create a CA context ref
CGContextRef textureContext = CGBitmapContextCreate(
textureData, texWidth, texHeight, 8, texWidth * 4,
CGImageGetColorSpace(textureImage),
kCGImageAlphaPremultipliedLast
);

// draw the image to in-memory buffer
CGContextDrawImage(textureContext, CGRectMake(0,0,texWidth,texHeight), textureImage);

// done with context - release it
CGContextRelease(textureContext);

// have GL create handle for our texture
glGenTextures(1, &textures[index]);

// tell GL that the image is 2D
glBindTexture(GL_TEXTURE_2D, textures[index]);

// send our data down to GL, copy into graphics hardware
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);

// free our in-memory copy of the data
free(textureData);

// specify min/max filters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

// tell GL to turn on textures
glEnable(GL_TEXTURE_2D);
}

最佳答案

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(20,20,1);
glMatrixMode(GL_MODELVIEW);

关于iPhone OpenGL : Tiling textures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4228947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com