提示コードのSprite部のコード//===部内部のコードですが提示画像のようにsetBindAttribLocation() -1というエラーが返ってきます。最上部のコードで4個のシェーダーを作成していますがどれもエラーですなぜかshaderLight変数
の頂点情報を設定するコードだけエラー出ます。原因がわかりません。
参考サイト引用 glGetError()
-1 : 呼んだ関数の引数の値が無効な値もしくは範囲外の場合
参考サイト: https://qiita.com/_ydah/items/da56763e94ba58af3d91
Sprite
cpp
1 2// ##################################### コンストラクタ ##################################### 3FrameWork::D2::Sprite::Sprite() : Render() 4{ 5 shaderLight.Load("shader/Bloom.vert", "shader/LightBox.frag"); 6 shaderBloom.Load("shader/Bloom.vert", "shader/Bloom.frag"); 7 shaderBloomBlur.Load("shader/Bloom_Blur.vert", "shader/Bloom_Blur.frag"); 8 shaderBloomFinal.Load("shader/BloomFinal.vert", "shader/BloomFinal.frag"); 9 10 11 vertex = FrameWork::Camera::getVertexAttribute(); 12 13 setAttribute(); 14 setNormal(); 15 16 shaderBloom.setEnable(); 17 glBindVertexArray(vao); 18 glBindBuffer(GL_ARRAY_BUFFER, vbo); 19 20 //座標 21 GLint attrib = shaderBloom.getAttribLocation("vertexPosition"); 22 glEnableVertexAttribArray(attrib); 23 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 24 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)0); 25 shaderBloom.setBindAttribLocation("vertexPosition"); 26 27 28 //UV 29 attrib = shaderBloom.getAttribLocation("vertexUV"); 30 glEnableVertexAttribArray(attrib); 31 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 32 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 2)); 33 shaderBloom.setBindAttribLocation("vertexUV"); 34 35 36 //Normal 37 attrib = shaderBloom.getAttribLocation("vertexNormal"); 38 glEnableVertexAttribArray(attrib); 39 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 40 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 4)); 41 shaderBloom.setBindAttribLocation("vertexNormal"); 42 43 shaderBloom.setDisable(); 44 glBindVertexArray(0); 45 glBindBuffer(GL_ARRAY_BUFFER, 0); 46 47 48 49//============================================================================================================================== 50 shaderLight.setEnable(); 51 glBindVertexArray(vao); 52 glBindBuffer(GL_ARRAY_BUFFER, vbo); 53 54 //座標 55 attrib = shaderLight.getAttribLocation("vertexPosition"); 56 glEnableVertexAttribArray(attrib); 57 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 58 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)0); 59 shaderLight.setBindAttribLocation("vertexPosition"); 60 61 62 //UV 63 attrib = shaderLight.getAttribLocation("vertexUV"); 64 65 glEnableVertexAttribArray(attrib); 66 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 67 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 2)); 68 shaderLight.setBindAttribLocation("vertexUV"); 69 70 71 72 //Normal 73 attrib = shaderLight.getAttribLocation("vertexNormal"); 74 glEnableVertexAttribArray(attrib); 75 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 76 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 4)); 77 shaderLight.setBindAttribLocation("vertexNormal"); 78 79 80 81 shaderLight.setDisable(); 82 glBindVertexArray(0); 83 glBindBuffer(GL_ARRAY_BUFFER, 0); 84 85//============================================================================================================================== 86 87 88 89 shaderBloomBlur.setEnable(); 90 glBindVertexArray(vao); 91 glBindBuffer(GL_ARRAY_BUFFER, vbo); 92 93 //座標 94 attrib = shaderBloomBlur.getAttribLocation("vertexPosition"); 95 glEnableVertexAttribArray(attrib); 96 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 97 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)0); 98 shaderBloomBlur.setBindAttribLocation("vertexPosition"); 99 100 101 //UV 102 attrib = shaderBloomBlur.getAttribLocation("vertexUV"); 103 glEnableVertexAttribArray(attrib); 104 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 105 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 2)); 106 shaderBloomBlur.setBindAttribLocation("vertexUV"); 107 108 shaderBloomBlur.setDisable(); 109 glBindVertexArray(0); 110 glBindBuffer(GL_ARRAY_BUFFER, 0); 111 112 113 114 shaderBloomFinal.setEnable(); 115 glBindVertexArray(vao); 116 glBindBuffer(GL_ARRAY_BUFFER, vbo); 117 118 //座標 119 attrib = shaderBloomFinal.getAttribLocation("vertexPosition"); 120 glEnableVertexAttribArray(attrib); 121 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 122 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)0); 123 shaderBloomFinal.setBindAttribLocation("vertexPosition"); 124 125 126 //UV 127 attrib = shaderBloomFinal.getAttribLocation("vertexUV"); 128 glEnableVertexAttribArray(attrib); 129 glBufferData(GL_ARRAY_BUFFER, vertex->size() * sizeof(VertexAttribute), vertex->data(), GL_DYNAMIC_DRAW); 130 glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat) * 2)); 131 shaderBloomFinal.setBindAttribLocation("vertexUV"); 132 133 shaderBloomFinal.setDisable(); 134 glBindVertexArray(0); 135 glBindBuffer(GL_ARRAY_BUFFER, 0); 136 137} 138
Shader
// ##################################### 頂点シェーダーに属性変数を関連ずける ##################################### void FrameWork::Shader::setBindAttribLocation(const char* str) { GLint n = glGetAttribLocation(program, str); //エラー処理 if (n == -1) { std::cerr <<"setBindAttribVertex(): "<< n << std::endl; } else { glBindAttribLocation(program, n, str); } }
GLSL
vert
1#version 330 core 2 3 4layout(location = 0) in vec2 vertexPosition; 5layout(location = 1) in vec2 vertexUV; 6layout(location = 2) in vec3 vertexNormal; 7 8out VS_OUT { 9 vec3 FragPos; 10 vec3 Normal; 11 vec2 TexCoords; 12} vs_out; 13 14uniform mat4 uTranslate; 15uniform mat4 uRotate; 16uniform mat4 uScale; 17uniform mat4 uViewProjection; 18 19void main() 20{ 21 mat4 model = uTranslate * uRotate * uScale; 22 23 vs_out.FragPos = vec3(model * vec4(vertexPosition,-1.0, 1.0)); 24 vs_out.TexCoords = vertexUV; 25 26 mat3 normalMatrix = transpose(inverse(mat3(model))); 27 vs_out.Normal = normalize(normalMatrix * vertexNormal); 28 29 //gl_Position = projection * view * model * vec4(aPos, 1.0); 30 31 gl_Position = (uViewProjection * model) * vec4(vertexPosition,-1.0, 1.0); 32 33}
frag
1#version 330 core 2layout (location = 0) out vec4 FragColor; 3layout (location = 1) out vec4 BrightColor; 4 5in VS_OUT { 6 vec3 FragPos; 7 vec3 Normal; 8 vec2 TexCoords; 9} fs_in; 10 11uniform vec3 lightColor; 12 13void main() 14{ 15 FragColor = vec4(lightColor, 1.0); 16 float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722)); 17 if(brightness > 1.0) 18 BrightColor = vec4(FragColor.rgb, 1.0); 19 else 20 BrightColor = vec4(0.0, 0.0, 0.0, 1.0); 21} 22 23
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。