提示コードですがActorクラスのサイズが変わっているためアクセスエラーが出る原因がわかりせん。これはなぜなのでしょうか?printfデバッグをした結果void RendererDepth()関数が原因なのでその定義をみましたが問題ありません。これは何が原因なのでしょうか?
GithubコードのCamera.chpp Renderer()関数部 Ground.cpp void RendererDepth()関数部です。
Github: https://github.com/Shigurechan/TopViewGame
端末
[shigurechan@localhost TopViewGame]$ ./program aaaああああ えええ terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 1) 中止 (コアダンプ) [shigurechan@localhost TopViewGame]$
#####Actor.hpp
#ifndef ___ACTOR_HPP___ #define ___ACTOR_HPP___ class Actor { public: Actor(); ~Actor(); //virtual void Update(); virtual void Update() = 0; virtual void Renderer(glm::mat4 view)const = 0; virtual void RendererDepth(GLuint depth,glm::mat4 view)const = 0; //virtual void Renderer(glm::mat4 view)const; std::shared_ptr<FrameWork::D3::Object> model; protected: FrameWork::ObjFile file; }; #endif
Ground.cpp
Ground::Ground() : Actor() { FrameWork::D3::LoadObj("Game/model/ground.obj",file); model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW); shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag"); shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag"); } void Ground::Renderer(glm::mat4 view)const { model->shader = shaderDepth; model->setBindBuffer(); model->shader.setEnable(); model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix); model->shader.setDisable(); model->setUnBindBuffer(); } void Ground::RendererDepth(GLuint depth,glm::mat4 view)const { model->shader = shader; model->setBindBuffer(); model->shader.setEnable(); /*文字数の関係で割愛*/ model->shader.setDisable(); model->setUnBindBuffer(); } Ground::~Ground() { } Ground::Ground() : Actor() { FrameWork::D3::LoadObj("Game/model/ground.obj",file); model = std::make_shared<FrameWork::D3::Object>(&file,GL_STATIC_DRAW); shader.Load("FrameWork/shader/3D//ShadowMap/ShadowMap.vert","FrameWork/shader/3D/ShadowMap/ShadowMap.frag"); shaderDepth.Load("FrameWork/shader/3D//ShadowMap/ShadowTexture.vert","FrameWork/shader/3D/ShadowMap/ShadowTexture.frag"); texture = FrameWork::LoadTexture("Game/Assets/debug.png"); model->setTexture(texture); model->setPosition(glm::vec3(0,0,-5)); model->setScale(glm::vec3(100,1,100)); model->setRotate(glm::vec3(1,0,0),0); } void Ground::setLightPosition(glm::vec3 pos) { model->shader.setEnable(); model->shader.setUniform4f("uFragment",FrameWork::GetGlColor(glm::vec4(200,255,255,255))); model->shader.setDisable(); } void Ground::Update() { model->shader.setEnable(); /* glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, depthMap); */ model->shader.setDisable(); } void Ground::Renderer(glm::mat4 view)const { model->shader = shaderDepth; model->setBindBuffer(); model->shader.setEnable(); glm::mat4 lightProjection, lightView; glm::mat4 lightSpaceMatrix; float near_plane = 1.0f, far_plane = 7.5f; //lightProjection = glm::perspective(glm::radians(45.0f), (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT, near_plane, far_plane); // note that if you use a perspective projection matrix you'll have to change the light position as the current light position isn't enough to reflect the whole scene lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0)); lightSpaceMatrix = lightProjection * lightView; // render scene from light's point of view model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix); model->shader.setDisable(); model->setUnBindBuffer(); } void Ground::RendererDepth(GLuint depth,glm::mat4 view)const { model->shader = shader; model->setBindBuffer(); model->shader.setEnable(); glm::mat4 lightProjection, lightView; glm::mat4 lightSpaceMatrix; float near_plane = 1.0f, far_plane = 7.5f; //lightProjection = glm::perspective(glm::radians(45.0f), (GLfloat)SHADOW_WIDTH / (GLfloat)SHADOW_HEIGHT, near_plane, far_plane); // note that if you use a perspective projection matrix you'll have to change the light position as the current light position isn't enough to reflect the whole scene lightProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); lightView = glm::lookAt(glm::vec3(0,0,-5), glm::vec3(0.0f), glm::vec3(0.0, 1.0, 0.0)); lightSpaceMatrix = lightProjection * lightView; // render scene from light's point of view model->shader.setUniformMatrix4fv("lightSpaceMatrix",lightSpaceMatrix); model->shader.setUniform3f("viewPos", glm::vec3(0,0,-5)); model->shader.setUniform3f("lightPos", glm::vec3(0,100,-5)); model->setEnableTexture(texture); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, depth); model->Renderer(view); model->shader.setDisable(); model->setUnBindBuffer(); } Ground::~Ground() { }
Camera.cpp
void FrameWork::Camera::Renderer() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); //ブレンド有効 glEnable(GL_TEXTURE_2D); //テクスチャを有効 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //ブレンドタイプ glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); //半透明 glEnable(GL_DEPTH_TEST); //深度バッファを有効 glDepthFunc(GL_LEQUAL); //深度バッファタイプ glEnable(GL_CULL_FACE); //カリングを有効 glCullFace(GL_BACK); //裏面を無効 //フレームバッファをバインド glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glClear(GL_DEPTH_BUFFER_BIT); printf("えええ\n"); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(std::vector<std::shared_ptr<Actor>>::iterator itr = actor.begin(); itr != actor.end(); itr++) { (*itr)->RendererDepth(depthMapFBO,getViewProjection()); } printf("ううう\n"); for(std::vector<std::shared_ptr<Actor>>::iterator itr = actor.begin(); itr != actor.end(); itr++) { (*itr)->Renderer(getViewProjection()); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y); glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, intermediateFBO); glBlitFramebuffer(0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, 0, 0, FrameWork::windowContext->getSize().x, FrameWork::windowContext->getSize().y, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); //////////////////////////////////////////////////////////////////////////////////////////////////// for(std::vector<std::shared_ptr<Actor>>::iterator itr = actor.begin(); itr != actor.end(); itr++) { (*itr)->RendererDepth(depthMapFBO,getViewProjection()); } /////////////////////////////////////////////////////////////////////////////////////////////////// //フレームバッファをレンダリング glDisable(GL_DEPTH_TEST); shaderFrameBuffer->setEnable(); glBindVertexArray(quadVAO); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, screenTexture); glDrawArrays(GL_TRIANGLES, 0, 6); shaderFrameBuffer->setDisable(); glBindVertexArray(0); glBindTexture(GL_TEXTURE_2D,0); glBindFramebuffer(GL_FRAMEBUFFER, 0); actor.resize(0); shadowActor.resize(0); }
回答1件
あなたの回答
tips
プレビュー