두 텍스처를 바인딩하여 텍스처를 얻으려고합니다. 그러나 하나의 텍스처 만 화면에 표시됩니다. 코드 울부 짖는 소리가 .. 내가 텍스처를로드하는 방법두 텍스처를 병합하는 방법
- (void)loadTexture:(NSString *)name intoLocation:(GLuint)location {
CGImageRef textureImage = [UIImage imageNamed:name].CGImage;
if (textureImage == nil) {
NSLog(@"Failed to load texture image");
return;
}
NSInteger texWidth = CGImageGetWidth(textureImage);
NSInteger texHeight = CGImageGetHeight(textureImage);
GLubyte *textureData = (GLubyte *)malloc(texWidth * texHeight * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData,
texWidth, texHeight,
8, texWidth * 4,
CGImageGetColorSpace(textureImage),
kCGImageAlphaPremultipliedLast);
CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)texWidth, (float)texHeight), textureImage);
CGContextRelease(textureContext);
glActiveTexture(location);
glGenTextures(3, &location);
glBindTexture(GL_TEXTURE_2D,2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
free(textureData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glEnable(GL_TEXTURE_2D);}
그리고 여기에 내가 텍스처로드를 호출하는 방법입니다 :
- (BOOL)createFramebuffer {
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8,
kEAGLDrawablePropertyColorFormat, nil];
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context]) {
[self release];
}
[self setupView];
glGenTextures(0, &textures[3]);
[self loadTexture:@"image1.png" intoLocation:textures[1]];
[self loadTexture:@"image2.png" intoLocation:textures[0]];
glGenFramebuffersOES(2, &viewFramebuffer);
glGenRenderbuffersOES(2, &viewRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
if (USE_DEPTH_BUFFER) {
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
}
if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
return YES;
}
I에 대한 추가 분명하다 지금 희망을 무엇 나는 필요하다.
당신이하려는 것을 설명하십시오. "두 텍스처 합치기"라는 문맥을 추가하지 않아도 아무 의미도 없습니다. 또한 지금까지 정확히 무엇을 시도했는지 설명하십시오. – derhass
"병합"이라고 말하면 실제로 의미하는 것은 "혼합"이라고 생각합니다. 이 경우 실제로 텍스처를 얻지는 않지만 하나의 텍스처를 사용하여 그리기 결과를 이전 결과 (예 : 다른 텍스처)와 결합하여 새 픽셀을 생성합니다. 대부분의 경우 (예 : 알파 블렌딩) 주문 관련 작업입니다. 어떤 경우이든, 어떤 종류의 코드 나 더 나은 설명을 보지 않고도이를 대답 할 방법이 없습니다. –