PDA

View Full Version : Visual artifact with single object rotation



Savvy_Fox42
12-14-2014, 10:17 AM
When my render code runs, it leaves an artifact of the unrotated cube, without the texture being applied.

Picture of the window:

1548

Render code: (rotated object exists in last 36 vertices)



GLuint MVP_id = glGetUniformLocation(program, "MVP");
mat4 projectionMatrix = perspective(60.0f, 4.0f / 3.0f, 0.01f, 100.0f);
mat4 viewMatrix = camera.getViewMatrix();
mat4 staticModelMatrix = mat4(1.0f);
mat4 rotateModelMatrix = mat4(1.0f);
mat4 SMVP = projectionMatrix * viewMatrix * staticModelMatrix;
mat4 RMVP = projectionMatrix * viewMatrix * staticModelMatrix;

rotateModelMatrix = glm::translate(rotateModelMatrix, vec3(-2, 2, 2));
rotateModelMatrix = glm::rotate(rotateModelMatrix, 45.0f, vec3(0, 1, 0));
rotateModelMatrix = glm::translate(rotateModelMatrix, vec3(2, -2, -2));

[...] Other code for putting verts in array [...]

int tris = verts.size() / 3;

GLuint VAOid = 0;
glGenVertexArrays(1, &VAOid);
glBindVertexArray(VAOid);

GLuint vertexbuffer;
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, verts.size() * sizeof(float), &verts[0], GL_STATIC_DRAW);

GLuint uvbuffer;
glGenBuffers(1, &uvbuffer);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(uvs), uvs, GL_STATIC_DRAW);

static double lastTime = glfwGetTime();
float deltaTime;
numFrames = 0;

glfwSetInputMode(main_Window.window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetCursorPos(main_Window.window, 0, 0);

while (!glfwWindowShouldClose(main_Window.window)) // Update loop for game
{
double currentTime = glfwGetTime();
numFrames++;
if (currentTime - lastTime >= 1.0){ // If last prinf() was more than 1 sec ago
// printf and reset timer
printf("%f ms/frame\n", 1000.0 / double(numFrames));
numFrames = 0;
lastTime += 1.0;
}
deltaTime = float(currentTime - lastTime); // FPS Counter Code (It's actually a milisecond per frame counter.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear buffers for rendering to.

glUseProgram(program);

glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);

viewMatrix = player001.getViewMatrix();
RMVP = projectionMatrix * viewMatrix * rotateModelMatrix;
glUniformMatrix4fv(MVP_id, 1, GL_FALSE, &RMVP[0][0]);

glDrawArrays(GL_TRIANGLES, tris-36, tris);

viewMatrix = player001.getViewMatrix();
SMVP = projectionMatrix * viewMatrix * staticModelMatrix;
glUniformMatrix4fv(MVP_id, 1, GL_FALSE, &SMVP[0][0]);

glDrawArrays(GL_TRIANGLES, 0, tris-36);

glUseProgram(0); // Render code that uses a basic shader (program 0).

uwi2k2
12-15-2014, 12:58 AM
hi,

the code so far looks fine ...
can you upload all your code so i could test it ... there must be a other logic bug in it.

regards
uwi2k2

Savvy_Fox42
12-15-2014, 01:08 PM
Thank you for your response, but I have already have fixed the issue. It was due to a vertex order issue. If someone can mark this as answered or delete it that would be appreciated.