Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please use appropriate C++11 functionality. #55

Closed
NicolBolas opened this issue Feb 9, 2017 · 0 comments
Closed

Please use appropriate C++11 functionality. #55

NicolBolas opened this issue Feb 9, 2017 · 0 comments
Assignees

Comments

@NicolBolas
Copy link

OpenGL tutorials have a peculiar place among programmers. Many neophyte programmers use them directly, often copying large parts into their projects and making only alterations that suit their needs.

As such, these tutorials are often where they get their first real exposure to the C++ language.

So I find myself dismayed when many newer OpenGL tutorials do things like this:

const GLchar* vertexSource =
    "#version 150 core\n"
    "in vec2 position;"
    "in vec3 color;"
    "out vec3 Color;"
    "void main()"
    "{"
    "    Color = color;"
    "    gl_Position = vec4(position, 0.0, 1.0);"
    "}";

C++11 added the raw string literal feature specifically for cases like this, where you're writing a literal that represents code that is in a different language.

New users need to be encouraged to use the language properly. OpenGL users ought to know that raw string literals exist in C++ and how to use them on shaders.

const GLchar* vertexSource =
R"glsl(#version 150 core
in vec2 position;
in vec3 color;
out vec3 Color;
void main()
{
    Color = color;
    gl_Position = vec4(position, 0.0, 1.0);
})glsl";

This is not a trivial matter of convenience; it affects how users debug their shaders. Your original version puts all of the shader code (save the #version declaration) on the same line. This means that, if the user makes a mistake, the error log will not help them, since it cannot point to the line where the error happened.

By contrast, the raw string literal version uses actual lines, which can in part help the user track down the specific problem.

I'm not asking that you litter your code with C++11-isms. I'm not saying that you should put auto and decltype and lambdas wherever you possibly can. But something like using raw string literals like this should be a no-brainer.

I can understand if you want to limit the compiler version to C++03 only.

@Overv Overv self-assigned this Feb 9, 2017
@Overv Overv closed this as completed in f3cbc90 Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants