Results 1 to 3 of 3
  1.    #1  
    I've been working on improving my app by re-writing it in C++ using OpenGL. I was able to achieve most everything, but I decided that drawing circles for each star was making it too slow. After some searching, I decided that the best way to improve the speed would be to use PointSprites rather than normal geometry. This would mean I would have to draw less vertex, speeding up the whole process. So I got it to draw points rather than a circle made of triangles.

    The problem is with the texturing. I got each sprite to be textured, using a PNG loaded via SDL with an alpha channel, but now it won't draw the background correctly. I figure my blending function is wrong, but I have tried many different combinations with varying degrees of success. Most combinations result in just the stars being drawn (which looks pretty good, the textures working well), while others result in nothing being drawn. One combination has everything visible, but the background is slightly faded, and the sprites are drawn over things that should be in front (and behind).

    I've been hitting my head on this for several says with no success. If anyone who knows OpenGL could chime in and tell me what I'm doing wrong, that would be wonderful.

    Thank you

    OpenGL Init:
    Code:
    //SDL and view setup
    ...
    //OpenGL options setup
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POINT_SPRITE_OES);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_COLOR, GL_ONE);
    glEnable(GL_ALPHA_TEST);
    glPointParameterf(GL_POINT_SIZE_MAX, 10.0f);
    glDepthFunc(GL_LESS);
    glShadeModel(GL_SMOOTH);
    Point Draw:
    Code:
    glPushMatrix();
    glDisable(GL_DEPTH_TEST); //doesn't seem to effect this
    glDepthMask(false); //also doesn't seem to change anything
    GLfloat point[3];
    point[0]=v.x;
    point[1]=v.y;
    point[2]=v.z;
    //Setup the texture for the point sprite
    glBindTexture(GL_TEXTURE_2D, textureid);
    glEnableClientState(GL_VERTEX_ARRAY);
    //Set the size of the sprite
    glPointSize(size);
    //Resize the texture
    glTexEnvf(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE);
    //Color probably has no effect with the texture, but left here anyway
    glColor4f(color.red, color.green, color.blue, color.alpha);
    glVertexPointer(3, GL_FLOAT, 0, point);
    glDrawArrays(GL_POINTS, 0, 1);
    glDisableClientState(GL_VERTEX_ARRAY);
    glPopMatrix();
  2. philbw's Avatar
    Posts
    310 Posts
    Global Posts
    352 Global Posts
    #2  
    I'm on my Pre so I couldn't really look at your code too well. I experimented with a number of formats and ways of loading them with varying amounts of luck. I finally settled on good ol' TGA. It's not compressed like PNG but I can load the files without having to use an SDL so that also helps with cross platform development. If you want to play with my TGA loader and see how it works for you just drop me an email at phil at boraware.com.

    - Phil -
  3.    #3  
    Thanks for the reply Phil, I'll probably drop you a line. I used PNG because I could figure out how to make them and use them without much difficulty. Not needing SDL would have some advantages, as you said, with cross platform development, which is in the road map (somewhere on the other side of the map, though).

    But I did have success loading the texture, I just think that my blending is wrong. I tried GL_SRC_COLOR/GL_ONE_MINUS_SRC_COLOR, as I saw in many examples, along with variations on SRC vs DST and COLOR vs ALPHA, and swapping the order of them. The best result so fare has been with GL_ONE and GL_ONE, but that fades out the background.

    I must be missing something. Can I not mix point sprites with untextured geometry?

    Also, of interest, in several blending combinations, I would only see the sprites, unless I go back into a card view, where the background re-appears. Going back into the app makes the background disappear again, so I wonder if the Pre disables some kind of texturing when in card view.

    Thanks

    jdiwnab

Posting Permissions