stuck with my first shader
hi. i have written a vertex and a fragment shader. I created the shader objects , passed the code, and linked them 2 a program object also. I checked at all points and the steps were successful. Now in my vertex shader my code is just the standard
void main(void)
{
gl_Position = ftransform();
}
and fragment shader is
void main(void)
{
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
}
I have written a program 2 rotate a square. I expected the color 2 b red, but it is white?
any idea?
I suspect that your shaders are not active at the drawing time, could you please post some code snippets on:
1-How you generate your shaders.
2-How you bind and unbind your shaders
Thanks
1-How you generate your shaders.
2-How you bind and unbind your shaders
Thanks
Tao.OpenGl.GlExtensionLoader.LoadAllExtensions(); string FileContents_1 = ReadFile( "vertex.glsl" ); string FileContents_2 = ReadFile( "fragment.glsl" ); int str_length_1 = FileContents_1.Length; int str_length_2 = FileContents_2.Length; int H_Vertexshader = Gl.glCreateShaderObjectARB( Gl.GL_VERTEX_SHADER_ARB ); int H_Fragmentshader = Gl.glCreateShaderObjectARB( Gl.GL_FRAGMENT_SHADER_ARB ); Gl.glShaderSourceARB( H_Vertexshader , 1 , ref FileContents_1 , ref str_length_1 ); Gl.glCompileShaderARB( H_Vertexshader ); int Compile_Result; Gl.glGetObjectParameterivARB( H_Vertexshader , Gl.GL_OBJECT_COMPILE_STATUS_ARB , out Compile_Result ); if( Compile_Result == 0) { MessageBox.Show(" Failed Vertex shader Compilatiion "); } Gl.glShaderSourceARB( H_Fragmentshader , 1 , ref FileContents_2 , ref str_length_2 ); Gl.glCompileShaderARB( H_Fragmentshader ); Gl.glGetObjectParameterivARB( H_Fragmentshader , Gl.GL_OBJECT_COMPILE_STATUS_ARB , out Compile_Result ); if( Compile_Result == 0) { MessageBox.Show(" Failed Fragment shader Compilatiion "); } int H_Program = Gl.glCreateProgramObjectARB(); Gl.glAttachObjectARB( H_Program , H_Vertexshader ); Gl.glAttachObjectARB( H_Program , H_Fragmentshader ); Gl.glLinkProgramARB ( H_Program ); int Link_Result; Gl.glGetObjectParameterivARB( H_Program , Gl.GL_OBJECT_LINK_STATUS_ARB , out Link_Result ); if( Link_Result == 0 ) { MessageBox.Show(" Failed Shader Program Linking "); }
You know what that looks fine to me, how about a little more info on how you bind your shaders?
(Ok I have to admit that I have few doubts about how the shaders strings are being passed to OpenGL since in C++ the glShaderSourceARB function takes a pointer to a pointer, but then again I haven't done any coding in C# [pig])
(Ok I have to admit that I have few doubts about how the shaders strings are being passed to OpenGL since in C++ the glShaderSourceARB function takes a pointer to a pointer, but then again I haven't done any coding in C# [pig])
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement