-1
텍스처로 큐브에 .png 파일을로드하려고합니다.큐브 ios에 텍스처로 .png 파일로드
[self loadTexture:&myTexture fromFile:@"my_png.png"];
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE);
이것은로드하는 기능이지만 불행히도 작동하지 않습니다.
- (void)loadTexture:(GLuint *)newTextureName fromFile:(NSString *)fileName {
// Load image from file and get reference
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
CGImageRef imageRef = [image CGImage];
if(imageRef) {
// get width and height
size_t imageWidth = CGImageGetWidth(imageRef);
size_t imageHeight = CGImageGetHeight(imageRef);
GLubyte *imageData = (GLubyte *)malloc(imageWidth * imageHeight * 4);
memset(imageData, 0, (imageWidth * imageHeight * 4));
CGContextRef imageContextRef = CGBitmapContextCreate(imageData, imageWidth, imageHeight, 8, imageWidth * 4, CGImageGetColorSpace(imageRef), kCGImageAlphaPremultipliedLast);
// Make CG system interpret OpenGL style texture coordinates properly by inverting Y axis
CGContextTranslateCTM(imageContextRef, 0, imageHeight);
CGContextScaleCTM(imageContextRef, 1.0, -1.0);
CGContextDrawImage(imageContextRef, CGRectMake(0.0, 0.0, (CGFloat)imageWidth, (CGFloat)imageHeight), imageRef);
CGContextRelease(imageContextRef);
glGenTextures(1, newTextureName);
glBindTexture(GL_TEXTURE_2D, *newTextureName);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
free(imageData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
}
이 문제를 해결할 생각이 있습니까?
스택 오버플로에 오신 것을 환영합니다! 문제를 더 자세하게 설명하면 더/더 나은 답을 얻을 수 있습니다. * 어떻게 작동하지 않습니까? 그 동안,이 모든 것을 더 쉽게 해주는'GLKTextureLoader' 클래스를 조사하고 싶을지도 모릅니다. – rickster