X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=util.cpp;h=9b018825d333e269e3e0007b0300165af563b28f;hp=401664424fe2149cb97c4f9718d341f1f8dfa812;hb=81f33379cabb7cf8b47f2d2bd3892f853afc89ab;hpb=919101c59390dbbe380af7cc77102819e515a632 diff --git a/util.cpp b/util.cpp index 4016644..9b01882 100644 --- a/util.cpp +++ b/util.cpp @@ -89,7 +89,7 @@ string read_file(const string &filename) const string full_pathname = *movit_data_directory + "/" + filename; FILE *fp = fopen(full_pathname.c_str(), "r"); - if (fp == NULL) { + if (fp == nullptr) { perror(full_pathname.c_str()); exit(1); } @@ -157,7 +157,19 @@ GLuint compile_shader(const string &shader_src, GLenum type) GLint status; glGetShaderiv(obj, GL_COMPILE_STATUS, &status); if (status == GL_FALSE) { - fprintf(stderr, "Failed to compile shader: %s\n", shader_src.c_str()); + // Add some line numbers to easier identify compile errors. + string src_with_lines = "/* 1 */ "; + size_t lineno = 1; + for (char ch : shader_src) { + src_with_lines.push_back(ch); + if (ch == '\n') { + char buf[32]; + snprintf(buf, sizeof(buf), "/* %3zu */ ", ++lineno); + src_with_lines += buf; + } + } + + fprintf(stderr, "Failed to compile shader:\n%s\n", src_with_lines.c_str()); exit(1); } @@ -294,7 +306,7 @@ void *get_gl_context_identifier() return (void *)wglGetCurrentContext(); #else void *ret = (void *)eglGetCurrentContext(); - if (ret != NULL) { + if (ret != nullptr) { return ret; } return (void *)glXGetCurrentContext();