how to reload the glsl shader?

Started by
5 comments, last by iishan 15 years, 9 months ago
i want to change my fragment shader, for example: first i write gl_FragData[0] = vec4(1.0, 0.0, 0.0, 1.0); when the shader is running, i want to change to gl_FragData[0] = vec4(1.0, 1.0, 1.0, 1.0), how can i do that? i try to reload the shader, rebind, recompile, but there is no change on my rendering result. could you give me some advice? thanks a lot!
Advertisement
Recompiling the shader isn't enough I guess, you'd have to also relink the program.

Using a uniform variable would be the better way to do this however. ;)
blah :)
sorry, i want to debug the shader throughing save the output to image by binding a fbo, so i will set gl_FragData[1] to any variable in the shader. Using a uniform variable would not resolve my problem.

i also relink the program as follows:

glShaderSource(m_hGLSLVertexShader, 1, &szVShader, NULL);
glShaderSource(m_hGLSLFragmentShader, 1, &szFShader, NULL);

// Now we actually compile the shader's code
glCompileShader(m_hGLSLVertexShader);
glCompileShader(m_hGLSLFragmentShader);

// We attach each shader we just loaded to our program object
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLVertexShader);
glAttachObjectARB(m_hGLSLProgramObject, m_hGLSLFragmentShader);

// Our last init function is to link our program object with OpenGL
glLinkProgramARB(m_hGLSLProgramObject);

but it does not work.
Quote:Original post by kolrabi
Recompiling the shader isn't enough I guess, you'd have to also relink the program.

Using a uniform variable would be the better way to do this however. ;)


No what he is saying is take a vec4 aka float temp[4]; upload that to GLSL with a uniform variable. And call the update each frame so you can update it. glUniform() and glGetUniformLocation()
but, i want output some interim result to debug, not the varialbe from cpu throuth a unifrom variable.

Quote:Original post by MARS_999
No what he is saying is take a vec4 aka float temp[4]; upload that to GLSL with a uniform variable. And call the update each frame so you can update it. glUniform() and glGetUniformLocation()


Quote:but it does not work.


Are you checking for errors? Post a small project so that people can test.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
yeah, i have resolved it.
when i do the shader recompile, relink operation, it will return an error as "invalidation operation", because of i did not bind an opengl context. I used mfc frame, so, i should do as follows:

wglMakeCurrent(m_pDC->GetSafeHdc(),m_hRC)//m_pDC and m_hRC is my custom variable

call opengl function(reload the shader, assign, compile, attach and link)

wglMakeCurrent(NULL,NULL);

thanks for every warmhearted people

This topic is closed to new replies.

Advertisement