132001f49Smrg/*
232001f49Smrg * Copyright (c) 1993-1997, Silicon Graphics, Inc.
332001f49Smrg * ALL RIGHTS RESERVED
432001f49Smrg * Permission to use, copy, modify, and distribute this software for
532001f49Smrg * any purpose and without fee is hereby granted, provided that the above
632001f49Smrg * copyright notice appear in all copies and that both the copyright notice
732001f49Smrg * and this permission notice appear in supporting documentation, and that
832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising
932001f49Smrg * or publicity pertaining to distribution of the software without specific,
1032001f49Smrg * written prior permission.
1132001f49Smrg *
1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
1632001f49Smrg * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
2432001f49Smrg *
2532001f49Smrg * US Government Users Restricted Rights
2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to
2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software
2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor
3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement.
3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the
3232001f49Smrg * United States.  Contractor/manufacturer is Silicon Graphics,
3332001f49Smrg * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
3432001f49Smrg *
3532001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
3632001f49Smrg */
3732001f49Smrg
3832001f49Smrg/*
3932001f49Smrg *  quadric.c
4032001f49Smrg *  This program demonstrates the use of some of the gluQuadric*
4132001f49Smrg *  routines. Quadric objects are created with some quadric
4232001f49Smrg *  properties and the callback routine to handle errors.
4332001f49Smrg *  Note that the cylinder has no top or bottom and the circle
4432001f49Smrg *  has a hole in it.
4532001f49Smrg */
4632001f49Smrg#include "glut_wrap.h"
4732001f49Smrg#include <stdio.h>
4832001f49Smrg#include <stdlib.h>
4932001f49Smrg
5032001f49SmrgGLuint startList;
5132001f49Smrg
5232001f49Smrgstatic void GLAPIENTRY errorCallback(GLenum errorCode)
5332001f49Smrg{
5432001f49Smrg   const GLubyte *estring;
5532001f49Smrg
5632001f49Smrg   estring = gluErrorString(errorCode);
5732001f49Smrg   fprintf(stderr, "Quadric Error: %s\n", estring);
5832001f49Smrg   exit(0);
5932001f49Smrg}
6032001f49Smrg
6132001f49Smrgstatic void init(void)
6232001f49Smrg{
6332001f49Smrg   GLUquadricObj *qobj;
6432001f49Smrg   GLfloat mat_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
6532001f49Smrg   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
6632001f49Smrg   GLfloat mat_shininess[] = { 50.0 };
6732001f49Smrg   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
6832001f49Smrg   GLfloat model_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
6932001f49Smrg
7032001f49Smrg   glClearColor(0.0, 0.0, 0.0, 0.0);
7132001f49Smrg
7232001f49Smrg   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
7332001f49Smrg   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
7432001f49Smrg   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
7532001f49Smrg   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
7632001f49Smrg   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
7732001f49Smrg
7832001f49Smrg   glEnable(GL_LIGHTING);
7932001f49Smrg   glEnable(GL_LIGHT0);
8032001f49Smrg   glEnable(GL_DEPTH_TEST);
8132001f49Smrg
8232001f49Smrg/*  Create 4 display lists, each with a different quadric object.
8332001f49Smrg *  Different drawing styles and surface normal specifications
8432001f49Smrg *  are demonstrated.
8532001f49Smrg */
8632001f49Smrg   startList = glGenLists(4);
8732001f49Smrg   qobj = gluNewQuadric();
8832001f49Smrg   gluQuadricCallback(qobj, GLU_ERROR, errorCallback);
8932001f49Smrg
9032001f49Smrg   gluQuadricDrawStyle(qobj, GLU_FILL); /* smooth shaded */
9132001f49Smrg   gluQuadricNormals(qobj, GLU_SMOOTH);
9232001f49Smrg   glNewList(startList, GL_COMPILE);
9332001f49Smrg      gluSphere(qobj, 0.75, 15, 10);
9432001f49Smrg   glEndList();
9532001f49Smrg
9632001f49Smrg   gluQuadricDrawStyle(qobj, GLU_FILL); /* flat shaded */
9732001f49Smrg   gluQuadricNormals(qobj, GLU_FLAT);
9832001f49Smrg   glNewList(startList+1, GL_COMPILE);
9932001f49Smrg      gluCylinder(qobj, 0.5, 0.3, 1.0, 15, 5);
10032001f49Smrg   glEndList();
10132001f49Smrg
10232001f49Smrg   gluQuadricDrawStyle(qobj, GLU_LINE); /* all polygons wireframe */
10332001f49Smrg   gluQuadricNormals(qobj, GLU_NONE);
10432001f49Smrg   glNewList(startList+2, GL_COMPILE);
10532001f49Smrg      gluDisk(qobj, 0.25, 1.0, 20, 4);
10632001f49Smrg   glEndList();
10732001f49Smrg
10832001f49Smrg   gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); /* boundary only  */
10932001f49Smrg   gluQuadricNormals(qobj, GLU_NONE);
11032001f49Smrg   glNewList(startList+3, GL_COMPILE);
11132001f49Smrg      gluPartialDisk(qobj, 0.0, 1.0, 20, 4, 0.0, 225.0);
11232001f49Smrg   glEndList();
11332001f49Smrg
11432001f49Smrg   gluDeleteQuadric(qobj);
11532001f49Smrg}
11632001f49Smrg
11732001f49Smrgstatic void display(void)
11832001f49Smrg{
11932001f49Smrg   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
12032001f49Smrg   glPushMatrix();
12132001f49Smrg
12232001f49Smrg   glEnable(GL_LIGHTING);
12332001f49Smrg   glShadeModel (GL_SMOOTH);
12432001f49Smrg   glTranslatef(-1.0, -1.0, 0.0);
12532001f49Smrg   glCallList(startList);
12632001f49Smrg
12732001f49Smrg   glShadeModel (GL_FLAT);
12832001f49Smrg   glTranslatef(0.0, 2.0, 0.0);
12932001f49Smrg   glPushMatrix();
13032001f49Smrg   glRotatef(300.0, 1.0, 0.0, 0.0);
13132001f49Smrg   glCallList(startList+1);
13232001f49Smrg   glPopMatrix();
13332001f49Smrg
13432001f49Smrg   glDisable(GL_LIGHTING);
13532001f49Smrg   glColor3f(0.0, 1.0, 1.0);
13632001f49Smrg   glTranslatef(2.0, -2.0, 0.0);
13732001f49Smrg   glCallList(startList+2);
13832001f49Smrg
13932001f49Smrg   glColor3f(1.0, 1.0, 0.0);
14032001f49Smrg   glTranslatef(0.0, 2.0, 0.0);
14132001f49Smrg   glCallList(startList+3);
14232001f49Smrg
14332001f49Smrg   glPopMatrix();
14432001f49Smrg   glFlush();
14532001f49Smrg}
14632001f49Smrg
14732001f49Smrgstatic void reshape (int w, int h)
14832001f49Smrg{
14932001f49Smrg   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
15032001f49Smrg   glMatrixMode(GL_PROJECTION);
15132001f49Smrg   glLoadIdentity();
15232001f49Smrg   if (w <= h)
15332001f49Smrg      glOrtho(-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w,
15432001f49Smrg         2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
15532001f49Smrg   else
15632001f49Smrg      glOrtho(-2.5*(GLfloat)w/(GLfloat)h,
15732001f49Smrg         2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0);
15832001f49Smrg   glMatrixMode(GL_MODELVIEW);
15932001f49Smrg   glLoadIdentity();
16032001f49Smrg}
16132001f49Smrg
16232001f49Smrg/* ARGSUSED1 */
16332001f49Smrgstatic void keyboard(unsigned char key, int x, int y)
16432001f49Smrg{
16532001f49Smrg   switch (key) {
16632001f49Smrg      case 27:
16732001f49Smrg         exit(0);
16832001f49Smrg         break;
16932001f49Smrg   }
17032001f49Smrg}
17132001f49Smrg
17232001f49Smrgint main(int argc, char** argv)
17332001f49Smrg{
17432001f49Smrg   glutInit(&argc, argv);
17532001f49Smrg   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
17632001f49Smrg   glutInitWindowSize(500, 500);
17732001f49Smrg   glutInitWindowPosition(100, 100);
17832001f49Smrg   glutCreateWindow(argv[0]);
17932001f49Smrg   init();
18032001f49Smrg   glutDisplayFunc(display);
18132001f49Smrg   glutReshapeFunc(reshape);
18232001f49Smrg   glutKeyboardFunc(keyboard);
18332001f49Smrg   glutMainLoop();
18432001f49Smrg   return 0;
18532001f49Smrg}
186