From 3b21507274aa4f98644382903ae529c1fc2c7bd4 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 20 Aug 2014 01:36:33 +1000 Subject: GL3D GWIN window + demo --- 3rdparty/tinygl-0.4-ugfx/examples/glu.c | 261 ++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 3rdparty/tinygl-0.4-ugfx/examples/glu.c (limited to '3rdparty/tinygl-0.4-ugfx/examples/glu.c') diff --git a/3rdparty/tinygl-0.4-ugfx/examples/glu.c b/3rdparty/tinygl-0.4-ugfx/examples/glu.c new file mode 100644 index 00000000..38561e71 --- /dev/null +++ b/3rdparty/tinygl-0.4-ugfx/examples/glu.c @@ -0,0 +1,261 @@ +#include +#include +#include +#include "glu.h" + + +void drawTorus(float rc, int numc, float rt, int numt) +{ + int i, j, k; + double s, t; + double x, y, z; + double pi, twopi; + + pi = 3.14159265358979323846; + twopi = 2 * pi; + + for (i = 0; i < numc; i++) { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) { + for (k = 1; k >= 0; k--) { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = cos(t*twopi/numt) * cos(s*twopi/numc); + y = sin(t*twopi/numt) * cos(s*twopi/numc); + z = sin(s*twopi/numc); + glNormal3f(x, y, z); + + x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt); + y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt); + z = rc * sin(s*twopi/numc); + glVertex3f(x, y, z); + } + } + glEnd(); + } +} + +static void normal3f( GLfloat x, GLfloat y, GLfloat z ) +{ + GLdouble mag; + + mag = sqrt( x*x + y*y + z*z ); + if (mag>0.00001F) { + x /= mag; + y /= mag; + z /= mag; + } + glNormal3f( x, y, z ); +} + +void gluPerspective( GLdouble fovy, GLdouble aspect, + GLdouble zNear, GLdouble zFar ) +{ + GLdouble xmin, xmax, ymin, ymax; + + ymax = zNear * tan( fovy * M_PI / 360.0 ); + ymin = -ymax; + + xmin = ymin * aspect; + xmax = ymax * aspect; + + glFrustum( xmin, xmax, ymin, ymax, zNear, zFar ); +} + +GLUquadricObj *gluNewQuadric(void) +{ + return NULL; +} + +void gluQuadricDrawStyle(GLUquadricObj *obj, int style) +{ +} + +void gluCylinder( GLUquadricObj *qobj, + GLdouble baseRadius, GLdouble topRadius, GLdouble height, + GLint slices, GLint stacks ) +{ + GLdouble da, r, dr, dz; + GLfloat z, nz, nsign; + GLint i, j; + GLfloat du = 1.0 / slices; + GLfloat dv = 1.0 / stacks; + GLfloat tcx = 0.0, tcy = 0.0; + + nsign = 1.0; + + da = 2.0*M_PI / slices; + dr = (topRadius-baseRadius) / stacks; + dz = height / stacks; + nz = (baseRadius-topRadius) / height; /* Z component of normal vectors */ + + for (i=0;i=0;j--) { + theta = (j==slices) ? 0.0 : j * dtheta; + x = -sin(theta) * sin(rho); + y = cos(theta) * sin(rho); + z = nsign * cos(rho); + if (normals) glNormal3f( x*nsign, y*nsign, z*nsign ); + glTexCoord2f(s,1-t); + s -= ds; + glVertex3f( x*radius, y*radius, z*radius ); + } + glEnd(); +} -- cgit v1.2.3