Jump to content
  • Advertisement
Sign in to follow this  
mishal153

stuck with my first shader

This topic is 4752 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 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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites

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 ");
}

Share this post


Link to post
Share on other sites
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])

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!