Está en la página 1de 5

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //*Num de buffer que se va a

utilizar y color
glutDisplayFunc(display); //*funcion de dibujado: display
glClearColor(0,0,1,0); //*Color de fondo, color de borrado
glClear(GL_COLOR_BUFFER_BIT); //*Cuando se mueve para que se vuelva a
dibujar primero limpiando
glFlush(); //*limpiar el buffer
glOrtho(-10.0,10.0,-10.0,10,-10.0,10.0); //*Inicializar la cámara
*GL_PI -> M_PI
--------------------------------------------------------------------------------------------
glutInitWindowSize(200, 200); //Cambiar el tamaño de la ventana
glOrtho(-50.0, 50.0, -50.0, 50, -1.0, 1.0); //En sist. de coordenadas OpenGL 100
//pixeles horizontales, 100 verticales;
*coord. Enteras
glOrtho(-100.0, 100.0, -100.0, 100, -1.0, 1.0); //200 pixeles x 200

++
//Algoritmo antialiasing para suavizar bordes en rectas

void init(void)
{
glClearColor(0,0.5,0.2,0); //Color de fondo de la ventana
glPointSize(10); //Para tamaño del punto
glColor3f(0,1,1); // Color para dibujar todos los puntos
glShadeModel(GL_FLAT);
}
--------------------------------------------------------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_POINTS);
glVertex2f(0,0); //Graficar puntos
glVertex2d(5,5); //Otra manera
glEnd();
glPopMatrix();
glFlush();
}
--------------------------------------------------------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glPointSize(5); //Tamaño del punto antes del glBegin()
glBegin(GL_POINTS);
glColor3f(1,0,0); //Color de punto
glVertex2f(0,0); //
glColor3f(1,1,0); // Otro color de punto
glVertex2f(3,3); //
glEnd();
glPopMatrix();
glFlush();
}
--------------------------------------------------------------------------------------------
void display(void)
{
GLfloat ang, radio = 8.0f, x, y;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glLineWidth(9); //Grosor de línea
glColor3f(1,0,0); //Color de líneas
glBegin(GL_LINE_LOOP); //Figura cerrada sin relleno
//glBegin(GL_POLYGON); //Figura cerrada con relleno

for (ang = 0.0f; ang < 2 * M_PI; ang += 2*M_PI/5)


{
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);
}

glColor3f(0,0,1);
glVertex2f(0,0);
glEnd();
glPopMatrix(); /
glFlush();
}
--------------------------------------------------------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glColor3f(0,0,0);
glRectf(0,0,8,8); //Dibujar rectángulo plano
glRectf(-8,-8,0,0); //
glColor3f(1,1,1);
glRectf(-8,0,0,8); //
glRectf(0,-8,8,0); //
glPopMatrix();
glFlush();
}
--------------------------------------------------------------------------------------------
Disco hueco
GLUquadricObj *pt;
pt=gluNewQuadric();
// esta orden especifica como va a ser renderizado:
gluQuadricDrawStyle(pt,GLU_LINE);
glColor3f (1.0, 0.0, 0.0);
// Dibuja Discos
gluDisk(pt, 4, 9, 15, 6);
--------------------------------------------------------------------------------------------
Sector de disco hueco
GLUquadricObj *pt;
pt=gluNewQuadric();
// renderizar con lineas
gluQuadricDrawStyle(pt,GLU_LINE);
glColor3f (1.0, 0.0, 0.0);
// Dibuja Disco parcial
gluPartialDisk(pt, 4, 9, 15, 6,0,90);

------------------------------------------------------------------------------------------------------
//HACAR LINEA
void linea(int x0, int y0,int x1,int y1){
glBegin(GL_LINES);
glVertex2f(x0,y0);
glVertex2f(x1,y1);
glEnd();
}
------------------------------------------------------------------------------------------------------

LABO 01
EJERCICIO 2

void display(void)
{
GLfloat ang, radio = 8.0f, x, y, aux1, aux2;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glColor3f(1,0,0);

int num, lado;


cout<<"Longitud del lado del cuadrado: ";
//cin>>lado;
lado=16;
cout<<"Numero de cuadrados: ";
//cin>>num;
num=8;

GLfloat vx[4];
vx[0]=-lado/2;
vx[1]=lado/2;
vx[2]=lado/2;
vx[3]=-lado/2;
GLfloat vy[4];
vy[0]=lado/2;
vy[1]=lado/2;
vy[2]=-lado/2;
vy[3]=-lado/2;

for(int k=0; k<num; k++){


glBegin(GL_LINE_LOOP);
aux1=vx[0];
aux2=vy[0];
for(int i=0; i<4; i++){
x = vx[i];
y = vy[i];
if(i!=3){
vx[i] = (vx[i]+vx[i+1])/2;
vy[i] = (vy[i]+vy[i+1])/2;
}else{
vx[i] = (vx[i]+aux1)/2;
vy[i] = (vy[i]+aux2)/2;
}
glVertex2f(x,y);
}
glEnd();
}

glPopMatrix(); // reecupera el estado del matriz


glFlush();
}

EJERCICIO 3

void display(void)
{
GLfloat ang, radio = 8.0f, x, y, aux1, aux2;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); // salva el estado actual de la matriz

glColor3f(0,0,0);
glBegin(GL_LINE_LOOP);

for (ang = 0.0f; ang < 2 * M_PI; ang += 2*M_PI/100)


{
//radio=2+4*sin(ang);
//radio=3-3*sin(ang);
//radio=ang;
radio=sin(ang) + pow(sin(2.5*ang),3);
x = radio * sin(ang);
y = radio * cos(ang);
glVertex2f(x,y);

}
glEnd();

glColor3f(1,0,0);

GLUquadricObj *pt;
pt=gluNewQuadric();
// esta orden especifica como va a ser renderizado:
gluQuadricDrawStyle(pt,GLU_LINE);
glColor3f (1.0, 0.0, 0.0);
// Dibuja Discos
gluDisk(pt, 0, 9, 15, 6);

glPopMatrix(); // reecupera el estado del matriz


glFlush();
}
LABORATORIO 03

static GLfloat theta[] = {0.0,0.0,0.0}; //Ángulo de giro para eje x, y, z

void girar_objeto_geometrico () //función que se ejecuta de forma indefinida a


través de una función callback
//Recalcula el ángulo de giro

static GLfloat theta[] = {0.0,0.0,0.0}; //Para ejecutar de manera indefinida

void myReshape(int w, int h) //Para mantener la proporcionalidad


*proyección ortográfica
----------------------------------------------------------------------------------------------------------
void cubo(void) //Cubo alámbrico
{
glutWireCube(1);
}
----------------------------------------
void cubo(void) //Cubo sólido
{
glColor3f(1,0,0);
glutSolidCube(1);
glColor3f(0,0,1);
glutWireCube(1); //Borde (Cubo modo alámbrico)
}

También podría gustarte