Hello,
I’m trying to display sprite for a particle application. I’m using shader but they don’t work.
This is the piece of code that I use in order to initiate the renderer :
if(LoadTGA(&treeTexture,p_variable->m_SPRITE )){
glEnable(GL_TEXTURE_2D);
glEnable(GL_POINT_SPRITE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
setVertexShader("../../../data/particule_shader.vert");
setFragmentShader("../../../data/particule_shader.frag");
setTransformUniform(p_variable->m_VERTEX_SIZE,"pointSize");
setTransformUniform(m_windowSetup->m_width,"viewPortWidth");
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &treeTexture.texID);
glBindTexture(GL_TEXTURE_2D, treeTexture.texID);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
}
here is my function which loads and launchs shaders :
void Renderer::setFragmentShader(char* frag) {
char *fs = NULL;
int success;
f = glCreateShader(GL_FRAGMENT_SHADER);
fs = textFileRead(frag);
const char * ff = fs;
glShaderSource(f, 1, &ff,NULL);
free(fs);
glCompileShader(f);
glAttachShader(p,f);
glLinkProgram(p);
glUseProgram(p);
glGetShaderiv(f, GL_COMPILE_STATUS, &success);
if (!success)
{
GLchar infoLog[GL_INFO_LOG_LENGTH];
glGetShaderInfoLog(f, GL_INFO_LOG_LENGTH, NULL, infoLog);
std::cout<<"Erreur dans la compilation du fragment shader `"<<frag<<"'"<<std::endl;
fprintf(stderr, "Info log: %s
", infoLog);
}else std::cout<<"Fragment shader `"<<frag<<"' OK!"<<std::endl;
}
Where f and p are GLuint, in the other hand setVertexShader use GLuint v and the same p
Here are my two shaders :
Vertex shader :
uniform float pointSize;
uniform float viewPortWidth;
void main()
{
vec4 camera_pos = gl_ModelViewMatrixInverse[3];
float dist = distance(gl_Position.xyz, camera_pos.xyz);
gl_PointSize=pointSize*viewPortWidth/dist;
gl_Position = ftransform();
gl_FrontColor=gl_Color;
}
Fragment shader :
void main()
{
gl_FragColor=gl_TexCoord[0];
}
My function which load thoses shaders alert me if there is an error during the compilation. Finally they compile fine at execution, the problem is that vertices dont change size when they are displayed (even if I put gl_PointSize=20.0 in the shader) and sprite texture is not displayed.
Ask me if you want other specific piece of code and thanks in advance for your help.