Jump to content

  • Log In with Google      Sign In   
  • Create Account

GLSL - "cannot find void main()"


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 01:39 PM

Following the shader program setup tutorial at http://www.arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html

 

I received the following error in my console window:

20qi7ms.jpg

 

By this error, I assume that the program locates and reads the .vs and .fs files from the appropriate directory, so that can't be the problem.

 

My calls that creates each shader are as follows:

void InitializeProgram()
{
    std::vector<GLuint> shaderList;
 
    shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "shader"));
    shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, "shader"));
 
    shaderOne = CreateProgram(shaderList);
    std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}

 

shader.vs

void main()

{

    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

}

 

shader.fs

void main()

{ 

    gl_FragColor = vec4(1.0,0.0,0.0,0.0);

}

 

Also, I thought there might be a problem with having the file extension .vs instead of .vert, but neither work.



Sponsor:

#2 TheChubu   Crossbones+   -  Reputation: 4839

Like
0Likes
Like

Posted 20 April 2013 - 01:46 PM

Shouldn't you call CreateShader with the full name? (ie, "shader.vs" and "shader.fs" )


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#3 Cornstalks   Crossbones+   -  Reputation: 6991

Like
2Likes
Like

Posted 20 April 2013 - 01:54 PM

Assuming you're using the code from that website, you need to pass the contents of the file to CreateShader, not the file name (with or without extension).

 

Funny enough, someone else was following the exact same tutorial and made the exact same error (I suggest you read this thread and my answer).


Edited by Cornstalks, 20 April 2013 - 01:57 PM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#4 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 02:14 PM

Oh, I'm pretty sure I know exactly what you mean. I think google let me down by not leading me to that thread with my same error. Is there a function that will parse my .txt shader files and put them in a std::string?



#5 Cornstalks   Crossbones+   -  Reputation: 6991

Like
2Likes
Like

Posted 20 April 2013 - 02:30 PM

Oh, I'm pretty sure I know exactly what you mean. I think google let me down by not leading me to that thread with my same error. Is there a function that will parse my .txt shader files and put them in a std::string?

No, but it's pretty easy to do yourself. There are many solutions, and which you choose probably doesn't matter in your situation (you don't need reading shader files to be blazing fast, as it's a one time thing and they're usually not massive files). I'd probably wrap it up in a function.

 

Also, just to nitpick a technicality, you don't need to parse your shader files (parsing has to do with syntactic analysis). You just need to read the source into memory so you can pass it on to OpenGL to compile the shader source.


Edited by Cornstalks, 20 April 2013 - 02:32 PM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 02:42 PM

Sorry, my concept of the word "parsing" was wrong, and i'll know not to use it, again. Thanks smile.png

 

Yeah, I'll write a basic function to extract the contents on my own. I'm sure it will look a lot nicer than explicitly writing it as an argument:

 

shaderList.push_back(CreateShader(GL_VERTEX_SHADER, "varying vec4 v; void main() { v = gl_Color; gl_Position = gl_ModelViewProjectionMatrix *gl_Vertex; }"));

 

Haha, thanks again!


Edited by Shawn619, 20 April 2013 - 02:42 PM.


#7 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 04:36 PM

One last question,

 

The function I wrote for reading .txt contents into a string is not working properly:

 

std::string readFiletoString(string fileName){
 
    std:string str;
    ifstream infile;
    infile.open(fileName);
 
 
    while(!infile.eof()) // To get you all the lines.
    {
        getline(infile,str); 
 
        // Saves the line in STRING.
        cout<<str; 
 
        // Prints our STRING.
    }
    infile.close();
    cout << str << endl;
    cout << "void main(){ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;}" << endl;
 
 
    if (str=="void main(){ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;}"){
        cout << "true" << endl;
    }else{
        cout << "false" << endl;
    }
 
 
    return str;
}

 

Somehow my function to read the same contents as opposed to manually writing it out is different, and gives me a shader error as a result:

 

15cddm9.jpg



#8 Cornstalks   Crossbones+   -  Reputation: 6991

Like
1Likes
Like

Posted 20 April 2013 - 04:57 PM

First, I'd suggest making these changes to reading the file contents:
std::string readFiletoString(string fileName){
    std:string contents;
    std:string line;
    ifstream infile(fileName);
 
 
    while (getline(infile, line)) // This is better than checking for .eof() (as it also handles other I/O errors)
    {
        contents += line + "\n";
    }
    return contents;
}

As for why your code is printing out false instead of true... I don't know, I'd have to use a debugger. Have you tried stepping through the code with your debugger? Also, how are you calling CreateShader() (are you sure you're giving it the shader source)?
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#9 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 05:12 PM

Your change works perfectly, thanks again!



#10 Cornstalks   Crossbones+   -  Reputation: 6991

Like
0Likes
Like

Posted 20 April 2013 - 05:18 PM

Your change works perfectly, thanks again!

Ah, I just read through your code again and I realize why it wasn't working. The first time your while loop runs, it reads the line and prints it out (note: str doesn't have a newline character on it (getline strips it off, which is why I added it back on in my code)). Great (except for the fact that it didn't save the string (note that getline doesn't accumulate lines into the string)). However, you haven't reached eof() yet (which is what you're while loop is checking for), so the loop runs again, and gets another line fromt he file (which is probably an empty line). Now str is empty (since getline read an empty line, and thus made str an empty string). Printing it out results in nothing being printed. Your if statement results in false because str is empty. Now you're returning an empty string, and your OpenGL code complains saying it can't find main (because it was given empty shader source).
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#11 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 20 April 2013 - 05:25 PM

Ah, I see. Thanks!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS