Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Points and Point Size

 

#include "stdafx.h"

#include <GL/glut.h>

 

void init(void)

{

   glClearColor (0.0, 0.0, 0.0, 0.0);     //set background color to black

   glShadeModel (GL_FLAT);

}

 

void display(void)

{

   glClear (GL_COLOR_BUFFER_BIT);

   glColor3f (1.0, 1.0, 1.0);     //set line color to white

 

   glTranslatef(10.0f, 10.0f, 0.0f);   //translate the origin

 

   glLineWidth(20.f);   //set width of line, cannot go between begin and end

   glPointSize(20.0f);  //set size of point, cannot go between begin and end

 

   glBegin(GL_LINES);

     glVertex2f(0.0f, 0.0f);

     glVertex2f(0.0f, 450.0f);

     glVertex2f(0.0f, 0.0f);

       glVertex2f(450.0f, 0.0f);

   glEnd();

 

  //following line is for "anti aliasing" otherwise get a square.  Details covered later

  glEnable(GL_POINT_SMOOTH);

 

  glColor3f (1.0, 0.0, 1.0);     //set point color to red

  glBegin(GL_POINTS);

      glVertex3f(200.0f, 200.0f, 0.0f);

  glEnd( );

  glLoadIdentity ();     //clear the slate

  glFlush ();            //causes execution

}

void reshape (int w, int h)                                         //This very important function will be covered later - many variations

{

    glViewport (0, 0, (GLsizei) w, (GLsizei) h);

    glMatrixMode (GL_PROJECTION);

    glLoadIdentity ();

    gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);

}

int main(int argc, char** argv)

{

   glutInit(&argc, argv);

   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

   glutInitWindowSize (500, 500);

   glutInitWindowPosition (100, 100);

   glutCreateWindow ("Translation, Lines, Points, Point Size and Line Width");

   init ();

   glutDisplayFunc(display);

   glutReshapeFunc(reshape);

   glutMainLoop();

   return 0;

}