• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Shawn619

GLSL - "cannot find void main()"

10 posts in this topic

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.

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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
2

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

0

Share this post


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

Share this post


Link to post
Share on other sites

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).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0