小编kal*_*l21的帖子

在OpenGL ES 2.0中,如何从采样器读取相邻的纹素?

我在GLSL片段着色器(OpenGL ES 2.0)中传递具有NxM大小的纹理作为采样器.从相邻纹理元素读取纹素数据的正确方法是什么?我在片段着色器中没有"变化的"纹理坐标.我只能使用片段坐标来读取纹理信息.

以下是我的着色器,我不确定它是否实际读取数据:

precision mediump float;

uniform sampler2D Sampler;

#define OFFSET 1.0

void main()
{

    vec2 T = gl_FragCoord.xy;

    //Find neighboring velocities:
    vec2 N = texture2D(Sampler,vec2(T.x,T.y+OFFSET)).xy;
    vec2 S = texture2D(Sampler,vec2(T.x,T.y-OFFSET)).xy;
    vec2 E = texture2D(Sampler,vec2(T.x+OFFSET,T.y)).xy; 
    vec2 W = texture2D(Sampler,vec2(T.x-OFFSET,T.y)).xy; 
}
Run Code Online (Sandbox Code Playgroud)

对于NxM尺寸纹理,OFFSET值应该是1.0还是其他值?

opengl-es glsl opengl-es-2.0

11
推荐指数
1
解决办法
6824
查看次数

在UIImage到纹理转换中,纹理垂直翻转

我试图在iOS平台上将UIImage读入纹理.我发现StackOverflow上的代码片段可以解决这个问题,但问题是当我显示纹理时它显示为镜像倒置.

int numComponents = 4;

UIImage* image = [UIImage imageNamed:@"Test.png"];
CGImageRef imageRef = [image CGImage];
int width = CGImageGetWidth(imageRef);
int height = CGImageGetHeight(imageRef);

//Allocate texture data
GLubyte* textureData = (GLubyte *)malloc(width * height * numComponents);    

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(textureData, width, height,
                                             bitsPerComponent, bytesPerRow, colorSpace,
                                             kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);

//texture setup
GLuint textureID;    
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, …
Run Code Online (Sandbox Code Playgroud)

ios4 ios opengl-es-2.0

1
推荐指数
1
解决办法
3996
查看次数

glReadPixels在设备上返回iOS6的空缓冲区

可能重复:
为什么glReadPixels()在iOS 6.0中的此代码中失败?

以下行在iOS 6模拟器上运行良好,但在iOS 6设备上不起作用.可能有什么不对?如何解决这个问题?非常感谢.

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
Run Code Online (Sandbox Code Playgroud)

opengl-es ios ios6

1
推荐指数
1
解决办法
1487
查看次数

标签 统计

ios ×2

opengl-es ×2

opengl-es-2.0 ×2

glsl ×1

ios4 ×1

ios6 ×1