PDA

View Full Version : point sprite texture coordinates in fragment shader?



thinks
01-06-2005, 02:19 PM
My problem probably has a simple solution to it so I will try and get straight to the point. I am using the point sprites extension for a particle system and so I am passing one vertex per particle to the vertex shader. If I have understood it correctly, during the rasterization step a lot of fragments are created from this single vertex (since GL_POINT_SPRITE_ARB is on), according to the current point size. My problem arrises when i try to implement my fragment program, and I have to assign values to all the fragments, based on a texture. I simply don't know where my texture coordinates are! Do I have to take care of sending them myself from my vertex program?

Here is some code, it is not much, and it doesn't work:

// Multiply texture value by current color
// testTexture is a uniform sampler2D
gl_FragColor = gl_Color*texture2D( testTexture, gl_TexCoord[0].st );
// This is basically what I want my fragment shader to do.Here how I handle texture's in my main app:

glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID); glfwLoadTexture2D("particle_w.tga",GLFW_BUILD_MIPMAPS_BIT);
glTexEnvi(GL_POINT_SPRITE_ARB,GL_COORD_REPLACE_ARB ,GL_TRUE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glEnable(GL_TEXTURE_2D); Does anything more have to be done?

Please let me know if anything is unclear and I will clarify... I know that the standard behaviour for the fragment shader manages the texturing just fine! I have seen it!

/ Tommy