From 2c19c071ad9698cbedf3368576cfd80953809938 Mon Sep 17 00:00:00 2001 From: Luke Holden Date: Wed, 27 Nov 2002 05:54:27 +0000 Subject: [PATCH] GLU: Added full quadrics support (except gluQuadricCallback) Quadrics.java: port of NeHe lesson18: Quadrics --- src/java/org/lwjgl/opengl/GLU.java | 208 +++++++++++++++++++++ src/native/common/org_lwjgl_opengl_GLU.cpp | 110 +++++++++++ src/native/common/org_lwjgl_opengl_GLU.h | 83 ++++++++ 3 files changed, 401 insertions(+) diff --git a/src/java/org/lwjgl/opengl/GLU.java b/src/java/org/lwjgl/opengl/GLU.java index 54044d83..84f14140 100644 --- a/src/java/org/lwjgl/opengl/GLU.java +++ b/src/java/org/lwjgl/opengl/GLU.java @@ -144,5 +144,213 @@ public class GLU implements GLUConstants { int type, int data /*void*/ ); + + /** + * creates and returns a pointer to a new quadrics object. This + * object must be referred to when calling quadrics rendering and control + * functions. A return value of zero means that there is not enough memory to + * allocate the object + * + * @returns adress to a new quadrics object + */ + public native int newQuadric(); + + /** + * draws a cylinder oriented along the z axis. The base of the + * cylinder is placed at z = 0, and the top at z=height. Like a sphere, a + * cylinder is subdivided around the z axis into slices, and along the z axis + * into stacks. + * + * Note that if topRadius is set to zero, then this routine will generate a + * cone. + * + * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then + * any generated normals point away from the z axis. Otherwise, they point + * toward the z axis. + * + * If texturing is turned on (with glu.quadricTexture), then texture + * coordinates are generated so that t ranges linearly from 0.0 at z = 0 to + * 1.0 at z = height, and s ranges from 0.0 at the +y axis, to 0.25 at the +x + * axis, to 0.5 at the -y axis, to 0.75 at the -x axis, and back to 1.0 at the + * +y axis. + * + * @param qobj Specifies the quadrics object (created with glu.newQuadric). + * + * @param baseRadius Specifies the radius of the cylinder at z = 0. + * + * @param topRadius Specifies the radius of the cylinder at z = height. + * + * @param height Specifies the height of the cylinder. + * + * @param slices Specifies the number of subdivisions around the z axis. + * + * @param stacks Specifies the number of subdivisions along the z axis. + */ + public native void cylinder( + int qobj, + double baseRadius, + double topRadius, + double height, + int slices, + int stacks + ); + + /** + * destroys the quadrics object and frees any memory used by + * it. Once glu.deleteQuadric has been called, the object cannot be used again. + * + * @param qobj pecifies the quadrics object to be destroyed (created with + * glu.newQuadric). + */ + public native void deleteQuadric( + int qobj + ); + + + /** + * renders a disk on the z = 0 plane. The disk has a radius of + * outerRadius, and contains a concentric circular hole with a radius of + * innerRadius. If innerRadius is 0, then no hole is generated. The disk is + * subdivided around the z axis into slices (like pizza slices), and also + * about the z axis into rings (as specified by slices and loops, + * respectively). + * + * With respect to orientation, the +z side of the disk is considered to be + * "outside" (see glu.quadricOrientation). This means that if the orientation + * is set to GLU.OUTSIDE, then any normals generated point along the +z axis. + * Otherwise, they point along the -z axis. + * + * If texturing is turned on (with glu.quadricTexture), texture coordinates are + * generated linearly such that where r=outerRadius, the value at (r, 0, 0) is + * (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), and at + * (0, -r, 0) it is (0.5, 0). + */ + public native void disk( + int target, + double innerRadius, + double outerRadius, + int slices, + int loops + ); + /** + * renders a partial disk on the z=0 plane. A partial disk is + * similar to a full disk, except that only the subset of the disk from + * startAngle through startAngle + sweepAngle is included (where 0 degrees is + * along the +y axis, 90 degrees along the +x axis, 180 along the -y axis, and + * 270 along the -x axis). + * + * The partial disk has a radius of outerRadius, and contains a concentric + * circular hole with a radius of innerRadius. If innerRadius is zero, then + * no hole is generated. The partial disk is subdivided around the z axis + * into slices (like pizza slices), and also about the z axis into rings (as + * specified by slices and loops, respectively). + * + * With respect to orientation, the +z side of the partial disk is considered + * to be outside (see gluQuadricOrientation). This means that if the + * orientation is set to GLU_OUTSIDE, then any normals generated point along + * the +z axis. Otherwise, they point along the -z axis. + * + * If texturing is turned on (with gluQuadricTexture), texture coordinates are + * generated linearly such that where r=outerRadius, the value at (r, 0, 0) is + * (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), and at + * (0, -r, 0) it is (0.5, 0). + */ + public native void partialDisk( + int target, + double innerRadius, + double outerRadius, + int slices, + int loops, + double startAngle, + double sweepAngle + ); + + /** + * specifies the draw style for quadrics rendered with + * qobj. The legal values are as follows: + * + * GLU.FILL: Quadrics are rendered with polygon primitives. The polygons + * are drawn in a counterclockwise fashion with respect to + * their normals (as defined with glu.quadricOrientation). + * + * GLU.LINE: Quadrics are rendered as a set of lines. + * + * GLU.SILHOUETTE: Quadrics are rendered as a set of lines, except that edges + * separating coplanar faces will not be drawn. + * + * GLU.POINT: Quadrics are rendered as a set of points. + */ + public native void quadricDrawStyle( + int target, + int drawStyle + ); + + /** + * specifies what kind of normals are desired for quadrics + * rendered with qobj. The legal values are as follows: + * + * GLU.NONE: No normals are generated. + * + * GLU.FLAT: One normal is generated for every facet of a quadric. + * + * GLU.SMOOTH: One normal is generated for every vertex of a quadric. This + * is the default. + */ + public native void quadricNormals( + int target, + int normals + ); + + /** + * specifies what kind of orientation is desired for + * quadrics rendered with qobj. The orientation values are as follows: + * + * GLU.OUTSIDE: Quadrics are drawn with normals pointing outward. + * + * GLU.INSIDE: Normals point inward. The default is GLU.OUTSIDE. + * + * Note that the interpretation of outward and inward depends on the quadric + * being drawn. + */ + public native void quadricOrientation( + int target, + int orientation + ); + + /** + * specifies if texture coordinates should be generated for + * quadrics rendered with qobj. If the value of textureCoords is true, + * then texture coordinates are generated, and if textureCoords is false, + * they are not.. The default is false. + * + * The manner in which texture coordinates are generated depends upon the + * specific quadric rendered. + */ + public native void quadricTexture( + int target, + boolean textureCoords + ); + + /** + * draws a sphere of the given radius centered around the origin. + * The sphere is subdivided around the z axis into slices and along the z axis + * into stacks (similar to lines of longitude and latitude). + * + * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then + * any normals generated point away from the center of the sphere. Otherwise, + * they point toward the center of the sphere. + + * If texturing is turned on (with glu.quadricTexture), then texture + * coordinates are generated so that t ranges from 0.0 at z=-radius to 1.0 at + * z=radius (t increases linearly along longitudinal lines), and s ranges from + * 0.0 at the +y axis, to 0.25 at the +x axis, to 0.5 at the -y axis, to 0.75 + * at the -x axis, and back to 1.0 at the +y axis. + */ + public native void sphere( + int target, + double radius, + int slices, + int stacks + ); } diff --git a/src/native/common/org_lwjgl_opengl_GLU.cpp b/src/native/common/org_lwjgl_opengl_GLU.cpp index 53b4244e..46d34ef1 100644 --- a/src/native/common/org_lwjgl_opengl_GLU.cpp +++ b/src/native/common/org_lwjgl_opengl_GLU.cpp @@ -165,3 +165,113 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLU_build2DMipmaps(JNIEnv * env, jo return ret; } +/* + * Class: org_lwjgl_opengl_GLU + * Method: newQuadric + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLU_newQuadric(JNIEnv * env, jobject obj) +{ + jint ret = (jint) gluNewQuadric(); + CHECK_GL_ERROR + return ret; +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: cylinder + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_cylinder(JNIEnv * env, jobject obj, jint quad, jdouble baseRadius, jdouble topRadius, jdouble height, jint slices, jint stacks) +{ + gluCylinder((GLUquadricObj *) quad, (GLdouble) baseRadius, (GLdouble) topRadius, (GLdouble) height, (GLint) slices, (GLint) stacks); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: deleteQuadric + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_deleteQuadric(JNIEnv * env, jobject obj, jint quad) +{ + gluDeleteQuadric((GLUquadricObj *) quad); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: disk + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_disk + (JNIEnv * env, jobject obj, jint quad, jdouble innerRadius, jdouble outerRadius, jint slices, jint loops) +{ + gluDisk((GLUquadricObj *) quad, (GLdouble) innerRadius, (GLdouble) outerRadius, (GLint) slices, (GLint) loops); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: partialDisk + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_partialDisk + (JNIEnv * env, jobject obj, jint quad, jdouble innerRadius, jdouble outerRadius, + jint slices, jint loops, jdouble startAngle, jdouble sweepAngle) +{ + gluPartialDisk((GLUquadricObj *) quad, (GLdouble) innerRadius, (GLdouble) outerRadius, + (GLint) slices, (GLint) loops, (GLdouble) startAngle, (GLdouble) sweepAngle); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricDrawStyle + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricDrawStyle + (JNIEnv * env, jobject obj, jint quad, jint drawStyle) +{ + gluQuadricDrawStyle((GLUquadricObj *) quad, (GLenum) drawStyle); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricNormals + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricNormals + (JNIEnv * env, jobject obj, jint quad, jint normals) +{ + gluQuadricNormals((GLUquadricObj *) quad, (GLenum) normals); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricOrientation + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricOrientation + (JNIEnv * env, jobject obj, jint quad, jint orientation) +{ + gluQuadricOrientation((GLUquadricObj *) quad, (GLenum) orientation); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricTexture + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricTexture + (JNIEnv * env, jobject obj, jint quad, jboolean textureCoords) +{ + gluQuadricTexture((GLUquadricObj *) quad, (GLboolean) textureCoords); + CHECK_GL_ERROR +} + +/* + * Class: org_lwjgl_opengl_GLU + * Method: sphere + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_sphere + (JNIEnv * env, jobject obj, jint quad, jdouble radius, jint slices, jint stacks) +{ + gluSphere((GLUquadricObj *) quad, (GLdouble) radius, (GLint) slices, (GLint) stacks); + CHECK_GL_ERROR +} + diff --git a/src/native/common/org_lwjgl_opengl_GLU.h b/src/native/common/org_lwjgl_opengl_GLU.h index ba1c21db..c89e8158 100644 --- a/src/native/common/org_lwjgl_opengl_GLU.h +++ b/src/native/common/org_lwjgl_opengl_GLU.h @@ -95,6 +95,89 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLU_build1DMipmaps JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLU_build2DMipmaps (JNIEnv *, jobject, jint, jint, jint, jint, jint, jint, jint); + + + +/* + * Class: org_lwjgl_opengl_GLU + * Method: newQuadric + * not sure exactly what to do with this part... + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GLU_newQuadric + (JNIEnv *, jobject); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: cylinder + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_cylinder + (JNIEnv *, jobject, jint, jdouble, jdouble, jdouble, jint, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: deleteQuadric + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_deleteQuadric + (JNIEnv *, jobject, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: disk + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_disk + (JNIEnv *, jobject, jint, jdouble, jdouble, jint, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: partialDisk + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_partialDisk + (JNIEnv *, jobject, jint, jdouble, jdouble, jint, jint, jdouble, jdouble); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricDrawStyle + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricDrawStyle + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricNormals + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricNormals + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricOrientation + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricOrientation + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricTexture + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricTexture + (JNIEnv *, jobject, jint, jboolean); + +/* + * Class: org_lwjgl_opengl_GLU + * Method: sphere + * not sure exactly what to do with this part... + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_sphere + (JNIEnv *, jobject, jint, jdouble, jint, jint); + #ifdef __cplusplus } #endif