You are on page 1of 8

Questão 1)

#include <iostream>

#include <GL/glut.h>

#include <math.h>

#define PI 3.141519

#define NPontos 100

void Retangulo() {

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);

glColor3f(0.0, 0.611, 0.213);

glVertex2f(-1.0, 1.0);

glColor3f(0.0, 0.611, 0.213);

glVertex2f(-1.0, -1.0);

glColor3f(0.0, 0.611, 0.213);

glVertex2f(1.0, -1.0);

glColor3f(0.0, 0.611, 0.213);

glVertex2f(1.0, 1.0);

glEnd();

glBegin(GL_QUADS);

glColor4f(1.0, 0.874, 0.0, 0.6);

glVertex2f(0.0, 0.70);

glColor4f(1.0, 0.874, 0.0, 0.6);

glVertex2f(-1.0, 0.0);

glColor4f(1.0, 0.874, 0.0, 0.6);

glVertex2f(0.0, -0.70);

glColor4f(1.0, 0.874, 0.0, 0.6);

glVertex2f(1.0, 0.0);

glEnd();

int i;

glColor4f(0.0, 0.0, 1.0, 0.6);

glBegin(GL_POLYGON);
for (i = 0; i <= NPontos; i++) {

float ang = 2.0 * PI * i / NPontos;

glVertex2f(0.45 * cos(ang), 0.45 * sin(ang));

glEnd();

glFlush();

void Inicia(void) {

glClearColor(0.0, 0.0, 0.0, 1.0);

int main() {

glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

glutCreateWindow("BANDEIRA");

glutDisplayFunc(Retangulo);

Inicia();

glutMainLoop();

return (0);

}
#include<iostream>

#include<GL/glut.h>

#include<fstream>

#include<sstream>

#include<windows.h>

using namespace std;

void Desenha(void) {

ifstream arquivoE;

string linha;

int pontos[32][2];

int i = 0, j = 0;

arquivoE.open("contorno.txt");

if (arquivoE.is_open())

while (getline(arquivoE, linha)) {

pontos[i][j] = stoi(linha);

j++;

if (j == 2) {

i++;

j = 0;

} else {

cout << "Não foi possivel ler o arquivo" << endl;

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0f, 0.650f, 0.650f);

glBegin(GL_LINE_LOOP);

glVertex2i(pontos[0][0], pontos[0][1]);

glVertex2i(pontos[1][0], pontos[1][1]);
glVertex2i(pontos[2][0], pontos[2][1]);

glVertex2i(pontos[3][0], pontos[3][1]);

glVertex2i(pontos[4][0], pontos[4][1]);

glVertex2i(pontos[5][0], pontos[5][1]);

glVertex2i(pontos[6][0], pontos[6][1]);

glVertex2i(pontos[7][0], pontos[7][1]);

glVertex2i(pontos[8][0], pontos[8][1]);

glVertex2i(pontos[9][0], pontos[9][1]);

glVertex2i(pontos[10][0], pontos[10][1]);

glVertex2i(pontos[11][0], pontos[11][1]);

glVertex2i(pontos[12][0], pontos[12][1]);

glVertex2i(pontos[13][0], pontos[13][1]);

glVertex2i(pontos[14][0], pontos[14][1]);

glVertex2i(pontos[15][0], pontos[15][1]);

glVertex2i(pontos[16][0], pontos[16][1]);

glVertex2i(pontos[17][0], pontos[17][1]);

glVertex2i(pontos[18][0], pontos[18][1]);

glVertex2i(pontos[19][0], pontos[19][1]);

glVertex2i(pontos[20][0], pontos[20][1]);

glVertex2i(pontos[21][0], pontos[21][1]);

glVertex2i(pontos[22][0], pontos[22][1]);

glVertex2i(pontos[23][0], pontos[23][1]);

glVertex2i(pontos[24][0], pontos[24][1]);

glVertex2i(pontos[25][0], pontos[25][1]);

glVertex2i(pontos[26][0], pontos[26][1]);

glVertex2i(pontos[27][0], pontos[27][1]);

glVertex2i(pontos[28][0], pontos[28][1]);

glVertex2i(pontos[29][0], pontos[29][1]);

glVertex2i(pontos[30][0], pontos[30][1]);

glVertex2i(pontos[31][0], pontos[31][1]);

glEnd();
glFlush();

void Inicializa(void) {

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

void AlteraTamanhoJanela(GLsizei w, GLsizei h) {

if (h == 0)

h = 1;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

if (w <= h)

gluOrtho2D(0.0f, 128.0f, 0.0f, 128.0f * h / w);

Else

gluOrtho2D(0.0f, 128.0f * w / h, 0.0f, 128.0f);

int main(void) {

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(128, 128);

glutInitWindowPosition(128, 128);

glutCreateWindow("Golfinho");

glutDisplayFunc(Desenha);

glutReshapeFunc(AlteraTamanhoJanela);

Inicializa();

glutMainLoop();

You might also like