Sei sulla pagina 1di 3

#include <stdlib.

h>
#include <math.h>
#include <GL/glut.h>
#define GL_PI 3.1416f
void init(void);
void display(void);
void reshape(int,int);
void ejes(void);
void cuadrado(void);
//void arco(float,float,float,float,float);
void circulo(int);
void arco(float,float,float,float,float);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0); //parametros: rojo, amarillo, azul, el cuarto es el
parametro alpha
glShadeModel(GL_FLAT);
glColor3f(1.0,0.0,0.0);
}

void cuadrado(void)
{
glBegin(GL_LINE_STRIP);
glVertex2f(-1.0,-1.0);
glVertex2f(1.0,-1.0);
glVertex2f(1.0,1.0);
glVertex2f(-1.0,1.0);
glVertex2f(-1.0,-1.0);
glEnd();
}

void ejes(void)
{
glBegin(GL_LINES);
glVertex2f(-9.0,0.0);
glVertex2f(9.0,0.0);
glVertex2f(0.0,-9.0);
glVertex2f(0.0,09.0);
glEnd();
}

void circulo(int N)
{
GLfloat ang, radio = 8.0f, x, y;
glBegin(GL_LINE_STRIP);
for (ang = 0.0f; ang < 2 * GL_PI; ang += 2*GL_PI/N)
{
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);
}
glEnd();
}

void arco(float radio,float cx,float cy,float ang1,float ang2)


{
GLfloat ang=0, x, y;
//ang1=2*GL_PI;
//ang2=3*GL_PI/2;
glBegin(GL_LINE_STRIP);
for (ang = ang1 ; ang >= ang2; ang -= 0.01)
{
y = radio * sin(ang)+cx;
x = radio * cos(ang)+cy;
glVertex2f(x,y);
}
glEnd();
}

void display(void)
{

glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

ejes();
glColor3f(0.0,1.0,1.0);
cuadrado();
glColor3f(0.0,1.0,0.0);
//glColor3f(0.5,0.5,0.5);
circulo(50);
arco(4.0,0.0,0.0,2*GL_PI,3*GL_PI/2);
arco(5.0,0.0,0.0,GL_PI,GL_PI/2);
arco(2.0,2.0,2.0,GL_PI,GL_PI/2);

// salva el estado actual de la matriz

glPopMatrix(); // reecupera el estado del matriz


glFlush();
}

void reshape(int w, int h)


{
glViewport(0,0,(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0,10.0,-10.0,10,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

Potrebbero piacerti anche