开发者

how to specify point sprite texture coordinates in OpenGL ES 1.1?

I'm writing a particle system that uses point sprites in OpenGL ES 1.1 on iOS. Everything works great until I try to texture the point sprites... when I render, each sprite is colored by the top left pixel of the texture I'm loading (rather than displaying the image). I've tried different images and different sizes and always get the same result.

setup code (taken from GLPaint example):

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);
}

and the render code:

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);

when texturing point sprites, do you have to specify texture coor开发者_如何学Cdinates, and if so, how?


no coordinates need to be specified, but you have to make the correct calls to enable point sprites:

glEnable(GL_POINT_SPRITE_OES) instead of glEnableClientState(GL_POINT_SPRITE_OES) did the trick.

going to go bone up on the difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜