Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Rafael de Luna Galdino RA 072135 , UNICAMP-2010 */
- #include <stdlib.h>
- #include <GL/glut.h>
- //coordenada y
- GLint y1 = 1;
- GLint height = 80;
- GLint x = 11;
- GLint inc = 5;
- int cont_numquads = 0;
- GLint vet_posy[10];
- //condicao
- int inicio = 1;
- int direcao[10];
- void init(void);
- void criaQuads(int x1, int y1, float corR, float corG, float corB);
- void display(void);
- void move(int passo);
- void keyboard(unsigned char key, int x, int y);
- int main(int argc, char** argv){
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize (180, 100);
- glutInitWindowPosition (100, 100);
- glutCreateWindow ("rOLAAAA");
- init();
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
- void init(void)
- {
- int i;
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glOrtho (0, 180, 0, 100, -1 ,1);
- for (i = 0; i < 10; ++i)
- {
- direcao[i] = inicio;
- vet_posy[i] = 10;
- }
- }
- void display(void)
- {
- int cont;
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(1.0, 1.0, 1.0);
- glLineWidth(15.0);
- // borda
- glBegin(GL_LINE_LOOP);
- glVertex2i(1,1); glVertex2i(180,1);
- glVertex2i(180,100); glVertex2i(1,100);
- glEnd();
- for (cont = 0; cont < 10; cont++)
- {
- criaQuads(x, vet_posy[cont], 0.8, 0.2, 0.8);
- x = x + 15;
- }
- x = 11;
- if (cont_numquads < 10)
- cont_numquads++;
- glFlush();
- glutSwapBuffers();
- }
- void criaQuads(int x, int y, float corR, float corG, float corB)
- {
- glColor3f(corR, corG, corB);
- glBegin(GL_QUADS);
- glVertex2i(x, y + 10);
- glVertex2i(x + 10, y + 10);
- glVertex2i(x + 10, y);
- glVertex2i(x, y);
- glEnd();
- }
- void keyboard(unsigned char key, int x, int y){
- switch (key)
- {
- case 27:
- exit(0);
- break;
- case 32:
- glutTimerFunc(50, move, 1);
- break;
- }
- }
- void move(int passo)
- {
- for(int cont = 0; cont < cont_numquads; cont++)
- {
- if (direcao[cont] == 1)
- vet_posy[cont] += inc;
- if (vet_posy[cont] == height)
- direcao[cont] = 0;
- if (direcao[cont] == 0)
- vet_posy[cont] -= inc;
- if (vet_posy[cont] == 10)
- direcao[cont] = 1;
- }
- glutPostRedisplay();
- glutTimerFunc(30,move, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment