关于将uiview的内容转换为纹理,OpenGL es
我想将当前显示在屏幕上的uiview的内容转换为OpenGL es纹理。 但是,当我这么做的时候,我遇到了一些麻烦。 由OpenGL es处理的纹理大小是输入图像的大小。当纹理渲染到屏幕时,显示纹理内容的uiview的大小已更改 因此,如果我通过以下代码直接读取uiview的内容,_drawView属于uiview类关于将uiview的内容转换为纹理,OpenGL es,uiview,opengl-es,textures,Uiview,Opengl Es,Textures,我想将当前显示在屏幕上的uiview的内容转换为OpenGL es纹理。 但是,当我这么做的时候,我遇到了一些麻烦。 由OpenGL es处理的纹理大小是输入图像的大小。当纹理渲染到屏幕时,显示纹理内容的uiview的大小已更改 因此,如果我通过以下代码直接读取uiview的内容,_drawView属于uiview类 //convert current uiview to texture, opengl es GLubyte *pixelBuffer = (GLubyte *)m
//convert current uiview to texture, opengl es
GLubyte *pixelBuffer = (GLubyte *)malloc(4 * _drawView.bounds.size.width * _drawView.bounds.size.height);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context =
CGBitmapContextCreate(pixelBuffer,
_drawView.bounds.size.width, _drawView.bounds.size.height,
8, 4* _drawView.bounds.size.width,
colourSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colourSpace);
NSLog(@"_drawView.bounds.size.width: %f", _drawView.bounds.size.width);
NSLog(@"_drawView.bounds.size.height: %f", _drawView.bounds.size.height);
[_drawView.layer renderInContext:context];
glGenBuffers(1, &_maskTexture);
glBindTexture(GL_TEXTURE_2D, _maskTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0,
GL_RGBA,
_drawView.bounds.size.width, _drawView.bounds.size.height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer);
CGContextRelease(context);
free(pixelBuffer);
_drawView.hidden = YES;
然后,_maskTexture的大小与输入图像不同。但是我需要保存在_maskTexture中的数据,以便在着色器函数中使用输入图像的纹理进行一些计算。但是,它们的大小不一样。如何解决这个问题?代码中的一个问题是调用glGenBuffers,它为缓冲区生成一个对象名。然后将此对象名称用于glBindTexture调用,该调用需要纹理的名称。您需要改为使用以获取纹理的有效对象名称