[ACCEPTED]-Externally Define Preprocessor Macros in GLSL-glsl
Accepted answer
You don't really need to prepend it to the 4 code you loaded. That's why there are multiple 3 strings in the glShaderSourceARB API.
Something 2 like the following does what you are looking 1 for:
char *sources[2] = { "#define FOO\n", sourceFromFile };
glShaderSourceARB(shader, 2, sources, NULL);
Here is what I use to avoid #version
problems. It 2 is Java, and not optimized for perfo, but 1 it works perfectly:
// extract shader sourcecode from file
StringBuilder shaderSource = Tools.readTextRessource(shaderSrcFile.url);
// apply defined values
int versionIndex = shaderSource.indexOf("#version");
if(versionIndex == -1) err("missing #version xxx in shader "+shaderSrcFile.name());
int defineInsertPoint = shaderSource.indexOf("\n", versionIndex)+1;
for (int i = defined.size() - 1; i >= 0; --i)
shaderSource.insert(defineInsertPoint, "#define " + defined.get(i) + "\n");
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.