OpenGL flickerinng near the edges
Posted
by
Daniel
on Game Development
See other posts from Game Development
or by Daniel
Published on 2014-06-11T09:26:28Z
Indexed on
2014/06/11
9:43 UTC
Read the original article
Hit count: 340
opengl
I am trying to simulate particles moving around the scene with OpenCL for computation and OpenGL for rendering with GLUT. There is no OpenCL-OpenGL interop yet, so the drawing is done in the older fixed pipeline way. Whenever circles get close to the edges, they start to flicker. The drawing should draw a part of the circle on the top of the scene and a part on the bottom.
The effect is the following:
The balls you see on the bottom should be one part on the bottom and one part on the top. Wrapping around the scene, so to say, but they constantly flicker.
The code for drawing them is:
void
Scene::drawCircle(GLuint index){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(pos.at(2*index),pos.at(2*index+1), 0.0f);
glBegin(GL_TRIANGLE_FAN);
GLfloat incr = (2.0 * M_PI) / (GLfloat) slices;
glColor3f(0.8f, 0.255f, 0.26f);
glVertex2f(0.0f, 0.0f);
glColor3f(1.0f, 0.0f, 0.0f);
for(GLint i = 0; i <=slices; ++i){
GLfloat x = radius * sin((GLfloat) i * incr);
GLfloat y = radius * cos((GLfloat) i * incr);
glVertex2f(x, y);
}
glEnd();
}
If it helps, this is the reshape method:
void
Scene::reshape(GLint width, GLint height){
if(0 == height) height = 1; //Prevent division by zero
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(xmin, xmax, ymin, ymax);
std::cout << xmin << " " << xmax << " " << ymin << " " << ymax << std::endl;
}
© Game Development or respective owner