Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Can I draw PointSprites from a Texture Atlas

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    2

    Can I draw PointSprites from a Texture Atlas

    Hi,

    I am using PointSprites for Particle Systems. Now, I am trying to put the texture to be drawn in a TextureAtlas. (So far, each PointSprite consumes its own Texture)

    Here are my questions:
    1) Is storing point sprites in individual Textures suboptimal from a performance perspective, i.e. should I worry about it at all? I want to eliminate glBindTexture commands when switching to another particle system.

    2) I tried to set texture coordinates when having GL_POINT_SPRITE_OES activated. Below is the code I am using. The glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexC oordPointer... commands dont seem to have any effect. Is there a way to set the 2D texture coordinates (i.e. the origin in the texture atlas) for point sprites?

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture.name);

    glEnable(GL_POINT_SPRITE_OES);
    glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE );

    glBindBuffer(GL_ARRAY_BUFFER, verticesID);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2,GL_FLOAT,sizeof(vertices[0]),0);

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4, GL_FLOAT, sizeof(vertices[0]),(GLvoid*) offsetof(ccPointSprite_T2F, colors) );

    glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
    glPointSizePointerOES(GL_FLOAT,sizeof(vertices[0]),(GLvoid*) offsetof(ccPointSprite_T2F, size) );

    **glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    **glTexCoordPointer(2, GL_FLOAT, sizeof(vertices[0]),(GLvoid*) offsetof(ccPointSprite_T2F, texCoords) );

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glDrawArrays(GL_POINTS, 0, particleIdx);

    Basically it does not matter if I have the lines marked with (**) included or not.

    Does someone know more about drawing PointSprites from a TextureAtlas? Thanks!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: Can I draw PointSprites from a Texture Atlas

    well basically all point sprites use texture coordinates between 0 and 1, and that is unavoidable.
    However there are some ways around it, you could perhaps use a texture matrix to change the shape and displacement of it, i am not 100% sure how it works with pointsprites without using shaders but it might work, and definitely will if your using shaders(if you do it in the fragment shader).

    Another way when using shaders is to do those transformations by hand in the fragment shader

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    2

    Re: Can I draw PointSprites from a Texture Atlas

    Thanks. I ll explore this option.

    Does anybody has comments on the performance issue? I.e. is it worth it? Basically I want to avoid glBinTexture calls but I am not holding many textures in memory. Maybe 10. 2xTexture Atlas and the rest is individual Textures for PointSprites. These are very small, say 16 or 32 pixel..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •