digitalmars.D - Derelict-GL3 Error
- Kevin (8/8) Jan 09 2017 Using Archlinux, Derelict-gl3 1.0.18
- Mike Parker (28/36) Jan 09 2017 This has nothing to do with Derelict. It's an error in your use
Using Archlinux, Derelict-gl3 1.0.18 check format (GLuint, Glenum, Glint*) // this does not work glGetShaderiv(program, GL_LINK_STATUS, &success); writeln("GL_ERROR: ", glGetError()); Give me error 1282 // this one works fine. glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
Jan 09 2017
On Tuesday, 10 January 2017 at 01:43:50 UTC, Kevin wrote:Using Archlinux, Derelict-gl3 1.0.18 check format (GLuint, Glenum, Glint*) // this does not work glGetShaderiv(program, GL_LINK_STATUS, &success); writeln("GL_ERROR: ", glGetError()); Give me error 1282 // this one works fine. glGetShaderiv(shader, GL_COMPILE_STATUS, &success);This has nothing to do with Derelict. It's an error in your use of OpenGL, so you need to look up the OpenGL error code 1282 and figure out what it means. Since I'm here, I'll save you some time. 1282 is GL_INVALID_OPERATION. However, just because you called it immediately after glGetShaderiv *does not mean* that function caused the error. The error code may have been set any time before that, by any of the functions you called. Then, when you call glGetError, the error code is reset to 0, so your next call to glGetError shows no error. Here's some psuedocode to illustrate: // OpenGL's internal error code errCode = 0; // In your code: glSomething(); // no error glSomethingElse(); // no error glAnotherThing(); // Oops! An error - errCode now is set to 1282 glThisThing(); // No error, but the state is now messed up glThatThing(); // No error err = glGetError(); // This returns 1282, as set by glAnotherThing above What you need to do is debug your OpenGL code. The simplest way to do that is to insert glGetError at different points, recompile, and run it again. This will help you narrow things down to the function that actually caused the error. And for future reference, please go to opengl.org or the OpenGL forums at gamedev.net for help with OpenGL.
Jan 09 2017
On Tuesday, 10 January 2017 at 04:34:24 UTC, Mike Parker wrote:On Tuesday, 10 January 2017 at 01:43:50 UTC, Kevin wrote:Thanks for info. I already did glGetError() above and below. and it only from that code. At first I thought i put the wrong type. I set success to 1 and let code go through and shader work fine. The glGetShaderiv(program, GL_LINK_STATUS, &success) check does not work. If you still think it opengl problem I will take it there or maybe i made a simple mistake I can't see. full code import std.string : toStringz; import std.stdio; import std.file; import derelict.opengl3.gl; struct Shader { private GLuint program; disable this(this); ~this() { glDeleteProgram(program); } void use() { glUseProgram(program); } bool create(string vertexName, string fragmentName, string geometryName=null) { char[512] infoLog; program = 0; GLuint vertexShader = shaderFile(vertexName, GL_VERTEX_SHADER); GLuint fragmentShader = shaderFile(fragmentName, GL_FRAGMENT_SHADER); GLuint geometryShader = 0; GLint success = 1; if(geometryName !is null) geometryShader = shaderFile(geometryName, GL_GEOMETRY_SHADER); if(vertexShader == 0) { writeln("Vertex is null"); return false; } if(fragmentShader == 0) { writeln("Fragment is null"); glDeleteShader(vertexShader); return false; } if(geometryName !is null) { if(geometryShader == 0) { writeln("Geometry is null"); glDeleteShader(vertexShader); glDeleteShader(fragmentShader); return false; } } // create program program = glCreateProgram(); glAttachShader(program, vertexShader); glAttachShader(program, fragmentShader); if(geometryName !is null) glAttachShader(program, geometryShader); glLinkProgram(program); writeln("Before GL_ERROR: ", glGetError()); // this does not work glGetShaderiv(program, GL_LINK_STATUS, &success); writeln("After GL_ERROR: ", glGetError()); if(!success) { writeln("GL_ERROR: ", glGetError()); glGetShaderInfoLog(program, 512, null, infoLog.ptr); writeln("ERROR::Shader program linking failed"); writeln(infoLog); } glDeleteShader(vertexShader); glDeleteShader(fragmentShader); if(geometryName !is null) glDeleteShader(geometryShader); return cast(bool) success; } private GLuint shaderFile(string sourceName, GLenum flag) { string fileData; GLchar* source; GLint success; GLchar[512] infoLog; GLuint shader = 0; if(exists(sourceName) != 0) fileData = cast(string) read(sourceName); else { writeln("ERROR: File doesn't exist"); return 0; } source = cast(GLchar*) (toStringz(fileData)); shader = glCreateShader(flag); glShaderSource(shader, 1, &source, null); glCompileShader(shader); // this one work fine glGetShaderiv(shader, GL_COMPILE_STATUS, &success); writeln("sh .. GL_ERROR: ", glGetError()); if(!success) { glGetShaderInfoLog(shader, 512, null, infoLog.ptr); if(flag == GL_VERTEX_SHADER) writeln("ERROR::Shader vertex compiltion failed "); else if(flag == GL_FRAGMENT_SHADER) writeln("ERROR::Shader fragment compiltion failed"); else if(flag == GL_GEOMETRY_SHADER) writeln("ERROR::Shader geometry compiltion failed"); writeln(infoLog); } return shader; } }Using Archlinux, Derelict-gl3 1.0.18 check format (GLuint, Glenum, Glint*) // this does not work glGetShaderiv(program, GL_LINK_STATUS, &success); writeln("GL_ERROR: ", glGetError()); Give me error 1282 // this one works fine. glGetShaderiv(shader, GL_COMPILE_STATUS, &success);This has nothing to do with Derelict. It's an error in your use of OpenGL, so you need to look up the OpenGL error code 1282 and figure out what it means. Since I'm here, I'll save you some time. 1282 is GL_INVALID_OPERATION. However, just because you called it immediately after glGetShaderiv *does not mean* that function caused the error. The error code may have been set any time before that, by any of the functions you called. Then, when you call glGetError, the error code is reset to 0, so your next call to glGetError shows no error. Here's some psuedocode to illustrate: // OpenGL's internal error code errCode = 0; // In your code: glSomething(); // no error glSomethingElse(); // no error glAnotherThing(); // Oops! An error - errCode now is set to 1282 glThisThing(); // No error, but the state is now messed up glThatThing(); // No error err = glGetError(); // This returns 1282, as set by glAnotherThing above What you need to do is debug your OpenGL code. The simplest way to do that is to insert glGetError at different points, recompile, and run it again. This will help you narrow things down to the function that actually caused the error. And for future reference, please go to opengl.org or the OpenGL forums at gamedev.net for help with OpenGL.
Jan 10 2017
On Tuesday, 10 January 2017 at 14:32:29 UTC, Kevin wrote:On Tuesday, 10 January 2017 at 04:34:24 UTC, Mike Parker wrote:You are right. My simple mistake. i use glGetShaderiv when I should have us glGetProgramiv. Thanks for your help.[...]Thanks for info. I already did glGetError() above and below. and it only from that code. At first I thought i put the wrong type. I set success to 1 and let code go through and shader work fine. The glGetShaderiv(program, GL_LINK_STATUS, &success) check does not work. If you still think it opengl problem I will take it there or maybe i made a simple mistake I can't see. [...]
Jan 10 2017
Don't use glGetError() it was such a horrible design decision to use that for debugging. A better way to debug was introduced. https://www.khronos.org/opengl/wiki/Debug_Output
Jan 12 2017