Jump to content
  • Advertisement
Sign in to follow this  
metalcrusader

Problems with uniform variables in GLSL

This topic is 4652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I´m trying to use GLSL in my Apps so I´ve written a function which should loads, compile, link my shader ( two vertex and two fragment). The fragmentShader needs two uniform variables so the function has to deliver them. In each step i use the control function which comes with GLSL to verify if compiling, linkin etc was successfully done. My problem is, that the function which delivers the uniform-Values to me, says that both variables have the same value but they should have different ones. Here is the code:
int installShaders( GLcharARB *vertexS, GLcharARB *fragmentS)
	GLhandleARB handleVertex, handleFragment, handleProg; //handles to Objects
	GLint vertCompiled, fragCompiled, linked; //status values	
	// Create Shader-Objects:
	handleVertex = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB);	
	handleFragment = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB);	
	// Load the Sourcecode in the Shader:
	glShaderSourceARB( handleVertex, 1, &vertexS, NULL);	
	glShaderSourceARB( handleFragment, 1, &fragmentS, NULL);
	// Compile Shaders:	
	glCompileShaderARB( handleVertex);
	glCompileShaderARB( handleFragment);	
	if( !vertCompiled || !fragCompiled){ 	return 0;}
	// Create Programobject and attach shaders:
	handleProg = glCreateProgramObjectARB();
	glAttachObjectARB( handleProg,  handleVertex);	
	glAttachObjectARB( handleProg,  handleFragment);	
	// Linking the shader-program:
	glLinkProgramARB( handleProg);
	//verify the linking:	
 	GLint *para = NULL; 
	printf( "Link-Status: %i \n", glGetObjectParameterivARB( handleProg, GL_OBJECT_LINK_STATUS_ARB, ¶));	
	if ( !linked){ return 0;}		
	glUseProgramObjectARB( handleProg);
        GLint locP1 = glGetUniformLocationARB( handleProg, "P1");
	printf ("locP1: %i \n", locP1);
	glUniform1fARB( locP1, 0.8);	
	GLint locP2 = glGetUniformLocationARB( handleProg, "P2");	
	printf ("locP2: %i \n", locP2);
	glUniform1fARB( locP2, 0.7);
	// print the uniform-Values:
	GLfloat *unifo1 = NULL;	
	GLfloat *unifo2 = NULL;
	printf( "Uni1 :%f \n", glGetUniformfvARB( handleProg, locP1, &unifo1));
	printf( "Uni2 :%f \n", glGetUniformfvARB( handleProg, locP2, &unifo2));	
	
    return 1;
}

./main Link-Status: 1 locP1: 0 locP2: 1 Uni1 :0.700000 Uni2 :0.700000 Can anyone help me? Greetings, Bjoern [Edited by - phantom on September 22, 2005 12:34:50 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:

I´m trying to use GLSL in my Apps so I´ve written a function which should loads, compile, link my shader ( two vertex and two fragment).


I only see


handleVertex = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB);
handleFragment = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB);





Thats enough for 2 shaders, 1 vertex, 1 fragment. Where are the other 2 calls?

Also, could you post the relevant parts of the shader code?

Share this post


Link to post
Share on other sites
Sorry, my mistake. Because of Login-Problems at this Forum i posted my question two days after coding. In this example i used only 1 vertex and 1 fragment shader. The vertex is only "glPosition = ftransform" but in the fragment i tried out to set the rgb-values for gl_FragColor:
"uniform float P1;
uniform float P2;
void main(void)
{
gl_FragColor = vec4(P1, P2, 0.0, 1.0);
}
that´s all!
Any ideas?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!