Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: what values to use to compile shaders?

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69

    what values to use to compile shaders?

    hi all. im having trouble compiling my shaders. here is what i believe to be the relevant code.

    Code :
    static const char *vshader =
    	    		"#version 430 core"
    	    		"layout (location = 0) in vec4 vPosition;"
    	    		"void main()"
    	    		"{"
    	    		"	gl_Position = vPosition;"
    	    		"}";
     
    	    static const char *fshader =
    	    		"#version 430 core"
    	    		"out vec4 fcolor;"
    	    		"void main()"
    	    		"{"
    	    		"	fColor = vec4 (0.0, 0.0, 1.0, 1.0);"
    	    		"}";
     
    		GLuint prog = glCreateProgram();
    	    GLuint vert = glCreateShader(GL_VERTEX_SHADER);
    	    GLuint frag = glCreateShader(GL_FRAGMENT_SHADER);
    	    glShaderSource(vert, 1, &vshader, 0);
    	    glShaderSource(frag, 1, &fshader, 0);
    	    glCompileShader(vert);
    	    glCompileShader(frag);
    	    glAttachShader(prog, vert);
    	    glAttachShader(prog, frag);
    	    glLinkProgram(prog);
    	    glUseProgram(prog);

    i believe the problem is with glShaderSource(). i dont know what values to use.
    thanks for the help.

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    315
    You should check if the shader compiled with glGetShader(shader_id, GL_COMPILE_STATUS, &status), and the errors/warnings of the compiles with glGetShaderInfoLog(). You can check the link status with glGetProgram(program_id, GL_LINK_STATUS, &status), and the link errors/warnings with glGetProgramInfoLog().

    The reason it's not working is that you've spelled fcolor two different ways in the fragment shader.

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    More significantly, you need some newline characters. When C concatenates adjacent string literals, it doesn't insert newlines (or any other whitespace).

    At a minimum, the #version directive needs to be terminated with a newline. At the moment, the "core" at the end of the first line and the "layout" at the beginning of the second line will be combined into a single "corelayout" token.

    I don't think that you need any other newlines in this particular case, but more complex shaders will have problems (e.g. a "//" comment will extend to the end of the shader, not the end of a single string literal).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •