如何在OpenGL ES 1.1中指定点精灵纹理坐标?

时间:2010-11-14 23:42:20

标签: ios opengl-es point-sprites

我正在编写一个在iOS上使用OpenGL ES 1.1中的点精灵的粒子系统。一切都很好,直到我尝试纹理点精灵...当我渲染时,每个精灵都被我正在加载的纹理的左上角像素着色(而不是显示图像)。我尝试过不同的图像和不同的尺寸,总能得到相同的结果。

设置代码(取自GLPaint示例):

CGImageRef      brushImage;
CGContextRef    brushContext;
size_t          width, height;
GLubyte         *brushData;
brushImage = [UIImage imageNamed:@"Particle.png"].CGImage;
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
if(brushImage) {
    brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
    brushContext = CGBitmapContextCreate(brushData, width, width, 8, width * 4, CGImageGetColorSpace(brushImage), kCGImageAlphaPremultipliedLast);
    CGContextDrawImage(brushContext, CGRectMake(0, 0.0, (CGFloat)width, (CGFloat)height), brushImage);
    CGContextRelease(brushContext);
    glGenTextures(1, &brushTexture);
    glBindTexture(GL_TEXTURE_2D, brushTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);
    free(brushData);
}

和渲染代码:

glLoadIdentity();
glEnable(GL_BLEND);

glTranslatef(0.0f,0.0f,0.0f);
glClearColor(0.0, 0.0, 0.0, 1.0f);

glClear(GL_COLOR_BUFFER_BIT );  
glEnableClientState(GL_POINT_SPRITE_OES);   
glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, brushTexture);

glTexEnvf(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);    
// took this out as incorrect call glEnableClientState(GL_POINT_SMOOTH);

glVertexPointer(2, GL_FLOAT, sizeof(ColoredVertexData2D), &vertexData[0].vertex);
glColorPointer(4, GL_FLOAT, sizeof(ColoredVertexData2D), &vertexData[0].color);
glPointSizePointerOES(GL_FLOAT,sizeof(ColoredVertexData2D),&vertexData[0].size) 

glDrawArrays(GL_POINTS, 0,1000);

当纹理点精灵时,你是否必须指定纹理坐标,如果是,如何指定?

1 个答案:

答案 0 :(得分:2)

不需要指定坐标,但是您必须进行正确的调用以启用点精灵:

glEnable(GL_POINT_SPRITE_OES)代替glEnableClientState(GL_POINT_SPRITE_OES)就可以了。

将会对差异产生影响。