Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am starting my first project in OpenGL/GLSL and I was wondering, how do you work with code of shaders?

Because it needs to be const char and syntax higlighting shows everything in the same color (as string) and so its difficult to navigate in code.

const char *shader = ..."void main()\n"...;

Do you edit the code and then add quotation marks or do you just write it with quotation marks from the start? Thanks

edit: using VS2012

share|improve this question

2 Answers 2

up vote 2 down vote accepted

One thing you can do to make including shader code in C(++) source files more convenient is defining a macro like this:

#define GLSL(x) "#version #150\n" #x

Example:

const char* shader = GLSL(
    out vec4 outColor;
    void main() {
        outColor = vec4(1.0, 0.0, 0.0, 1.0);
    }
);

This will give you better formatting and basic C-style syntax highlighting:

Note that new lines will be ignored, so any preprocessor statements must be explicit.

share|improve this answer

some use separate files and include them as resources, some use macros, some use external files and read them in at runtime.

both of the external file options will allow syntax highlighting

and technically you don't need const char*, just a char* will do (it is implicitly convertible)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.