Remove GLEW dependency; improve GLES1 usage.

Remove dependency on GLEW.  It was used in precisely one place in
FBO.cpp.  It has been replaced with a partial substitute which correctly
interrogates for framebuffer object support in GLES, but doesn't yet
hook up the functions that call it.  More work needs doing here, as GL
1.1 has EXT and ARB extensions, GLES1 has an OES extension, and GL 2.0+
and GLES2 provide support directly.

Fix up places where GL (as opposed to GLES) headers were still included
despite specifying USE_GLES1.

GLES doesn't have glRect.() functions; implement glRectf().  Hopefully I
got the state preservation correct.

Convert use of glInterleavedArrays() to glVertexPointer() and
glTexCoordPointer().

Disable compressed texture support in SOIL.c -- GLES2 only supports DXT1
as an extension, and GLES1 doesn't have it at all.

After this changes, the thing compiles.
diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt
index 03cdbc7..02455b4 100644
--- a/src/libprojectM/CMakeLists.txt
+++ b/src/libprojectM/CMakeLists.txt
@@ -19,8 +19,6 @@
 
 OPTION (USE_OPENMP "Use OpenMP and OMPTL for multi-core parallelization" ON)
 
-OPTION (USE_NATIVE_GLEW "Use projectM's native implemention of GLEW." OFF)
-
 OPTION (USE_CG "Use Cg for Pixel Shader support" OFF)
 
 OPTION (BUILD_PROJECTM_STATIC "Build the projectM target library in the platform's native static (NOT shared) format." OFF)
@@ -45,17 +43,8 @@
   CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})"
   FORCE)
 
-if (USE_NATIVE_GLEW)
-ADD_DEFINITIONS(-DUSE_NATIVE_GLEW)
- SET(GLEW_SOURCES glew.h glew.c)
- SET(GLEW_LIBRARY "")
-else(USE_NATIVE_GLEW)
- set (GLEW_SOURCES "")
- find_package (GLEW)
-endif(USE_NATIVE_GLEW)
-
 SET(projectM_SOURCES projectM.cpp PCM.cpp Preset.cpp fftsg.cpp KeyHandler.cpp
-timer.cpp wipemalloc.cpp PresetLoader.cpp  PresetChooser.cpp PipelineMerger.cpp ConfigFile.cpp  TimeKeeper.cpp PresetFactory.cpp PresetFactoryManager.cpp ${GLEW_SOURCES})
+timer.cpp wipemalloc.cpp PresetLoader.cpp  PresetChooser.cpp PipelineMerger.cpp ConfigFile.cpp  TimeKeeper.cpp PresetFactory.cpp PresetFactoryManager.cpp)
 
 if (MSVC)
 SET(projectM_SOURCES ${projectM_SOURCES} dlfcn.c win32-dirent.cpp)
@@ -202,7 +191,6 @@
 				${IMAGE_LINK_TARGETS}
 				${CG_LINK_TARGETS}
 				${PRESET_FACTORY_LINK_TARGETS}
-				${GLEW_LIBRARY}
 				${FTGL_LINK_TARGETS}
 				${MATH_LIBRARIES}
 				dl
@@ -213,7 +201,6 @@
 				${IMAGE_LINK_TARGETS}
 				${CG_LINK_TARGETS}
 				${PRESET_FACTORY_LINK_TARGETS}
-				${GLEW_LIBRARY}
 				${FTGL_LINK_TARGETS}
 				${MATH_LIBRARIES}
 				dl
diff --git a/src/libprojectM/Common.hpp b/src/libprojectM/Common.hpp
index b292495..b325f80 100644
--- a/src/libprojectM/Common.hpp
+++ b/src/libprojectM/Common.hpp
@@ -63,7 +63,7 @@
 
 #ifdef LINUX
 #include <cstdlib>
-#define projectM_isnan isnan
+#define projectM_isnan std::isnan
 
 #endif
 
@@ -241,5 +241,3 @@
 typedef std::vector<int> RatingList;
 
 #endif
-
-
diff --git a/src/libprojectM/Renderer/FBO.cpp b/src/libprojectM/Renderer/FBO.cpp
index fac2408..5506e9c 100644
--- a/src/libprojectM/Renderer/FBO.cpp
+++ b/src/libprojectM/Renderer/FBO.cpp
@@ -97,10 +97,16 @@
    this->texsize = texsize;
 
 #ifdef USE_FBO
-   glewInit();
       // Forceably disable FBO if user requested it but the video card / driver lacks
       // the appropraite frame buffer extension.
-      if (useFBO = glewIsSupported("GL_EXT_framebuffer_object"))
+      useFBO = !!strstr ((char const *) glGetString (GL_EXTENSIONS),
+#ifdef USE_GLES1
+                         "GL_OES_framebuffer_object"
+#else
+                         "GL_EXT_framebuffer_object"
+#endif
+                        );
+      if (useFBO)
 	{	 
 
 	  GLuint   fb,  depth_rb, rgba_tex,  other_tex;
diff --git a/src/libprojectM/Renderer/FBO.hpp b/src/libprojectM/Renderer/FBO.hpp
index e79954d..77a1272 100644
--- a/src/libprojectM/Renderer/FBO.hpp
+++ b/src/libprojectM/Renderer/FBO.hpp
@@ -28,14 +28,6 @@
 #ifndef _RENDERTARGET_H
 #define _RENDERTARGET_H
 
-#ifdef USE_FBO
-#ifdef USE_NATIVE_GLEW
-#include "glew.h"
-#else
-#include <GL/glew.h>
-#endif
-#endif
-
 #ifdef MACOS
 #include <OpenGL/gl.h>
 #include <AGL/agl.h>
@@ -48,6 +40,7 @@
 #ifdef LINUX
 #ifdef USE_GLES1
 #include <GLES/gl.h>
+#include <GLES/glext.h>
 #else
 #include <GL/gl.h>
 #include <GL/glx.h>
diff --git a/src/libprojectM/Renderer/MilkdropWaveform.cpp b/src/libprojectM/Renderer/MilkdropWaveform.cpp
index d93291e..db1181f 100644
--- a/src/libprojectM/Renderer/MilkdropWaveform.cpp
+++ b/src/libprojectM/Renderer/MilkdropWaveform.cpp
@@ -7,10 +7,11 @@
 #include <iostream>
 
 #ifdef LINUX
+#ifdef USE_GLES1
+#include <GLES/gl.h>
+#else
 #include <GL/gl.h>
 #endif
-#ifdef WIN32
-#include "glew.h"
 #endif
 #ifdef __APPLE__
 #include <OpenGL/gl.h>
diff --git a/src/libprojectM/Renderer/Renderable.cpp b/src/libprojectM/Renderer/Renderable.cpp
index 3693858..389f64c 100644
--- a/src/libprojectM/Renderer/Renderable.cpp
+++ b/src/libprojectM/Renderer/Renderable.cpp
@@ -20,6 +20,27 @@
 typedef float floatTriple[3];
 typedef float floatQuad[4];
 
+static void
+glRectf (GLfloat x1, GLfloat x2, GLfloat y1, GLfloat y2)
+{
+  GLfloat verts[] = {
+    x1, y1,
+    x2, y1,
+    x1, y2,
+    x2, y2
+  };
+  GLboolean prev;
+
+  prev = glIsEnabled (GL_VERTEX_ARRAY);
+
+  glEnableClientState (GL_VERTEX_ARRAY);
+  glVertexPointer (2, GL_FLOAT, 0, verts);
+  glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
+
+  if (!prev)
+    glDisableClientState (GL_VERTEX_ARRAY);
+}
+
 RenderContext::RenderContext()
 	: time(0),texsize(512), aspectRatio(1), aspectCorrect(false){};
 
@@ -331,10 +352,10 @@
 
 	glColor4f(inner_r, inner_g, inner_b, inner_a * masterAlpha);
 
-	glRectd(of, of, of+iff, texof);
-	glRectd(of+iff, of, texof-iff, of+iff);
-	glRectd(texof-iff, of, texof, texof);
-	glRectd(of+iff, texof, texof-iff, texof-iff);
+	glRectf(of, of, of+iff, texof);
+	glRectf(of+iff, of, texof-iff, of+iff);
+	glRectf(texof-iff, of, texof, texof);
+	glRectf(of+iff, texof, texof-iff, texof-iff);
 
 	float pointsE[4][2] = {{of,of},{of,texof},{of+iff,of},{of+iff,texof}};
 	glVertexPointer(2,GL_FLOAT,0,pointsE);
diff --git a/src/libprojectM/Renderer/Renderer.cpp b/src/libprojectM/Renderer/Renderer.cpp
index acae065..509ea79 100644
--- a/src/libprojectM/Renderer/Renderer.cpp
+++ b/src/libprojectM/Renderer/Renderer.cpp
@@ -308,7 +308,8 @@
 
 	//glVertexPointer(2, GL_FLOAT, 0, p);
 	//glTexCoordPointer(2, GL_FLOAT, 0, t);
-	glInterleavedArrays(GL_T2F_V3F,0,p);
+  glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 5, (GLfloat *) p);
+  glVertexPointer (3, GL_FLOAT, sizeof (GLfloat) * 5, (GLfloat *) p + 2);
 
 
 	if (pipeline.staticPerPixel)
@@ -778,4 +779,3 @@
 		(*pos)->Draw(renderContext);
 
 }
-
diff --git a/src/libprojectM/Renderer/SOIL/SOIL.c b/src/libprojectM/Renderer/SOIL/SOIL.c
index 2403db2..23c145e 100644
--- a/src/libprojectM/Renderer/SOIL/SOIL.c
+++ b/src/libprojectM/Renderer/SOIL/SOIL.c
@@ -26,8 +26,13 @@
 	#include <Carbon/Carbon.h>

 	#define APIENTRY

 #else

-	#include <GL/gl.h>

-	#include <GL/glx.h>

+  #ifdef USE_GLES1

+    #include <GLES/gl.h>

+    #define APIENTRY

+  #else

+	  #include <GL/gl.h>

+	  #include <GL/glx.h>

+  #endif

 #endif

 

 #include "SOIL.h"

@@ -1359,7 +1364,7 @@
 		} else

 		{

 			/*	unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE;	*/

-			unsigned int clamp_mode = GL_CLAMP;

+			unsigned int clamp_mode = GL_CLAMP_TO_EDGE;

 			glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );

 			glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );

 			if( opengl_texture_type == SOIL_TEXTURE_CUBE_MAP )

@@ -1826,7 +1831,7 @@
 		} else

 		{

 			/*	unsigned int clamp_mode = SOIL_CLAMP_TO_EDGE;	*/

-			unsigned int clamp_mode = GL_CLAMP;

+			unsigned int clamp_mode = GL_CLAMP_TO_EDGE;

 			glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_S, clamp_mode );

 			glTexParameteri( opengl_texture_type, GL_TEXTURE_WRAP_T, clamp_mode );

 			glTexParameteri( opengl_texture_type, SOIL_TEXTURE_WRAP_R, clamp_mode );

@@ -1966,6 +1971,14 @@
 

 int query_DXT_capability( void )

 {

+#ifdef USE_GLES1

+  /*

+   * GLES1 has no S3-style texture compression extension.

+   * GLES2 has GL_EXT_texture_compression_dxt1 available which only supports,

+   * obviously enough, DXT1 compression.

+   */

+  has_DXT_capability = SOIL_CAPABILITY_NONE;

+#else

 	/*	check for the capability	*/

 	if( has_DXT_capability == SOIL_CAPABILITY_UNKNOWN )

 	{

@@ -2035,6 +2048,7 @@
 			}

 		}

 	}

+#endif

 	/*	let the user know if we can do DXT or not	*/

 	return has_DXT_capability;

 }

diff --git a/src/libprojectM/Renderer/TextureManager.cpp b/src/libprojectM/Renderer/TextureManager.cpp
index 76f4ffd..0cc4da3 100644
--- a/src/libprojectM/Renderer/TextureManager.cpp
+++ b/src/libprojectM/Renderer/TextureManager.cpp
@@ -1,8 +1,9 @@
 #ifdef LINUX
+#ifdef USE_GLES1
+#include <GLES/gl.h>
+#else
 #include <GL/gl.h>
 #endif
-#ifdef WIN32
-#include "glew.h"
 #endif
 #ifdef __APPLE__
 #include <OpenGL/gl.h>
diff --git a/src/libprojectM/Renderer/Waveform.cpp b/src/libprojectM/Renderer/Waveform.cpp
index da1e47f..0aca543 100644
--- a/src/libprojectM/Renderer/Waveform.cpp
+++ b/src/libprojectM/Renderer/Waveform.cpp
@@ -6,10 +6,11 @@
  */
 
 #ifdef LINUX
+#ifdef USE_GLES1
+#include <GLES/gl.h>
+#else
 #include <GL/gl.h>
 #endif
-#ifdef WIN32
-#include "glew.h"
 #endif
 #ifdef __APPLE__
 #include <OpenGL/gl.h>
@@ -119,6 +120,3 @@
 			delete[] value2;
 
    }
-
-
-