Академический Документы
Профессиональный Документы
Культура Документы
void display()
{
glClearColor(1,1,0,0); //Color de pantalla
glClear(GL_COLOR_BUFFER_BIT);//limpia la pantalla
glColor3f(1,0,0); //Color de la pluma
//Pintar el Punto
glPointSize(7); //tamaño del punto
glBegin(GL_POINTS);
glVertex2f(.1,.6);
glVertex2f(0,0);
glEnd();
glFlush(); // Refuerzo de pintado
}
void main()
{
Ejmplo 2:
/* OpenGL(R) es una marca registrada de Silicon Graphics, Inc. */
/*
* helloOpenGL.c
Éste es un ejemplo basico de un progama OpenGL
*/
#include<GL/glut.h>
Graficación-06 1
void display(void)
{
/* Limpia Todos los pixeles */
glClear (GL_COLOR_BUFFER_BIT);
/* don't wait!
* inicia procesamiento de las Rutinas OpenGL
*/
glFlush ();
}
/*
* Declara el tamaño de la ventana Inicial, posicion y modo de
despliegue
* (single buffer and RGBA). Abre una ventan con "Hello" en su barra
de
* titulo. Llama a la rutinas de inicializacion.
* Resgistra las funciones para desplegado gráfico.
* Entra a programa prinicipal (loop) y procesa los eventos
*
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requiere que main retorne un int. */
}
dx = x2 - x1;
dy = y2 - y1;
Graficación-06 3
}
else e += inc2;
y += incy;
draw_pixel(x,y, BLACK);
}
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
bres(200, 200, 100, 100);
glFlush();
}
void myinit()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 499.0, 0.0, 499.0);
}
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500); /* ventana 500x500 pixeles */
glutInitWindowPosition(0,0); /* coloca la ventana de despliegue en
esq. sup. izq */
glutCreateWindow("Bresenham's Algorithm"); /* título de la
ventana*/
glutDisplayFunc(display); /*llama a la funcion display cuando se
abre la ventana */
#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void init(void){
glClearColor(1.0,1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,200.0,0.0,150.0);
}
Graficación-06 4
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void Circle(){
int xCenter=100,yCenter=100,r=50;
int x=0,y=r;
int d=3-(2*r);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0.5);
while(x<=y){
setPixel(xCenter+x,yCenter+y);
setPixel(xCenter+y,yCenter+x);
setPixel(xCenter-x,yCenter+y);
setPixel(xCenter+y,yCenter-x);
setPixel(xCenter-x,yCenter-y);
setPixel(xCenter-y,yCenter-x);
setPixel(xCenter+x,yCenter-y);
setPixel(xCenter-y,yCenter+x);
if (d<0)
d += (4*x)+6;
else
{
d += (4*(x-y))+10;
y -= 1;
}
x++;
glFlush();
Graficación-06 5
EJERCICICIOS:
1) Elabore un programa para pintar en la pantalla el siguiente dibujo con OpenGL. Para
pintar las líneas utilice el algoritmo de Bresenham y el del sistema.
2.) Implemente los dos algoritmos restantes para pintar circulos, vistos en clases.
Graficación-06 6