최근 OpenGL에서 시작하여 화면 및 프레임 버퍼에 배경 이미지를 그릴 수있었습니다. 모두 잘 작동합니다. 새 텍스처를 만들어 프레임 버퍼에 추가하면 문제가 발생합니다.OpenGL iphone에서 터치하여 텍스처를 그립니다.
{
[EAGLContext setCurrentContext:context]; glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); glViewport(0, 0, backingWidth, backingHeight); // Clear screen glClear(GL_COLOR_BUFFER_BIT); // Render player ship [playerShip drawAtPoint:CGPointMake(160, 240)]; // glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); // [context presentRenderbuffer:GL_RENDERBUFFER_OES]; }
제가
// glBindRenderbufferOES (GL_RENDERBUFFER_OES, viewRenderbuffer)를 상기 두 개의 라인을 주석 처리하는 경우;
// [컨텍스트 presentRenderbuffer : GL_RENDERBUFFER_OES];
은 내가 아래 코드를 그리기하고 새로운 질감 얻을 해달라고 :
NSInteger myDataLength = 20 * 20 * 4; GLubyte * buffer = (GLubyte *) malloc (myDataLength); glReadPixels (위치 .x-10, 위치 .y-10, 20, 20, GL_RGBA, GL_UNSIGNED_BYTE, 버퍼);
// gl renders "upside down" so swap top to bottom into new array.
// there's gotta be a better way, but this works.
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
for(int y = 0; y < 20; y++)
{
for(int x = 0; x < 20 * 4; x++)
{
buffer2[(19 - y) * 20 * 4 + x] = buffer[y * 4 * 20 + x];
}
}
// make data provider with data.
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);
// prep the ingredients
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * 20;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
// make the cgimage
CGImageRef imageRef = CGImageCreate(20, 20, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
// then make the uiimage from that
UIImage *myImage = [UIImage imageWithCGImage:imageRef];
Texture2D *texture = [[Texture2D alloc] initWithImage:myImage];
UIImageWriteToSavedPhotosAlbum(myImage, self, nil, nil);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity();
[texture drawAtPoint:location];
glPopMatrix();
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
은 내가 실수를하고있는 중이 야 어디 잘 모릅니다. 나는 이것에 초보적이다.
OpenGL을 처음 접한 이래로 당신이 말하는 것에 대해 자세히 설명해주십시오. 어떻게해야합니까? 내가 한 것은 진행하는 올바른 방법 일까? PhotoBooth처럼 이미지 워프를 시도하고 있습니다. – DivineDesert
@Dimple OpenGL에는 3D 장면을 그릴 때 가시성을 감지하는 데 사용되는 선택적인 깊이 버퍼가 있습니다 (전경 오브젝트는 z 값이 배경 오브젝트보다 작아서 어떤 픽셀을 그릴 지 알 수 있습니다). 2D 텍스처를 사진처럼 렌더링 할 때 Z 버퍼는 생산성을 떨어 뜨릴 수 있으며 결국에는 새로운 텍스처가 렌더링되지 않게합니다 (깊이 버퍼링). z 버퍼를 비활성화하면 도움이 될 수 있습니다. 그러나 그것이 당신의 문제인지 확실하지 않습니다. 아마 더 완벽한 예제를 게시하면 도움이 될 것입니다. – KPK