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

…衆ロ難τιáo~ 提交于 2019-12-11 08:16:28

问题


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 coordinates, and if so, how?


回答1:


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.



来源:https://stackoverflow.com/questions/4180401/how-to-specify-point-sprite-texture-coordinates-in-opengl-es-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!