Códigos Programas Bandeira, Cubo E Pirâmide em Opengl

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Códigos Programas Bandeira , Cubo e Pirâmide em

OpenGl.

Bandeira
/*Aluna: Deise Neves*/

#include <windows.h>

#include <GL\gl.h>

#include <GL\glu.h>

#include <GL\glut.h>

#include <math.h>

#define PI 3.1415926535

void Bandeira(void)

double i, angle;

glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0f, 1.0f, 0.0f);//Verde retangulo

glBegin(GL_QUADS);

glVertex2f(-0.4f,-0.3f);

glVertex2f(-0.4f,0.3f);
glVertex2f(0.4f,0.3f);

glVertex2f(0.4f,-0.3f);

glEnd();

glColor3f(1.0f,1.0f,0.5f);//Amarelo losango

glBegin(GL_QUADS);

glVertex2f(0.0,-0.3f);

glVertex2f(-0.4f,0.0f);

glVertex2f(0.0f,0.3f);

glVertex2f(0.4f,0.0f);

glEnd();

glColor3f(0.0, 0.0, 1.0);//Azul circunferencia

glBegin(GL_POLYGON);

for (i = 0; i < 100; i++)

angle = 2*PI*i/100;

glVertex2f(cos(angle)/5.3, sin(angle)/5.0);

glEnd();

glFlush();

void Inicializa (void)

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

int main(void)

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(400,350);

glutInitWindowPosition(10,10);

glutCreateWindow("Bandeira");

glutDisplayFunc(Bandeira);

Inicializa();

glutMainLoop();

}
Pirâmide e Cubo
/*Aluna: Deise Neves*/

#include <GL/glut.h>

#include <stdlib.h>

static int slices = 16;

static int stacks = 16;

void resize(int width, int height)

const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity() ;

void Desenha(void)
{

const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;

const double a = t*90.0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/*Cubo 2D*/

glPushMatrix();

glTranslated(-2.4,1.2,-6);

glRotated(60,1,0,0);

glRotated(a,0,0,1);

glBegin(GL_LINE_LOOP);

glColor3f(1.0f,0.0f,0.5f);

glVertex2f(0.1f,0.1f);

glVertex2f(0.1f,0.6f);

glVertex2f(0.1f,0.1f);

glVertex2f(0.6f,0.1f);

glVertex2f(0.7f,0.2f);

glVertex2f(0.6f,0.1f);

glVertex2f(0.6f,0.6f);

glVertex2f(0.7f,0.7f);

glVertex2f(0.6f,0.6f);

glVertex2f(0.1f,0.6f);

glVertex2f(0.2f,0.7f);

glVertex2f(0.7f,0.7f);

glVertex2f(0.7f,0.2f);
glVertex2f(0.2f,0.2f);

glVertex2f(0.2f,0.7f);

glVertex2f(0.2f,0.2f);

glVertex2f(0.1f,0.1f);

glEnd();

glPopMatrix();

/*Piramide 2D*/

glPushMatrix();

glTranslated(0,1.2,-6);

glRotated(60,1,0,0);

glRotated(a,0,0,1);

glBegin(GL_LINE_LOOP);

glColor3f(0.5f,0.0f,0.0f);

glVertex2f(0.0f,0.0f);

glVertex2f(0.5f,0.0f);

glVertex2f(0.0f,0.3f);

glVertex2f(0.0f,0.0f);

glVertex2f(-0.25f,-0.3f);

glVertex2f(0.0f,0.3f);

glVertex2f(0.25f,-0.3f);

glVertex2f(0.5f,0.0f);

glVertex2f(0.25f,-0.3f);

glVertex2f(-0.25f,-0.3f);

glEnd();

glPopMatrix();
/*Triangulo 2D*/

glPushMatrix();

glTranslated(2.4,1.2,-6);

glRotated(60,1,0,0);

glRotated(a,0,0,1);

glBegin(GL_TRIANGLES);

glColor3f(1.0f, 0.0f, 0.0f);

glVertex2f(0.0f,0.0f);

glColor3f(0.0f, 1.0f, 0.0f);

glVertex2f(0.3f,0.6f);

glColor3f(0.0f, 0.0f, 1.0f);

glVertex2f(0.6f,0.0f);

glEnd();

glPopMatrix();

glutSwapBuffers();

void idle(void)

glutPostRedisplay();

int main(int argc, char *argv[])

{
glutInit(&argc, argv);

glutInitWindowSize(640,480);

glutInitWindowPosition(10,10);

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("CUBO, PIRAMIDE E TRIANGULO 2D");

glutReshapeFunc(resize);

glutDisplayFunc(Desenha);

glutIdleFunc(idle);

glutMainLoop();

return EXIT_SUCCESS;

You might also like