void display() { /*start boiler*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //set camera direction and position gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw light source glLightfv(GL_LIGHT0, GL_POSITION, light_one); /*end boiler*/ GLfloat increment = 0.005; if (moveCounter > 1000) { moveCounter = 0; } if (moveCounter > 660) { changeColor[1] += increment; changeColor[2] = 0; changeColor[0] = 0; } else if (moveCounter > 330) { changeColor[1] = 0; changeColor[2] += increment; changeColor[0] = 0; } else if (moveCounter > 0) { changeColor[1] = 0; changeColor[2] = 0; changeColor[0] += increment; } moveCounter++; s.setColor(changeColor); for (int i = 0; i < squareLength; i++) { allSquares[i].move(); } draw(); /*start boiler*/ glFlush(); glutSwapBuffers(); /*end boiler*/ }
//do all rendering here, "should" only call .draw on objects void draw() { if (leftMouseDown == true) { s.setColor(red); } else { s.setColor(green); } //move object according to mouse flags (should be in mouse movement function) /*if (isMovingLeft && leftMouseDown) { s.move(-0.01f, 0); } else if (leftMouseDown) { s.move(0.01f, 0); }*/ //loop through squares array and draw for (int i = 0; i < squareLength; i++) { allSquares[i].draw(); } //draw the square s //s.draw(); //force update (only if we changed something, should have this in mouse or keyboard functions glutPostRedisplay(); }
void keyboard(unsigned char key, int x, int y) { //user interaction here switch(key) { case 'a': viewer[0] -= 0.5f; break; case 'w': viewer[1] += 0.5f; break; case 's': viewer[1] -= 0.5f; break; case 'd': viewer[0] += 0.5f; break; case 'q': viewer[2] -= 0.5f; break; case 'e': viewer[2] += 0.5f; break; case 'j': light_one[1] -= 5.0f; break; case 'k': light_one[1] += 5.0f; break; case 'i': light_one[2] -= 5.0f; break; case 'm': light_one[2] += 5.0f; break; case'1': x_pos -= 0.5; break; case'2': x_pos += 0.5; break; case 'o': s.hide(); break; case 'p': s.show(); break; case 'W': s.move(0,0.1); break; case 'S': s.move(0,-0.1); break; case 'A': s.move(0.1,0); break; case'D': s.move(-0.1,0); break; case 'r': changeColor[0]= 1; changeColor[1]= 0; changeColor[2]= 0; break; case 'g': changeColor[1]+= 0.1; } s.setColor(changeColor); glutPostRedisplay(); }
void display() { /*start boiler*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //set camera direction and position gluLookAt(viewer[0], viewer[1], viewer[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw light source glLightfv(GL_LIGHT0, GL_POSITION, light_one); /*end boiler*/ //dummy triangle //glBegin(GL_QUADS); // glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); // glVertex3f(-2,2,0); // glVertex3f(2,2,0); // glVertex3f(2,-2,0); // glVertex3f(-2,-2,0); //glEnd(); /*moveCounter++; if (moveCounter < 100) { s.move(0.1, 0.1); }*/ GLfloat increment = 0.005; if (moveCounter > 1000) { moveCounter = 0; } if (moveCounter > 660) { changeColor[1] += increment; changeColor[2] = 0; changeColor[0] = 0; } else if (moveCounter > 330) { changeColor[1] = 0; changeColor[2] += increment; changeColor[0] = 0; } else if (moveCounter > 0) { changeColor[1] = 0; changeColor[2] = 0; changeColor[0] += increment; } moveCounter++; s.setColor(changeColor); s.draw(); glutPostRedisplay(); /*start boiler*/ glFlush(); glutSwapBuffers(); /*end boiler*/ }