Reputation: 2749
I have a simple openGl program that should redrawn when i change a spinner. When the paintGL method is invoked the color of my vertex triangles change but the number of them (that is based on the spinner ) don't.
My code is the following:
void GLWidget::paintGL()
{
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR) ;
glClearColor(0.0, 0.0, 0.0, 0.0);
for(int i=0;i<numVertex;i++){
glBegin(GL_TRIANGLE_FAN);
drawTriangle(i);
glEnd();
}
qDebug("numVetex %d",numVertex);
};
void GLWidget::drawTriangle(int iteraction){
float theta=thetaIncrement*iteraction;
float x= radius*qCos(theta);
float y=radius*qSin(theta);
double r=((double) rand() / (RAND_MAX));
double g=((double) rand() / (RAND_MAX));
double b=((double) rand() / (RAND_MAX));
glColor3f(r,g,b);
glVertex3f( 0.0f, 0.0f, 0.0f);
glVertex3f(x,y,0.0f);
theta=thetaIncrement*(iteraction+1);
x= radius*qCos(theta);
y=radius*qSin(theta);
glVertex3f( x,y, 0.0f);
}
Even if i don't draw anything for example, on even number of vertex i just put a return on paintGl , the already drawn vertex still are showed on the screen.
Any recommendation?
Upvotes: 0
Views: 45
Reputation: 48216
your glClear call doesn't have a valid argument remove the GL_COLOR part:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
Upvotes: 1