Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualOlof Hedman

Posted 11 October 2012 - 01:06 AM


A different way to do with with macro magic is something like:


Yep, that's pretty much what Olof Hedman and I were talking about, should work just fine.


Yep. I like my suggestion (and mhagain's) better though, that is to re-define the main function name.
That way you don't have to clutter your source file with #ifdefs, and the other main should be removed at link time.

#1Olof Hedman

Posted 11 October 2012 - 01:06 AM

A different way to do with with macro magic is something like:
Shader.glsl

#ifdef COMPILING_VERTEX_SHADER

// vertex shader
void main()
{}

#endif
#ifdef COMPILING_FRAGMENT_SHADER

// fragment shader
void main()
{}

#endif

Source File.cpp
std::string fileContents = fileToString("Shader.glsl"); // load it as a string
std::string compilingString = "#define COMPILNG_VERTEX_SHADER\n" + fileContents;
// load vertex shader...
compilingString = "#define COMPILING_FRAGMENT_SHADER\n" + fileContents;
// load fragment shader...


A different way to do with with macro magic is something like:


Yep, that's pretty much what Olof Hedman and I were talking about, should work just fine.


Yep. I like my suggestion (and mhagain's) better though, that is to re-define the main function name.
That way you don't have to clutter your source file with #ifdefs, and the other main should be removed at link time.

PARTNERS