martes, 18 de febrero de 2014

Lines Matrix and points Matrix with OpenGL(GLUT)

Matriz De Lineas
Código fuente:
/*
 * GLUT Shapes Demo
 *
 * Written by Nigel Stewart November 2003
 *
 * This program is test harness for the sphere, cone
 * and torus shapes in GLUT.
 *
 * Spinning wireframe and smooth shaded shapes are
 * displayed until the ESC or q key is pressed.  The
 * number of geometry stacks and slices can be adjusted
 * using the + and - keys.
 */

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glut.h>
#endif

#include <stdlib.h>



static void display(void)
{
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glClear(GL_COLOR_BUFFER_BIT);
 glPointSize(10);
 glLineWidth(5);
 glColor3f(1.0,0.0,0.0);
 glBegin(GL_LINES);


    for(double i=-1;i<=1;i+=0.1)
      {
        glVertex2d(-1,-i);
        glVertex2d(1,-i);
        glVertex2d(i,-1);
        glVertex2d(i,1);
      }
     glEnd();
     glFlush();

}

int main(int argc, char *argv[])
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(300,300);
  glutInitWindowPosition(0,0);
  glutCreateWindow("Matriz de Lineas");
  glutDisplayFunc(display);
  glutMainLoop();
}

Resultado:

Matriz de Puntos 
Código Fuente:

/*
 * GLUT Shapes Demo
 *
 * Written by Nigel Stewart November 2003
 *
 * This program is test harness for the sphere, cone
 * and torus shapes in GLUT.
 *
 * Spinning wireframe and smooth shaded shapes are
 * displayed until the ESC or q key is pressed.  The
 * number of geometry stacks and slices can be adjusted
 * using the + and - keys.
 */

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glut.h>
#endif

#include <stdlib.h>



static void display(void)
{
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glClear(GL_COLOR_BUFFER_BIT);
 glPointSize(10);
 glLineWidth(5);
 glColor3f(1.0,0.0,0.0);
 glBegin(GL_POINTS);


    for(double x=-1; x<=1;x+=0.1)
    {
        for(double y=1;y>=-1;y-=0.1)
        {

            glVertex2f(x,y);
        }

    }

     glEnd();
     glFlush();

}


int main(int argc, char *argv[])
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(300,300);
  glutInitWindowPosition(0,0);
  glutCreateWindow("Matriz de Puntos");
  glutDisplayFunc(display);
  glutMainLoop();
}

Resultado:

No hay comentarios:

Publicar un comentario