Moved old SDL::Palette to SDL::Game::Palette.
[sdlgit/SDL_perl.git] / src / OpenGL.xs
index def391c..841d92b 100644 (file)
@@ -1,6 +1,31 @@
-// SDL::OpenGL
 //
-// Copyright (C) 2002,2003,2004 David J. Goehrig
+// OpenGL.xs
+//
+// Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
+//
+// ------------------------------------------------------------------------------
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+//
+// ------------------------------------------------------------------------------
+//
+// Please feel free to send questions, suggestions or improvements to:
+//
+//     David J. Goehrig
+//     dgoehrig@cpan.org
+//
 
 #include "EXTERN.h"
 #include "perl.h"
 
 #include <SDL.h>
 
+#ifdef PERL_DARWIN
 #include <gl.h>
 #include <glu.h>
+#else
+#include <GL/gl.h>
+
+#if defined(__WIN32__) && defined(__MINGW32__)
+/* 
+this is a sort of dirty hack - MS Windows supports just OpenGL 1.1 and all 1.2+
+related stuff was moved from GL/gl.h to GL/glext.h; however this separation
+was done not properly and even if we are OK with OpenGL 1.1 there are some
+constants missing in GL/gl.h thus we need also GL/glext.h
+*/
+#include <GL/glext.h>
+#undef GL_VERSION_1_3
+#undef GL_VERSION_1_2
+#endif
+
+#include <GL/glu.h>
+#endif
+
 
 #ifdef USE_THREADS
 #define HAVE_TLS_CONTEXT
@@ -23,7 +67,9 @@
 #define GL_ALL_CLIENT_ATTRIB_BITS 0xFFFFFFF
 #endif /* GL_ALL_CLIENT_BITS */  
 
-#include "defines.h"
+#define GL_HAS_NURBS
+
+#include "../../src/defines.h"
 
 SV* sdl_perl_nurbs_error_hook;
 void
@@ -708,12 +754,6 @@ glGet ( param )
             croak("Unknown glGet parameter!");
         }
 
-const char * glGetString ( name )
-       GLenum name
-       CODE:
-               RETVAL = (const char *)glGetString (name);
-       OUTPUT:
-               RETVAL
 
 Uint32
 glIsEnabled ( cap )
@@ -850,6 +890,8 @@ glDrawElements ( mode, count, type, indices )
        CODE:
                glDrawElements( mode, count, type, indices);
 
+#ifdef GL_VERSION_1_2
+
 void
 glDrawRangeElements ( mode, start, end, count, type, indices )
        GLenum mode
@@ -861,6 +903,8 @@ glDrawRangeElements ( mode, start, end, count, type, indices )
        CODE:
                glDrawRangeElements(mode,start,end,count,type,indices);
 
+#endif // GL_VERSION_1_2
+
 void
 glDrawArrays ( mode, first, count )
        GLenum mode
@@ -916,7 +960,7 @@ glLoadMatrix (  ... )
                int i;
                double mat[16];
                for ( i = 0; i < 16; i++ ) {
-                       mat[i] = (i < items  && SvNOK(ST(i)) ? SvNV(ST(i)) : 0.0 );
+                       mat[i] = i < items ? SvNV(ST(i)) : 0.0;
                }
                glLoadMatrixd(mat);
 
@@ -926,7 +970,7 @@ glMultMatrix ( ... )
                int i;
                double mat[16];
                for ( i = 0; i < 16; i++ ) {
-                       mat[i] = (i < items  && SvNOK(ST(i)) ? SvNV(ST(i)) : 0.0 );
+                       mat[i] = i < items ? SvNV(ST(i)) : 0.0;
                }
                glMultMatrixd(mat);
 
@@ -1010,7 +1054,7 @@ glClipPlane ( plane, ... )
                double v[4];
                int i;
                for (i = 0; i < 4; i++ ) {
-                       v[i] = (i+1 < items && SvNOK(ST(i+1))) ? SvNV(ST(i+1)) : 0.0;
+                       v[i] = i+1 < items ? SvNV(ST(i+1)) : 0.0;
                }
                glClipPlane(plane,v);
        
@@ -1049,13 +1093,13 @@ glLight ( light, name, ... )
                if ( items == 6 ) {
                        float v[4];     
                        for ( i = 0; i < 4; i++ ) {
-                               v[i] = (SvNOK(ST(i+2))) ? SvNV(ST(i+2)) : 0.0;
+                               v[i] = SvNV(ST(i+2));
                        }
                        glLightfv(light,name,v);        
                } else if ( items == 5 ) {
                        float v[3];
                        for ( i = 0; i < 3; i++ ) {
-                               v[i] = (SvNOK(ST(i+2))) ? SvNV(ST(i+2)) : 0.0;
+                               v[i] = SvNV(ST(i+2));
                        }
                        glLightfv(light,name,v);        
                } else if ( items == 3 ) {
@@ -1094,13 +1138,13 @@ glMaterial ( face, name, ... )
                if ( items == 6 ) {
                        float v[4];
                        for ( i = 0; i < 4; i++ ) {
-                               v[i] = (SvNOK(ST(i+2))) ? SvNV(ST(i+2)) : 0.0;
+                               v[i] = SvNV(ST(i+2));
                        }
                        glMaterialfv(face,name,v);
                } else if ( items == 5 ) {
                        float v[3];
-                       for ( i = 0; i < 4; i++ ) {
-                               v[i] = (SvNOK(ST(i+2))) ? SvNV(ST(i+2)) : 0.0;
+                       for ( i = 0; i < 3; i++ ) {
+                               v[i] = SvNV(ST(i+2));
                        }
                        glMaterialfv(face,name,v);
                } else if ( items == 3 ) {      
@@ -1231,24 +1275,16 @@ glCallListsString ( string )
                glCallLists(len,GL_BYTE,str);
 
 void
-glRasterPos ( x, y, ... )
+glRasterPos ( x, y, z, ... )
        double x
        double y
+       double z
        CODE:
-               if (items == 2)
-               {
-                       glRasterPos2d (x,y);
-               }
-               else if (items == 3)
-               {
-                       double z = SvNV (ST(2));
-                       glRasterPos3d (x,y,z);
-               }
-               else if (items == 4)
-               {
-                       double z = SvNV (ST(2));
-                       double w = SvNV (ST(3));
-                       glRasterPos4d (x,y,z,w);
+               if ( items == 4 ) {
+                       double w = SvNV(ST(3));
+                       glRasterPos4d(x,y,z,w);
+               } else {
+                       glRasterPos3d(x,y,z);
                }
 
 void
@@ -1732,9 +1768,9 @@ AV*
 glGenTextures ( n )
        Uint32 n;
        CODE:
-               Uint32 i;
-               Uint32 *names;
-               names = (Uint32*)safemalloc(sizeof(Uint32)*n);
+               GLsizei i;
+               GLuint* names;
+               names = (GLuint*)safemalloc(sizeof(GLuint)*n);
                RETVAL = newAV();
                glGenTextures(n,names);
                for ( i = 0; i < n; i++ ) {
@@ -1762,9 +1798,9 @@ glBindTexture ( target, texture )
 void
 glDeleteTextures ( ... )
        CODE:
-               Uint32 *textures;
+               GLuint* textures;
                int i;
-               textures = (Uint32*)safemalloc(sizeof(Uint32) * items);
+               textures = (GLuint*)safemalloc(sizeof(GLuint) * items);
                if ( textures ) {
                        for ( i = 0; i < items; i++ ) {
                                textures[i] = SvIV(ST(i));      
@@ -1776,11 +1812,11 @@ glDeleteTextures ( ... )
 AV*
 glAreTexturesResident ( ... )
        CODE:
-               Uint32 *textures;
+               GLuint* textures;
                GLboolean *homes;
                int i;
                RETVAL = newAV();
-               textures = (Uint32*)safemalloc(sizeof(Uint32) * items);
+               textures = (GLuint*)safemalloc(sizeof(GLuint) * items);
                homes = (GLboolean*)safemalloc(sizeof(GLboolean) * items);
                if ( textures ) {
                        for ( i = 0; i < items; i++ ) {
@@ -2407,8 +2443,10 @@ gluNurbsCallback ( obj, which, cb )
                                gluNurbsCallback(obj,GLU_ERROR,(GLvoid*)sdl_perl_nurbs_error_callback);
                                break;
 #ifdef GLU_NURBS_BEGIN
+#ifdef GLU_VERSION_1_3
                        case GLU_NURBS_BEGIN:
                        case GLU_NURBS_BEGIN_DATA:
+
                                gluNurbsCallbackData(obj,(void*)cb);
                                gluNurbsCallback(obj,GLU_NURBS_BEGIN_DATA,
                                        (GLvoid*)sdl_perl_nurbs_being_callback);        
@@ -2443,11 +2481,14 @@ gluNurbsCallback ( obj, which, cb )
                                gluNurbsCallback(obj,GLU_NURBS_END_DATA,
                                        (GLvoid*)sdl_perl_nurbs_end_callback);  
                                break;
-#endif
+#endif // GLU_VERSION_1_3
+#endif // GLU_NURBS_BEGIN
                        default:
                                Perl_croak(aTHX_ "SDL::OpenGL::NurbsCallback - invalid type");
                }
 
+#ifdef GLU_VERSION_1_3
+
 void
 gluNurbsCallbackData ( obj, cb )
        GLUnurbsObj *obj
@@ -2455,6 +2496,8 @@ gluNurbsCallbackData ( obj, cb )
        CODE:
                gluNurbsCallbackData(obj,(void*)cb);
 
+#endif
+
 void
 gluBeginSurface ( obj )
        GLUnurbsObj *obj
@@ -2727,23 +2770,16 @@ gluNewQuadric ()
 void
 gluDeleteQuadric (quad)
        GLUquadric      *quad
-       CODE:
-               gluDeleteQuadric(quad);
 
 void
 gluQuadricNormals ( quad, normal )
        GLUquadric *quad
        GLenum  normal
-       CODE:
-               gluQuadricNormals(quad, normal);
-
 
 void
 gluQuadricTexture ( quad, texture )
        GLUquadric *quad
        GLboolean  texture
-       CODE:
-               gluQuadricTexture ( quad, texture );
 
 void
 gluCylinder ( quad, base, top, height, slices, stacks )
@@ -2753,8 +2789,6 @@ gluCylinder ( quad, base, top, height, slices, stacks )
        GLdouble  height
        GLint  slices
        GLint  stacks
-       CODE:
-               gluCylinder ( quad, base, top, height, slices, stacks );
 
 void
 gluDisk ( quad, inner, outer, slices, loops )
@@ -2763,9 +2797,7 @@ gluDisk ( quad, inner, outer, slices, loops )
        GLdouble outer
        GLint slices
        GLint loops
-       CODE:
-               gluDisk ( quad, inner, outer, slices, loops );  
-       
+
 void
 gluPartialDisk ( quad, inner, outer, slices, loops, start, sweep )
        GLUquadric *quad
@@ -2775,9 +2807,6 @@ gluPartialDisk ( quad, inner, outer, slices, loops, start, sweep )
        GLint loops
        GLdouble start
        GLdouble sweep
-       
-       CODE:
-               gluPartialDisk ( quad, inner, outer, slices, loops, start, sweep );
 
 void
 gluSphere ( quad, radius, slices, stacks )
@@ -2785,9 +2814,6 @@ gluSphere ( quad, radius, slices, stacks )
        GLdouble radius
        GLint  slices
        GLint  stacks
-       CODE:
-               gluSphere ( quad, radius, slices, stacks );
-
 
 #endif