Results 1 to 4 of 4

Thread: Loading and Using Fragment Shader

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Location
    Poole, Dorset, England
    Posts
    6

    Loading and Using Fragment Shader

    Hello, hope this is the place for the question.

    Basically im trying to load a fragment shader into openGL and apply it to a mesh...


    Shader Code:
    Code :
    void main()
    	{
    	gl_FragColor = vec4(0.4,0.4,0.8,1.0);
    	}


    Loading Shader: (I've put a `cout<<glGetError<<endl;` after each line and they all seem to succeed)
    Code :
    const char *shaderArray = &amp;file_string;
    shader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource( shader, 1, &amp;shaderArray, NULL );
    glCompileShader( shader );
    program = glCreateProgram();
    glAttachShader( program, shader );
    glLinkProgram( program );

    Then after the glUseProgram a GL_INVALID_OPERATION is generated...
    Code :
    if( glIsProgram( program ) )
    {
    glUseProgram( program );
    cout<<"Error Code: "<<glGetError()<<endl;
    }

    I'm assuming its due to:
    "GL_INVALID_OPERATION is generated if program could not be made part of current state."
    OpenGL Reference Manual

    But I can't see why this is - the use Program is called once GL is initiated and everything...

    I'm sure its some silly mistake, but any help would be greatly appreciated.

    Thanks in Advance
    - Jorj

  2. #2
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Loading and Using Fragment Shader

    you should check if shader got compiled and linked correct. the first for sure. query the compile and link strings for errors or warning. i forgot the exact code though. google.

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Loading and Using Fragment Shader

    If you do not know this tutorial already, I suggest you to check out the Lighthouse3D GLSL tutorial. It is a good tutorial to start with glsl and you will find how to handle errors.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2008
    Location
    Poole, Dorset, England
    Posts
    6

    Re: Loading and Using Fragment Shader

    Awesome, there was an error, it was in loading the string into openGL, and converting char array to "const char **"'s...

    Thanks for your help
    - Jorj

Similar Threads

  1. Replies: 7
    Last Post: 06-06-2018, 06:35 AM
  2. Replies: 4
    Last Post: 08-03-2017, 01:01 PM
  3. Replies: 7
    Last Post: 09-15-2015, 04:00 AM
  4. Replies: 1
    Last Post: 08-02-2015, 07:45 PM
  5. Vertex and fragment shader loading
    By in forum OpenGL: Linux
    Replies: 1
    Last Post: 07-17-2002, 02:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean