Okej, 그래서 나는 3 개의 (또는 2 개의 중요하지 않은) 객체가 있고 그 중 하나가 버퍼를 "애니메이션"으로 업데이트하는 정말 이상한 경우가 있습니다. 다른 말로하면, 한 물체는 움직이고 다른 물체는 여전히 서 있습니다. 움직이는 물체가 움직일 때 이상한 부분이 나타나지만 움직이는 물체를 렌더링 한 후에 렌더링되는 물체는 정확하게 움직입니다. 움직이는 물체는 움직이지만 움직이지는 않습니다. 그것이 의미가 있기를 바랍니다. 이제OpenGL - 버퍼가 다음 렌더링 객체를 업데이트합니다.
일부 코드와 내가 관련이 난 것 그 부분 버퍼로이 문제를 해결 한 이후 :
Object::Object() {
...
glGenVertexArrays(1, &VAO_);
glGenBuffers(2, VBO_);
glGenBuffers(1, &EBO_);
glBindVertexArray(VAO_);
glBindBuffer(GL_ARRAY_BUFFER, VBO_[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * 3, vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO_[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * 2, tex_vert, GL_STREAM_DRAW);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 6, indices, GL_STATIC_DRAW);
glBindVertexArray(0); // unbind vertex
glBindBuffer(GL_ARRAY_BUFFER, 0); // unbind buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // unbind buffer
}
void Object::Update() {
...
glBindBuffer(GL_ARRAY_BUFFER, VBO_[1]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * 4 * 2, tex_vert);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void Object::Render() {
...
glUseProgram(Shader_.GetProgramID());
glBindVertexArray(VAO_);
glBindTexture(GL_TEXTURE_2D, Texture_);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
int Main() {
Object m();
Object m2();
Object m3();
while (!glfwWindowShouldClose(engine.window)) {
...
m.Update();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m.Render();
m3.Render();
m2.Render();
glfwSwapBuffers(window);
...
}
}
그래서 anitmated 얻을 M3 만 m는 이동
등을 m3와 m2로 변경 장소, m2가됩니다 움직이게. m2/m3을 렌더링하지 않으면 m은 애니메이션과 움직입니다. 언급하자면, 애니메이션이 아닌 모든 객체는 텍스처를 얻지 만 초기화 상태를 유지하므로 모든 것이 처음부터 잘 보입니다.
VAO, VBO 및 EBO는 각 개체마다 다른 값을 가지지 만 "잘못된"버퍼 (VBO_ [1])가 업데이트됩니다.
대부분의 잘못된 방법으로이 문제를 해결 했으므로 다른 사람이 올바른 방향으로 나를 가리킬 수 있다면 정말 고맙겠습니다.
편집 :
에 대한 추가 정보 조각 쉐이더
void Object::Update() {
if (Keyboard::KeyPressed(GLFW_KEY_W)) {
if (MovementY_ < 0) {
MovementY_ = 0;
}
MovementY_ += MovementSpeed_ * Engine::GetDeltaTime();
TextureTopLeft_ = glm::vec2((MALE_TEXTURE_SIZE_S * SpriteFrame_) - MALE_TEXTURE_SIZE_S, MALE_UP_STAND_T - MALE_TEXTURE_SIZE_T);
TextureTopRight_ = glm::vec2((MALE_TEXTURE_SIZE_S * SpriteFrame_), MALE_UP_STAND_T - MALE_TEXTURE_SIZE_T);
TextureBottomLeft_ = glm::vec2((MALE_TEXTURE_SIZE_S * SpriteFrame_) - MALE_TEXTURE_SIZE_S, MALE_UP_STAND_T);
TextureBottomRight_ = glm::vec2((MALE_TEXTURE_SIZE_S * SpriteFrame_), MALE_UP_STAND_T);
}
float tex_vert[4][2] = {
{TextureTopRight_.s, TextureTopRight_.t},
{TextureBottomRight_.s, TextureBottomRight_.t},
{TextureBottomLeft_.s, TextureBottomLeft_.t},
{TextureTopLeft_.s, TextureTopLeft_.t},
};
glBindBuffer(GL_ARRAY_BUFFER, VBO_[1]);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * 4 * 2, tex_vert);
glBindBuffer(GL_ARRAY_BUFFER, 0);
PositionX_ += MovementX_;
PositionY_ += MovementY_;
}
void Object::Render() {
glm::mat4 Projection, Model;
Projection = glm::orthoLH(0.0f, float(Engine::GetFrameBufferWidth()), 0.0f, float(Engine::GetFrameBufferHeight()), 0.0f, 1000.0f);
Model = glm::translate(Model, glm::vec3(PositionX_, PositionY_, PositionY_));
glm::mat4 mvp = Projection * Model;
GLint MVP = glGetUniformLocation(Shader_.GetProgramID(), "MVP");
glUniformMatrix4fv(MVP, 1, GL_FALSE, glm::value_ptr(mvp));
glUseProgram(Shader_.GetProgramID());
glBindVertexArray(VAO_);
glBindTexture(GL_TEXTURE_2D, Texture_);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
# These two never change, assigned in object-creation.
float vertices[4][3] = {
{+SpriteWidth_, +SpriteHeight_, 0.0f},
{+SpriteWidth_, -SpriteHeight_, 0.0f},
{-SpriteWidth_, -SpriteHeight_, 0.0f},
{-SpriteWidth_, +SpriteHeight_, 0.0f},
};
unsigned int indices[] = {
2, 1, 0,
2, 0, 3,
};
등 버퍼를 작성하는 방법 : 쉐이더
out vec4 FragColor;
in vec2 TexCoord;
uniform sampler2D ourTexture;
void main() {
FragColor = texture(ourTexture, TexCoord);
}
정점 :
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
out vec2 TexCoord;
uniform mat4 MVP;
void main() {
gl_Position = MVP * vec4(aPos, 1.0);
TexCoord = aTexCoord;
}
이것은 완전히 불분명합니다. 객체를 어떻게 움직이고 움직이게합니까? 어떤 행렬을 사용하고 어딘가에 설정합니까? [최소한의 완전하고 검증 가능한 예제를 만드는 방법] (https://stackoverflow.com/help/mcve)을 읽어보십시오. – Rabbid76
질문이 더 많은 정보로 업데이트되었지만이 정보가 필요하다고 생각하는 이유를 협조 해주십시오. 나는 그것이 실제 예를 어지럽 혔다 고 생각했기 때문에 실종되었다. 문제는 개체가 잘못된 위치에 있는지에 관한 것이 아니라 업데이트 기능을 실행하지 않는 개체가 "tex_vert"에서 새로운 정보를 얻는 이유입니다. – nauman
'VERTEX shader'라고 부르면 조각 쉐이더입니다. 개체의 움직임과 애니메이션에 문제가 있다고하셨습니다.그러나 당신은 여전히 움직이는 코드를 사용하여 객체를 움직이게하지 않습니다. 버텍스 쉐이더와 매트릭스 설정을 보여주십시오. 큰 소리로 울부 짖기위한 – Rabbid76