This has me stumped for quiet sometime now that I don't know what to do anymore with it.
So basically I have a ball that just moves from one side of the screen to the other, and even though the game is running upwards of 100+ FPS, I still see the the ball jump or stagger around when it moves, as if its skipping frames or something, and I don't know where the problem is, and its just killing my mood :(
Here is a video of the thing:
and here is the relevant code:
int main(int argc, char ** argv) {
//snip some code
glfwSetTime(0);
double total_time = 0;
double current_time = glfwGetTime();
double previous_time = current_time;
glfwSwapInterval(0);
while(run) {
current_time = glfwGetTime();
gamestate.update(&gamestate, &mouse_st, current_time - previous_time);
previous_time = current_time;
if(!gamestate.is_init) {
gamestate.init(&gamestate);
gamestate.is_init = 1;
}
if((glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)) {
run = false;
glfwSetWindowShouldClose(window, true);
}
glClear(GL_COLOR_BUFFER_BIT);
gamestate.render(&gamestate);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
return 0;
}
and here is what what update and render functions do:
void render(game_state *gamestate) { //Render Function
int vpos = gamestate->vpos_attrib_loc;
int color = gamestate->color_attrib_loc;
int model = gamestate->model_t_attrib_loc;
start_node = gamestate->named_objects;
for(int i = 0; i < gamestate->object_count; ++i) {
switch(start_node->type) {
case BALL: {
ball_object *ball = (ball_object *) start_node->obj;
ball->circ.render(vpos, color, model);
} break;
//snip code
}
start_node++;
}
}
////////////////////////////Update Fucntion//////////////////////////
void update(game_state *gamestate, mouse_state *mouse, double dt) {
start_node = gamestate->named_objects;
for(int i = 0; i < gamestate->object_count; ++i) {
switch(start_node->type) {
case BALL: {
ball_object *ball = (ball_object *) start_node->obj;
ball->circ.move_position((float)( ball->velocity*dt ));
if(ball->circ.get_position().y < -gamestate->window_width_height.y/2.0)
ball->circ._direction.y = 1;
if(ball->circ.get_position().y > gamestate->window_width_height.y/2.0)
ball->circ._direction.y = -1;
if(ball->circ.get_position().x < -gamestate->window_width_height.x/2.0)
ball->circ._direction.x = 1;
if(ball->circ.get_position().x > gamestate->window_width_height.x/2.0)
ball->circ._direction.x = -1;
} break;
}
start_node++;
}
}