提示コードですがMesh::Draw()
関数のshader.setUniformMatrix4fv("uTranslate",getMatTranslation());
関数で下記のエラーが出ます。これはなぜでしょうか?Mesh
クラスのコンストラクタでシェーダーをロードしてDraw()
関数で使っているのですが
なぜ-1のエラーが返ってくるのか原因がわりません。
確認したこと
その他の2Dで円や矩形などの描画はこのクラスで行えるのでshader
クラスは問題ないです。
Github: https://github.com/Shigurechan/GL
command
1$ ./GL 2this->vertex: 24 3this->index: 0 4this->texture: 0 5 6あああ 7GL: source/Shader.cpp:295: void FrameWork::Shader::setUniformMatrix4fv(const char*, glm::mat4): Assertion `0' failed. 8
Shader.cpp
1// ##################################### mat4 ##################################### 2void FrameWork::Shader::setUniformMatrix4fv(const char* name, const glm::mat4 m) 3{ 4 const GLuint object = glGetUniformLocation(program, name); 5 if (object == -1) { assert(0); } //エラー処理 6 glUniformMatrix4fv(object, 1, false, glm::value_ptr(m)); 7}
vert
1/*######################################################################### 2# 3###########################################################################*/ 4#version 420 5//#extension GL_ARB_explicit_uniform_location : require 6 7 8layout(location = 0) in vec3 vertexPosition; 9//layout(location = 1) in vec2 vertexUV; 10//layout(location = 2) in vec3 vertexNormal; 11 12 13//layout(location = 3) out vec2 vUV; 14layout(location = 1) out vec4 vFragment; 15//layout(location = 4) out vec3 vNormal; 16 17 18 19uniform mat4 uTranslate; 20uniform mat4 uRotate; 21uniform mat4 uScale; 22uniform mat4 uViewProjection; 23 24uniform vec4 uFragment; 25 26 27void main() 28{ 29 vec4 vertex = vec4(vertexPosition,1.0); 30 mat4 model = uTranslate * uRotate * uScale; 31 gl_Position = (uViewProjection * model) * vertex; 32 33 34 35// vUV = vertexUV; 36 vFragment = uFragment; 37// vNormal = vertexNormal; 38}
/*######################################################################### # ###########################################################################*/ #version 420 //#extension GL_ARB_explicit_uniform_location : require //layout(location = 3) in vec2 vUV; layout(location = 1) in vec4 vfragment; //layout(location = 4) in vec3 vNormal; //uniform sampler2D uImage; out vec4 fragment; void main() { fragment = vfragment; // fragment = texture(uImage,vUV); }
Mode.cpp
1#include "../header/Model.hpp" 2 3#include <iostream> 4#include <assert.h> 5#include <vector> 6#include <assimp/Importer.hpp> 7#include <assimp/scene.h> 8#include <assimp/postprocess.h> 9#include <glm/glm.hpp> 10#include <GL/glew.h> 11#include "../lib/stb/stb_image.h" 12 13#include "../header/Resource.hpp" 14#include "../header/Camera.hpp" 15 16 17FrameWork::D3::Mesh::Mesh(std::vector<VertexAttribute> ver, std::vector<unsigned int> idx, std::vector<Texture> tex) : Transform() 18{ 19 this->vertex = ver; //頂点 20 this->index = idx; //インデックス 21 this->texture = tex; //テクスチャ 22 23 printf("this->vertex: %d\n",this->vertex.size()); 24 printf("this->index: %d\n",this->index.size()); 25 printf("this->texture: %d\n\n",this->texture.size()); 26 27 if ( shader.Input(FrameWork::LoadShader("Shader/3D/BasicMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasicMono_3D.frag")->data()) == false) 28 { 29 printf("シェーダーロード失敗\n"); 30 } 31 32 33 34 glGenVertexArrays(1, &VAO); 35 glGenBuffers(1, &VBO); 36 37 glBindVertexArray(VAO); 38 glBindBuffer(GL_ARRAY_BUFFER, VBO); 39 40 //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); 41 42 //glBufferData(GL_ELEMENT_ARRAY_BUFFER, index.size() * sizeof(unsigned int),index.data(), GL_DYNAMIC_DRAW); 43 glBufferData(GL_ARRAY_BUFFER, vertex.size() * sizeof(VertexAttribute), vertex.data(), GL_DYNAMIC_DRAW); 44 45 GLint attrib = shader.getAttribLocation("vertexPosition"); 46 glEnableVertexAttribArray(attrib); 47 glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); 48 shader.setBindAttribLocation("vertexPosition"); 49 50 51 //printf("あああ\n"); 52 53 // vertex texture coords 54 //attrib = shader.getAttribLocation("vertexUV"); 55 //glEnableVertexAttribArray(attrib); 56 //glVertexAttribPointer(attrib, 2, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 3)); 57//printf("ららら\n"); 58 // vertex normals 59 //attrib = shader.getAttribLocation("vertexNormal"); 60 //glEnableVertexAttribArray(attrib); 61 //glVertexAttribPointer(attrib, 3, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 5)); 62 63 64 glBindVertexArray(0); 65 glBindBuffer(GL_ARRAY_BUFFER, 0); 66 67 68} 69 70 71 72void FrameWork::D3::Mesh::Draw() 73{ 74 shader.setEnable(); 75 76 glBindVertexArray(VAO); 77 glBindBuffer(GL_ARRAY_BUFFER, VBO); 78 79 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex.size(), vertex.data()); 80 81 //Transform 82 setPosition(glm::vec3(0,0,-20)); //座標 83 setScale(glm::vec3(10,10,10)); //スケール 84 setRotate(glm::vec3(0,0,0),0); //回転 85 86 //描画 87 shader.setUniformMatrix4fv("uTranslate",getMatTranslation()); 88 shader.setUniformMatrix4fv("uRotate", getMatRotate()); 89 shader.setUniformMatrix4fv("uScale", getMatScale()); 90 shader.setUniform4f("uFragment", FrameWork::GetGlColor(glm::vec4(0,0,255,255))); 91 shader.setUniformMatrix4fv("uViewProjection", FrameWork::Camera::getViewProjection()); 92 93 for(unsigned int i = 0; i < texture.size(); i++) 94 { 95 //glBindTexture(GL_TEXTURE_2D, texture[i].id); 96 //glActiveTexture(GL_TEXTURE0 + i); 97 } 98 99 //glDrawElements(GL_TRIANGLES, index.size(), GL_UNSIGNED_INT, 0); 100 glDrawArrays(GL_TRIANGLES,0,vertex.size()); 101 102 //バインド解除 103 glBindVertexArray(0); 104 glBindBuffer(GL_ARRAY_BUFFER, 0); 105 //glBindTexture(GL_TEXTURE_2D, 0); 106 107 shader.setDisable(); 108} 109 110void FrameWork::D3::Model::processNode(aiNode *node, const aiScene *scene) 111{ 112 113 for(unsigned int i = 0; i< node->mNumMeshes; i++) 114 { 115 //printf("push_back\n"); 116 117 aiMesh *m = scene->mMeshes[node->mMeshes[i]]; 118 mesh.push_back(processMesh(m,scene)); 119 } 120 121 for(unsigned int i = 0; i< node->mNumChildren; i++) 122 { 123 //printf("再帰的\n"); 124 processNode(node->mChildren[i],scene); 125 } 126} 127 128void FrameWork::D3::Model::loadModel(const char *path) 129{ 130 Assimp::Importer import; 131 //const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate); 132 const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs); 133 134 if(scene == NULL) 135 { 136 std::cerr<<"ERROR::ASIMP: " << import.GetErrorString() <<std::endl; 137 assert(0); 138 } 139 140 std::string str(path); 141 142 directory = str.substr(0,str.find_last_of('/')); 143 144 processNode(scene->mRootNode, scene); 145} 146 147 148 149FrameWork::D3::Mesh FrameWork::D3::Model::processMesh(aiMesh *m, const aiScene *scene) 150{ 151 // data to fill 152 std::vector<VertexAttribute> ver(0); 153 std::vector<unsigned int> idx(0); 154 std::vector<Texture> tex(0); 155 156 157 for(unsigned int i = 0; i < m->mNumVertices; i++) 158 { 159 VertexAttribute vert; 160 glm::vec3 vector; 161 vert.position[0] = m->mVertices[i].x; 162 vert.position[1] = m->mVertices[i].y; 163 vert.position[2] = m->mVertices[i].z; 164 165 // normals 166 if (m->HasNormals() == true) 167 { 168 //vert.normal[0] = m->mNormals[i].x; 169 //vert.normal[1] = m->mNormals[i].y; 170 //vert.normal[2] = m->mNormals[i].z; 171 172 } 173 174 // texture coordinates 175 if(m->mTextureCoords != NULL) 176 { 177 glm::vec2 vec; 178 //vert.uv[0] = m->mTextureCoords[0][i].x; 179 180 } 181 else 182 { 183 //vert.uv[0] = 0.0f; 184 //vert.uv[1] = 0.0f; 185 186 } 187 ver.push_back(vert); 188 } 189 190 191 return Mesh(ver, idx, tex); 192 193} 194
回答1件
あなたの回答
tips
プレビュー