/* * triangle.c -- A simple example of OpenGL and GLUT. */ #include /******HERE INSERTING EMITSTRING FUNCTION*********/ #define RUL_H 20 #define FONT GLUT_BITMAP_8_BY_13 #define CHAR_W 8 #define CHAR_H 13 #define CHAR_DESCENT 3 #define LINE_SEP 2 #define CARRIAGE_RETURN 13 #define BACK_SPACE 8 static int toggle = 1; /* emitString(s, x, y) -- displays string s at location x,y */ void emitString(char *s, int tx, int ty) { int x,y; x = tx; y = ty; while( *s ) { if( *s == CARRIAGE_RETURN ) { x = tx; y += CHAR_H + LINE_SEP; } else { glRasterPos2i(x,y); glutBitmapCharacter(FONT,*s); x += CHAR_W; } ++s; } } void drawDisk() { GLUquadricObj *qobj; GLdouble innerRadius = 0; GLdouble outerRadius = 100; GLint slices = 30; GLint loops = 2; // glColor3f(1, 0, 0); qobj = gluNewQuadric(); gluDisk(qobj, innerRadius, outerRadius, slices, loops); } /************************************************/ void displayCB(void) /* function called whenever redisplay needed */ { glClear(GL_COLOR_BUFFER_BIT); /* clear the display */ glColor3f(1.0, 1.0, 1.0); /* set current color to white */ glBegin(GL_POLYGON); /* draw filled triangle */ glVertex2i(200,125); /* specify each vertex of triangle */ glVertex2i(100,375); glVertex2i(300,375); glEnd(); /* OpenGL draws the filled triangle */ glColor3f(1, 0, 0); // emitString("Hello! I am an example!",100,250); if(toggle) { glPushMatrix(); glTranslatef(200, 200, 0); drawDisk(); glPopMatrix(); } glFlush(); /* Complete any pending operations */ } void keyCB(unsigned char key, int x, int y) /* called on key press */ { if( key == 'q' ) exit(0); else if(key == 't') { toggle = !(toggle); glutPostRedisplay(); } } int main(int argc, char *argv[]) { int win; glutInit(&argc, argv); /* initialize GLUT system */ glutInitDisplayMode(GLUT_RGB); glutInitWindowSize(400,500); /* width=400pixels height=500pixels */ win = glutCreateWindow("Triangle"); /* create window */ /* from this point on the current window is win */ glClearColor(0.0,0.0,0.0,0.0); /* set background to black */ gluOrtho2D(0,400,0,500); /* how object is mapped to window */ //ortho2(XMIN - 0.5, XMAX + 0.5, YMIN - 0.5, YMAX + 0.5); glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(keyCB); /* set window's key callback */ glutMainLoop(); /* start processing events... */ /* execution never reaches this point */ return 0; }