Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0(3) : error C1013: function "main" is already defined at 0(4)

Tags:

opengl

glsl

I've google this a little bit and I can't figure out what is wrong. My shader:

#version 120

attribute vec2 coord2d;
void main(void) 
{
    gl_Position = vec4(coord2d, 0.0, 1.0);
}

This shader I know works, but when I try to link the program I get:

glLinkProgram:Vertex info
-----------
0(3) : error C1013: function "main" is already defined at 0(4)

I've checked to make sure that the viles are getting into memory properly and what not. they compile just fine. it is the linking step that something goes wrong. I'm clueless as to what and I've been hitting my head on this for quite some time. any tips?

Edit:

Here is the code i use to create the shader. it gets all the way to the conditional, it actually completes execution entirely, but the log prints out what you saw above.

GLuint updateProg()
{
    prog = glCreateProgram();
    if (vs == 0 || fs == 0) return 0;
    glAttachShader(prog, vs);
    glAttachShader(prog, fs);
    int link_ok;
    glLinkProgram(prog);
    glGetProgramiv(prog, GL_LINK_STATUS, &link_ok);
    if (!link_ok) 
    {
        fprintf(stderr, "glLinkProgram:");
        print_log(prog);
        return 0;
    }
    return prog;
}
like image 887
Narcolapser Avatar asked Jan 22 '12 06:01

Narcolapser


2 Answers

The error sounds like you might be trying to link two copies of the shader? Check the code for creating shader object(s), loading code into them, and linking them into the program object. That is, double-check all the calls to glCreateShader, glShaderSource, glCreateProgram, and glAttachShader to make sure they make sense.

edit

You've added the code that calls glCreateProgram above, but not the code that calls glCreateShader. Your error is consistent with accidentally (incorrectly) passing GL_VERTEX_SHADER to glCreateShader for the fragment shader.

like image 84
Chris Dodd Avatar answered Nov 06 '22 12:11

Chris Dodd


I had this error today. It happened because I copy/pasted too much code. I called glCreateShader(GL_VERTEX_SHADER); for both my vertex and fragment shader. They compiled just fine, but they wouldn't link, because they were both vertex shaders.

like image 42
Smackerlacker Avatar answered Nov 06 '22 12:11

Smackerlacker