OpenGL-Simple
view release on metacpan or search on metacpan
void glFinish();
void glFlush();
void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
void glClear(GLbitfield mask);
void glClearDepth(GLclampd depth);
void glClipPlane(...)
PREINIT:
GLenum plane;
GLdouble equation[4];
CODE:
if ((2==items)
&& (SvROK(ST(1))
&& (SVt_PVAV == SvTYPE(SvRV(ST(1)))))
) {
/* Two items, of which the second is an array ref. */
AV *array;
int i;
array =(AV *) SvRV(ST(1));
if (3!=av_len(array)) {
croak("glClipPlane($scalar,\\@array)"
"should be passed an array of "
"exactly 4 elements, not %d.",
1+av_len(array));
}
plane = (GLenum) SvIV(ST(0));
for (i=0;i<4;i++) {
SV **svp;
svp = av_fetch(array,i,0);
equation[i] = (GLdouble) SvNV(*svp);
}
} else if (5==items) {
/* assume args are (plane,a,b,c,d). */
int i;
plane = (GLenum) SvIV(ST(0));
for (i=0;i<4;i++) {
equation[i] = (GLdouble) SvNV(ST(1+i));
}
} else {
croak("Usage: glClipPlane($plane,\\@equation)");
}
/* plane and equation[] are defined. */
glClipPlane(plane,equation);
void glGetClipPlane(...)
PREINIT:
GLdouble equation[4];
int i;
PPCODE:
if (1==items) {
/* Dump everything on the stack */
glGetClipPlane(SvIV(ST(0)),equation);
EXTEND(sp,4);
for (i=0;i<4;i++) {
PUSHs(sv_2mortal(newSVnv(equation[i])));
}
} else if (2==items) {
/* Write through supplied array reference */
if ( (SvROK(ST(1)))
&&(SVt_PVAV==SvTYPE(SvRV(ST(1))))
) {
AV *array=(AV *)SvRV(ST(1));
glGetClipPlane(SvIV(ST(0)),equation);
for (i=0;i<4;i++) {
av_store(array,i,newSVnv(equation[i]));
}
}
} else {
/* Your what's itchy? */
croak("glGetClipPlane() takes either one or two arguments.");
}
void glLoadIdentity();
void glMatrixMode(GLenum mode);
void glLoadMatrix(...)
PREINIT:
GLdouble m[16];
int i;
CODE:
if (16!=items) {
croak("glMatrixMode takes a 16-element array");
} else {
/* Copy arguments into matrix */
for (i=0;i<16;i++) { m[i] = SvNV(ST(i)); }
glLoadMatrixd(m);
}
void glMultMatrix(...)
PREINIT:
GLdouble m[16];
int i;
CODE:
if (16!=items) {
croak( "glMultMatrix takes a 16-element array");
} else {
/* Copy arguments into matrix */
for (i=0;i<16;i++) { m[i] = SvNV(ST(i)); }
glMultMatrixd(m);
}
for (i=0;i<3;i++) { a[i] = SvNV(ST(i+2)); }
glLightfv(light,pname,a);
break;
case GL_SPOT_EXPONENT:
case GL_SPOT_CUTOFF:
case GL_CONSTANT_ATTENUATION:
case GL_LINEAR_ATTENUATION:
case GL_QUADRATIC_ATTENUATION:
/* Just the one argument */
glLightf(light,pname,SvNV(ST(2)));
break;
default:
croak("Bad pname passed to glLight()");
}
void glShadeModel(GLenum mode);
void glCullFace(GLenum mode);
void glDepthFunc(GLenum func);
void glDepthMask(GLboolean flag);
void glDepthRange(GLclampd near, GLclampd far);
void glColorMask( GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha );
void glPolygonMode( GLenum face, GLenum mode );
void glPolygonOffset( GLfloat factor, GLfloat units );
void glViewport( GLint x, GLint y, GLsizei width, GLsizei height );
void glBlendFunc( GLenum sfactor, GLenum dfactor);
void glHint(GLenum target, GLenum mode);
void glLineWidth(GLfloat width);
void glLineStipple(GLint factor, GLushort pattern);
void glPointSize( GLfloat size );
void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar );
void glFrustum(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,GLdouble near_val,GLdouble far_val);
void glFrontFace( GLenum mode );
void glGet(...)
PREINIT:
toygl_rtype rtype;
GLenum pname;
/* Dunno if this should really be allocated on the stack. */
GLdouble doublearr[16];
GLint intarr[4];
GLboolean boolarr[4];
int nvals; /* No of values returned by glGet() */
PPCODE:
if ( (1!=items) && (2!=items) ) {
croak("glGet() requires 1 or 2 arguments");
}
if ( (2==items) && (!SvROK(ST(1))) ) {
croak("Second argument to glGet() must be reference");
}
pname = SvIV(ST(0));
/* Determine from the pname argument what glGet() is
* going to hand us back.
*/
switch(pname) {
case GL_ALPHA_TEST:
case GL_AUTO_NORMAL:
case GL_BLEND:
case GL_CLIP_PLANE0:
case GL_CLIP_PLANE1:
case GL_CLIP_PLANE2:
case GL_CLIP_PLANE3:
case GL_CLIP_PLANE4:
case GL_CLIP_PLANE5:
case GL_COLOR_ARRAY:
case GL_COLOR_LOGIC_OP:
case GL_COLOR_MATERIAL:
case GL_CULL_FACE:
case GL_CURRENT_RASTER_POSITION_VALID:
case GL_DEPTH_TEST:
case GL_DEPTH_WRITEMASK:
case GL_DITHER:
case GL_DOUBLEBUFFER:
case GL_EDGE_FLAG:
case GL_EDGE_FLAG_ARRAY:
case GL_FOG:
case GL_INDEX_ARRAY:
case GL_INDEX_LOGIC_OP:
case GL_INDEX_MODE:
case GL_LIGHT0:
case GL_LIGHT1:
case GL_LIGHT2:
case GL_LIGHT3:
case GL_LIGHT4:
case GL_LIGHTING:
case GL_LIGHT_MODEL_LOCAL_VIEWER:
case GL_LIGHT_MODEL_TWO_SIDE:
case GL_LINE_SMOOTH:
case GL_LINE_STIPPLE:
case GL_MAP1_COLOR_4:
case GL_MAP1_INDEX:
case GL_MAP1_NORMAL:
case GL_MAP1_TEXTURE_COORD_1:
case GL_MAP1_TEXTURE_COORD_2:
case GL_MAP1_TEXTURE_COORD_3:
case GL_MAP1_TEXTURE_COORD_4:
case GL_MAP1_VERTEX_3:
case GL_MAP1_VERTEX_4:
case GL_MAP2_COLOR_4:
case GL_MAP2_INDEX:
case GL_MAP2_NORMAL:
# Texture-mapping calls
void glBindTexture( GLenum target, GLuint texture );
void glIsTexture( GLuint texture );
void glDeleteTextures(...)
PREINIT:
GLuint *textures=NULL;
int n,i;
CODE:
if (
(2==items)
&& (SvROK(ST(1))
&& (SVt_PVAV == SvTYPE(SvRV(ST(1)))))
) {
/* Two items, of which the second is an array ref.
* Do things C-style, and interpret the first
* as the number of elements in the array to delete.
*/
AV *array;
array =(AV *) SvRV(ST(1));
n=SvIV(ST(0)); /* No of items to delete */
if (NULL==(textures=malloc(sizeof(GLuint)*n))) {
perror("malloc()");
croak("Out of memory");
}
for (i=0;i<n;i++) {
SV **svp;
svp = av_fetch(array,i,0);
textures[i] = SvUV(*svp);
}
} else {
/* Assume all arguments are textures to delete */
n=items;
if (NULL==(textures=malloc(sizeof(GLuint)*n))) {
perror("malloc()");
croak("Out of memory");
}
for (i=0;i<n;i++) {
textures[i] = SvUV(ST(i));
}
}
glDeleteTextures(n,textures);
free(textures);
void glGenTextures(...)
PREINIT:
GLuint *texture=NULL;
int n;
AV *array;
SV **svpp;
PPCODE:
if ( (1!=items) && (2!=items) ) {
croak("Bad number of arguments");
}
n = SvUV(ST(0));
if (2==items) {
int i;
if ( (!SvROK(ST(1)))
|| (SVt_PVAV != SvTYPE(SvRV(ST(1))))
) {
croak("Second arg must be array ref");
}
array = (AV *)SvRV(ST(1));
}
if (NULL==(texture=malloc(sizeof(GLuint)*n))) {
perror("malloc()");
croak("out of memory allocating texture IDs");
}
glGenTextures(n,texture);
if (1==items) {
int i;
/* Push the texture IDs onto the stack */
EXTEND(SP,n);
for (i=0;i<n;i++) {
PUSHs(sv_2mortal(newSViv(texture[i])));
}
} else {
/* Write texture IDs into the referenced array */
int i;
/* First, empty the array and resize it. */
av_clear(array);
av_fill(array,n-1);
/* Now store the elements. */
for (i=0;i<n;i++) {
av_store(array,i,newSViv(texture[i]));
}
}
free(texture);
void glTexParameter(...)
PREINIT:
GLenum pname,target;
char *badargno="Bad number of arguments to glTexParameter()";
CODE:
if (items<3) { fprintf(stderr,"items=%d\n",items);fflush(stderr); croak(badargno); }
target = (GLenum) SvIV(ST(0));
pname = (GLenum) SvIV(ST(1));
( run in 2.418 seconds using v1.01-cache-2.11-cpan-5511b514fd6 )