#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
float r=1,g=0,b=0;
float dx,dy;
int lado=20,linea=7,inc=1,i;
int ban=1;
int b2 = 0;
void cuadro(float r, float g, float b)
{
glColor3f(r,g,b);
glEnable( GL_LINE_SMOOTH );
glBegin( GL_POLYGON);
glVertex2f(6,3);glVertex2f(3, 3);
glVertex2f(3,6);glVertex2f(6,6);
glEnd();
}
void cuadrof(float r, float g, float b)
{
glColor3f(r,g,b);
glEnable( GL_LINE_SMOOTH );
glBegin(GL_LINE_LOOP);
glVertex2f(6,3);glVertex2f(3,3);
glVertex2f(3,6);glVertex2f(6,6);
glEnd();
}
void display(void)
{
// ban=1;
glClear( GL_COLOR_BUFFER_BIT );
glEnable( GL_LINE_SMOOTH );
if(ban==1){
cuadro(r,g,b);
}else
{
cuadrof(r,g,b);
}
glFlush();
}
void key(unsigned char c, int x, int y)
{
if (c == 27) {
exit(0);
}if(c == 'a')
{
r=0;
g=0;
b=1;
} else if(c == 'v')
{
r=0;
g=1;
b=0;
}else if(c == 'r')
{
r=1;
g=0;
b=0;
}else if(c='w'){
if( ban == 1 )
ban=0;
else
ban = 1;
}
glutPostRedisplay();
//glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv); // Inicializa la libreria GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(550,550); // Inicializa el tamaño de la ventana
glutInitWindowPosition(100,50); // posicion de la ventana
glutCreateWindow("CuadroFrame"); // crea la ventana
glClearColor( 1, 1, 1, 0);
gluOrtho2D( 0, 9, 9, 0 );
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMainLoop();
return EXIT_SUCCESS;
}
Ejercicio 2:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795
float r, g, b, y;
int ancho = 600, alto = 300, linea = 6, inc = 1;
void funcionseno(float r,float g, float b)
{
glLineWidth(linea);
glBegin( GL_LINE_STRIP );
glColor3f(r,g,b);
//glVertex2f(0,0);
for( float i = -3.005*PI; i<= 3.005*PI; i = i + PI/20 )
{
y = 2*sin(i);
//x = i;
glVertex2f( i,y);
}
glEnd();
}
void funcioncoseno(float r,float g, float b)
{
glLineWidth(linea/3);
glBegin( GL_LINE_STRIP );
glColor3f(r,g,b);
for( float i = -3.005*PI; i<= 3.005*PI; i = i + PI/20 )
{
y = 2*cos(i);
//x = i;
glVertex2f( i,y);
}
glEnd();
}
void referencia(float r, float g, float b)
{
glLineWidth(linea/4); //ANCHO DE LINEA
glColor3f(r, g, b);
glBegin(GL_LINES);
glVertex2f(-1000,0);glVertex2f(1000,0);// EN X
glVertex2f(0,-1000);glVertex2f(0,1000);//EN Y
glEnd();
//glLineWidth(linea);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
referencia(0,0,0);
glPushMatrix();
glScalef( 30.0, 30.0, 1.0 );
funcionseno(1,0,0);
funcioncoseno(0,1,0);
glPopMatrix();
glFlush();
}
void Init()
{ glClearColor(1.0,1.0,1.0,0);
gluOrtho2D( -ancho/2, ancho/2, -alto/2, alto/2 );
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize( ancho, alto);
glutCreateWindow("Graficas");
Init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Ejercicio 3:
Versión 1:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
float r = 0.5, g = 0.5, b = 0.5;
int ancho = 600, alto=600;
int tam_px = 10;
int matrizPuntos[1000][2];
int i = 0;
int clics = 0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(tam_px);
glColor3f(r,g,b);
glBegin( GL_LINE_STRIP );
if( clics >= 2 )
{
int j;
for( j = 0; j < clics; j++ )
{
glVertex2f( matrizPuntos[j][0], matrizPuntos[j][1] );
}
}
glEnd();
glFlush();
}
void mouse(int boton, int estado, int x, int y)
{
if ( boton == GLUT_LEFT_BUTTON && estado == GLUT_DOWN ) // BOTON IZQ y el estado es presionado
{
clics++;
matrizPuntos[i][0] = x;
matrizPuntos[i][1] = y;
i++;
}
glutPostRedisplay();
}
void miInicializacion()
{ glClearColor( 1.0, 1.0, 1.0,0);
gluOrtho2D( 0, ancho, alto, 0 );
glEnable(GL_POINT_SMOOTH);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(ancho,alto);
glutCreateWindow("Dibujo a mano alzada");
miInicializacion();
glClear(GL_COLOR_BUFFER_BIT);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
Versión 2:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
float r = 0.5, g = 0.5, b = 0.5;
int ancho = 600, alto=600;
int tam_px = 10;
int matrizPuntos[60000][2];
int i = 0;
int clics = 0;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(tam_px);
glColor3f(r,g,b);
glBegin( GL_LINE_STRIP );
if( i >= 2 )
{
int j;
for( j = 0; j < i; j++ )
{
glVertex2f( matrizPuntos[j][0], matrizPuntos[j][1] );
}
}
glEnd();
glFlush();
}
void mouse( int x, int y)
{
matrizPuntos[i][0] = x;
matrizPuntos[i][1] = y;
i++;
//printf( "x: %d, y: %d, iii:%d ", x, y, i );
glutPostRedisplay();
}
void miInicializacion()
{ glClearColor( 1.0, 1.0, 1.0,0);
gluOrtho2D( 0, ancho, alto, 0 );
glEnable(GL_POINT_SMOOTH);
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutInitWindowSize(ancho,alto);
glutCreateWindow("Dibujo a mano alzada");
miInicializacion();
glClear(GL_COLOR_BUFFER_BIT);
glutDisplayFunc(display);
glutPassiveMotionFunc(mouse);
glutMainLoop();
return 0;
}




No hay comentarios.:
Publicar un comentario