nsimage에서 gluint 텍스처를 얻는 것
-
21-12-2019 - |
문제
mac os
를 사용하여 Syphon-SDK
앱에서 작업하고 있습니다.
Syphon
는 입력 소스로 사용하는 비디오 처리 도구에서 사용할 수있는 렌더링 데이터를 "게시"하는 서비스입니다.
샘플 프로젝트 ( http://syphon.v002.info//a>) 렌더링을 가져옵니다.Quartz Composer
파일의 데이터를 게시하고 게시합니다.
내 프로젝트에서는 정적 NSImage
를 렌더링해야하며 OpenGL
를 사용해야하고 결과 텍스처를 게시해야합니다.
해결책
여기는 다음과 같습니다 :
- (void)textureFromImage:(NSImage*)theImg textureName:(GLuint*)texName
{
NSBitmapImageRep* bitmap = [NSBitmapImageRep alloc];
int samplesPerPixel = 0;
NSSize imgSize = [theImg size];
[theImg lockFocus];
[bitmap initWithFocusedViewRect:
NSMakeRect(0.0, 0.0, imgSize.width, imgSize.height)];
[theImg unlockFocus];
// Set proper unpacking row length for bitmap.
glPixelStorei(GL_UNPACK_ROW_LENGTH, [bitmap pixelsWide]);
// Set byte aligned unpacking (needed for 3 byte per pixel bitmaps).
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
// Generate a new texture name if one was not provided.
if (*texName == 0)
glGenTextures (1, texName);
glBindTexture (GL_TEXTURE_RECTANGLE_EXT, *texName);
// Non-mipmap filtering (redundant for texture_rectangle).
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
samplesPerPixel = [bitmap samplesPerPixel];
// Nonplanar, RGB 24 bit bitmap, or RGBA 32 bit bitmap.
if(![bitmap isPlanar] &&
(samplesPerPixel == 3 || samplesPerPixel == 4))
{
glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0,
samplesPerPixel == 4 ? GL_RGBA8 : GL_RGB8,
[bitmap pixelsWide],
[bitmap pixelsHigh],
0,
samplesPerPixel == 4 ? GL_RGBA : GL_RGB,
GL_UNSIGNED_BYTE,
[bitmap bitmapData]);
}
else
{
// Handle other bitmap formats.
}
// Clean up.
[bitmap release];
}
.
다른 사람을 돕기 위해
제휴하지 않습니다 StackOverflow