PDA

View Full Version : Objects disappear after intermittent time



Talan77
05-08-2014, 11:53 AM
Hi, I'm building up a 2D game in c++ with OpenGL, and recently I ran into a glitch with the objects on my screen all disappearing. This started after I updated my code to include 2 types of objects, an orb and a player, each with their own shader programs. The render function for my player object, given w as a pointer to my World object, is:


void Player::render(int layer) {
glUseProgram(w->scaleing_program);
glUniformMatrix4fv(w->proj2_location, 1, GL_FALSE, w->proj_matrix);
glBindTexture(GL_TEXTURE_2D, w->texture[1]);

glBindBuffer(GL_ARRAY_BUFFER, vbo);
GLint posAttrib = glGetAttribLocation(w->scaleing_program, "position");
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(posAttrib);

vmath::vec2 pos = {position.mX, position.mY};
vmath::vec2 cam = { TheCamera::Instance()->point.mX, TheCamera::Instance()->point.mY};
vmath::vec2 offset = (pos - cam)/100.0f;

vmath::mat4 mv_matrix = vmath::translate(offset[0], offset[1], 0.0f);
//vmath::rotate(0.0f, 0.0f, 0.0f, 0.0f);
glUniformMatrix4fv(w->mv2_location, 1, GL_FALSE, mv_matrix);

GLint rl = glGetUniformLocation(w->scaleing_program, "r");
glUniform1f(rl,radius/30.0f);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}


my other object is very similar; Am I missing something?? The objects disappear usually after about 15 - 30 seconds on the screen, but appear fine until then...

-Baffled N00b

Talan77
05-11-2014, 03:39 AM
I guess my OpenGL code is alright for now; I found an issue with seconds passed being 0 on occasion causing the glitches.