viewing paste Unknown #11113 | Plain text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
/*
 * Copyright (c) 2009 University of Michigan, Ann Arbor.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the University of Michigan, Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Authors: Manoj Rajagopalan, Sugih Jamin
*/
#include <stdio.h>
#include <stdlib.h>
 
#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
 
#define NENDS 2           /* number of end "points" to draw */
 
GLdouble width, height;   /* window width and height */
int wd;                   /* GLUT window handle */
int ends[NENDS][2];       /* array of 2D points */
 
/* Program initialization NOT OpenGL/GLUT dependent,
   as we haven't created a GLUT window yet */
void
init(void)
{
  width  = 1280.0;                 /* initial window width and height, */
  height = 800.0;                  /* within which we draw. */
  ends[0][0] = (int)(0.25*width);  /* (0,0) is the lower left corner */
  ends[0][1] = (int)(0.75*height);
  ends[1][0] = (int)(0.75*width);
  ends[1][1] = (int)(0.25*height);
}
 
/* Callback functions for GLUT */
 
/* Draw the window - this is where all the GL actions are */
void
display(void)
{
  int i;
 
  /* clear the screen to white */
  glClearColor(1.0, 1.0, 1.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
 
  /* draw a black line */
  glColor3f(0.0, 0.0, 0.0);
  glLineWidth(5.0);
  glBegin(GL_LINES);
 
  glVertex2i(100,300);
  glVertex2i(100,600);
  glVertex2i(100,600);
  glVertex2i(250,600);
  glVertex2i(100,300);
  glVertex2i(250,300);
 
  glVertex2i(300,300);
  glVertex2i(300,600);
  glVertex2i(300,450);
  glVertex2i(500,450);
  glVertex2i(500,300);
  glVertex2i(500,600);
 
  glVertex2i(550,300);
  glVertex2i(550,600);
  glVertex2i(550,300);
  glVertex2i(750,300);
  glVertex2i(750,300);
  glVertex2i(750,600);
 
  glVertex2i(800,300);
  glVertex2i(1000,300);
  glVertex2i(800,300);
  glVertex2i(800,350);
  glVertex2i(1000,300);
  glVertex2i(1000,600);
  glVertex2i(800,600);
  glVertex2i(1000,600);
  glEnd();
  glFlush();
}
 
/* Called when window is resized,
   also when window is first created,
   before the first call to display(). */
void
reshape(int w, int h)
{
  /* save new screen dimensions */
  width = (GLdouble) w;
  height = (GLdouble) h;
 
  /* tell OpenGL to use the whole window for drawing */
  glViewport(0, 0, (GLsizei) width, (GLsizei) height);
 
  /* do an orthographic parallel projection with the coordinate
     system set to first quadrant, limited by screen/window size */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(0.0, width, 0.0, height);
}
 
int
main(int argc, char *argv[])
{
  /* perform initialization NOT OpenGL/GLUT dependent,
     as we haven't created a GLUT window yet */
  init();
 
  /* initialize GLUT, let it extract command-line
     GLUT options that you may provide
     - NOTE THE '&' BEFORE argc */
  glutInit(&argc, argv);
 
  /* specify the display to be single
     buffered and color as RGBA values */
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
 
  /* set the initial window size */
  glutInitWindowSize((int) width, (int) height);
 
  /* create the window and store the handle to it */
  wd = glutCreateWindow("Experiment with line drawing" /* title */ );
 
  /* --- register callbacks with GLUT --- */
 
  /* register function to handle window resizes */
  glutReshapeFunc(reshape);
 
  /* register function that draws in the window */
  glutDisplayFunc(display);
 
  /* start the GLUT main loop */
  glutMainLoop();
 
  return 0;
}
Viewed 445 times, submitted by unknown.