Commits

Todd Rovito committed 0cc1a35

-Cleaned up the copyright notice in the headers
-Added some #pragmas to remove bad warnings
-Moved SDL_GL_SetAttribute before all the SDL_Init to avoid a seg fault
-Cleaned up many lines to not go beyond 80 characters

  • Participants
  • Parent commits 54fde07

Comments (0)

Files changed (13)

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 #ifndef GLEW_STATIC
 #define GLEW_STATIC
 #endif
-#include <gl\glew.h>			// OpenGL Extension "autoloader"
-#include <gl\gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
+#include <gl/glew.h>			// OpenGL Extension "autoloader"
+#include <gl/gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
 #endif
 
 // Mac OS X
 
 };
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtypedef-redefinition"
 typedef struct GLBatchStruct GLBatch;
+#pragma clang diagnostic pop
 
 void glBatchInitBatch(GLBatch *batch);
 void glBatchBegin(GLBatch *batch, GLenum primitive, GLuint nVerts, GLuint nTextureUnits);
 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 

File GLGeometryTransform.h

-//
-//  GLGeometryTransform.h
-//  SDL2Triangle
-//
-//  Created by Todd V. Rovito on 8/18/13.
-//
-//
 /*
+GLGeometryTransform.h
+ 
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ 
+ See LICENSE.txt for full details of the MPL license.
+ 
+ Copyright (c) 2013, Todd V. Rovito
+ https://bitbucket.org/rovitotv/sdl2-gltools
+
+ The Open GL Super Bible has the following license and must be followed:
+ 
  Copyright (c) 2009, Richard S. Wright Jr.
  All rights reserved.
  
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- 
- Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
- 
- Redistributions in binary form must reproduce the above copyright notice, this list
- of conditions and the following disclaimer in the documentation and/or other
- materials provided with the distribution.
- 
- Neither the name of Richard S. Wright Jr. nor the names of other contributors may be used
- to endorse or promote products derived from this software without specific prior
- written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ 
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 
+ Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
+ 
+ Neither the name of Richard S. Wright Jr. nor the names of other contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+ 
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
+ */
 #ifndef GLGeometryTransform_h
 #define GLGeometryTransform_h
 

File GLMatrixStack.h

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 

File GLShaderManager.h

-//
-//  GLShaderManager.h
-//  
-//
-//  Created by Todd V. Rovito on 7/25/13.
-//
-//
-/* Copyright (c) 2009, Richard S. Wright Jr.
+/*
+GLShaderManager.h
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ 
+ See LICENSE.txt for full details of the MPL license.
+ 
+ Copyright (c) 2013, Todd V. Rovito
+ https://bitbucket.org/rovitotv/sdl2-gltools
+ 
+ The Open GL Super Bible has the following license and must be followed:
+ 
+ Copyright (c) 2009, Richard S. Wright Jr.
  All rights reserved.
  
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
  
- Redistributions of source code must retain the above copyright notice, this list
- of conditions and the following disclaimer.
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
  
- Redistributions in binary form must reproduce the above copyright notice, this list
- of conditions and the following disclaimer in the documentation and/or other
- materials provided with the distribution.
+ Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
  
- Neither the name of Richard S. Wright Jr. nor the names of other contributors may be used
- to endorse or promote products derived from this software without specific prior
- written permission.
+ Neither the name of Richard S. Wright Jr. nor the names of other contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
  
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
-
-
 #ifndef _GLShaderManager_h
 #define _GLShaderManager_h
 
 #define GLEW_STATIC
 #endif
 
-#include <gl\glew.h>			// OpenGL Extension "autoloader"
-#include <gl\gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
+#include <gl/glew.h>			// OpenGL Extension "autoloader"
+#include <gl/gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
 #endif
 
 // Mac OS X
 #define MAX_SHADER_NAME_LENGTH	64
 
 #include "GLTools.h"
+#include <stdarg.h>
 #include "math3d.h"
 
 enum GLT_STOCK_SHADER { GLT_SHADER_IDENTITY = 0, GLT_SHADER_FLAT, GLT_SHADER_SHADED, GLT_SHADER_DEFAULT_LIGHT, GLT_SHADER_POINT_LIGHT_DIFF,
 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
-
-
-
 #ifndef _GLTools_h
 #define _GLTools_h
 
 #define GLEW_STATIC
 #endif
 
-#include <gl\glew.h>			// OpenGL Extension "autoloader"
-#include <gl\gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
+#include <gl\glew.h>	// OpenGL Extension "autoloader"
+#include <gl\gl.h>		// Microsoft OpenGL headers (version 1.1 by themselves)
 #endif
 
 // Mac OS X
 #define OPENGL_ES
 #else
 #include <GL/glew.h>
-#include <OpenGL/gl.h>		// Apple OpenGL haders (version depends on OS X SDK version)
+#include <OpenGL/gl.h>
+// Apple OpenGL haders (version depends on OS X SDK version)
 #endif
 #endif
 
 #include <glew.h>
 #endif
 
-//////////////////////// TEMPORARY TEMPORARY TEMPORARY - On SnowLeopard this is suppored, but GLEW doens't hook up properly
+//////////////////////// TEMPORARY TEMPORARY TEMPORARY - On SnowLeopard this is
+////// suppored, but GLEW doens't hook up properly
 //////////////////////// Fixed probably in 10.6.3
-//// NOTE FROM TVR DO NOT COMMENT these out the Mac needs these even though it produces warnings
+//// NOTE FROM TVR DO NOT COMMENT these out the Mac needs these even though it
+//// produces warnings
 #ifdef __APPLE__
 #define glGenVertexArrays glGenVertexArraysAPPLE
 #define glDeleteVertexArrays  glDeleteVertexArraysAPPLE
 #endif
 #endif
 
-
-// Universal includes
 #include <stdio.h>
-#include <math.h>
 #include <stdarg.h>
+#include <math.h>
 #include <math3d.h>
 #include <GLBatch.h>
 #include <GLTriangleBatch.h>
 #define LITTLE_ENDIAN_DWORD
 #endif
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtypedef-redefinition"
+
 typedef struct GLTriangleStruct GLTriangle; // why does this have to be done?  This makes no sense...
 typedef struct GLBatchStruct GLBatch;
 
+#pragma clang diagnostic pop
+
 GLuint glToolsLoadShaderPairSrcWithAttributes(const char *szVertexProg, const char *szFragmentProg, ...);
 void glToolsLoadShaderSrc(const char *szShaderSrc, GLuint shader);
 void glToolsSetClearColor(float red, float green, float blue, float alpha);

File GLTriangleBatch.h

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 #define GLEW_STATIC
 #endif
 
-#include <gl\glew.h>			// OpenGL Extension "autoloader"
-#include <gl\gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
+#include <gl/glew.h>			// OpenGL Extension "autoloader"
+#include <gl/gl.h>			// Microsoft OpenGL headers (version 1.1 by themselves)
 #endif
 
 // Mac OS X
     GLuint vertexArrayBufferObject;
 };
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtypedef-redefinition"
 typedef struct GLTriangleStruct GLTriangle;
+#pragma clang diagnostic pop
 
 void glTriangleBatchInit(GLTriangle *glTriangle);
 void glTriangleBatchDestroy(GLTriangle *glTriangle);
 void glTriangleBatchEnd(GLTriangle *glTriangle);
 void glTriangleBatchDraw(GLTriangle *glTriangle);
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 #endif

File SphereWorld.c

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013, Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 #include <stdio.h>
 #include <SDL.h>
 #define PROGRAM_NAME "OpenGL Sphere World"
-/*
-#ifdef __APPLE__
-#include <glut/glut.h>
-#else
-#define FREEGLUT_STATIC
-#include <GL/glut.h>
-#endif
-*/
+
 
 
 /* A simple function that prints a message, the error code returned by SDL,
     
     SDL_Window *mainwindow;
     SDL_GLContext maincontext;
-   
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-        sdldie("Unable to initalize SDL");
+
     /* Request opengl 3.2 context.
-     *      * SDL doesn't have the ability to choose which profile at this time of writing,
-     *           * but it should default to the core profile */
+     * SDL doesn't have the ability to choose which profile at this time of 
+     * writing, but it should default to the core profile */
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     
     /* Turn on double buffering with a 24bit Z buffer.
-     *      * You may need to change this to 16 or 32 for your system */
+     * You may need to change this to 16 or 32 for your system */
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+    if (SDL_Init(SDL_INIT_VIDEO) < 0)
+        sdldie("Unable to initalize SDL");
+
     
     /* Create our window centered at 512x512 resolution */
-    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                                  800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
+    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED,
+                                  SDL_WINDOWPOS_CENTERED,
+                                  800, 600, SDL_WINDOW_OPENGL |
+                                  SDL_WINDOW_SHOWN);
     if (!mainwindow) /* Die if creation failed */
         sdldie("Unable to create window");
     
     
     
     SetupRC(uiStockShaders, &floorBatch, &torusBatch);
-    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix, &transformPipeline);
+    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix,
+               &transformPipeline);
     for (int cycle = 0; cycle < 150; cycle++) {
-        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders, &transformPipeline, &floorBatch, &torusBatch);
+        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders,
+                    &transformPipeline, &floorBatch, &torusBatch);
         // glutMainLoop();  // this might be an issue SDL equivilant?
         SDL_GL_SwapWindow(mainwindow);
     

File SphereWorld2.c

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013,  Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 //////////////////////////////////////////////////////////////////
 // This function does any needed initialization on the rendering
 // context.
-void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch, GLTriangle *torusBatch,  GLTriangle *sphereBatch)
+void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch,
+             GLTriangle *torusBatch,  GLTriangle *sphereBatch)
 {
 	// Initialze Shader Manager
     glShaderManagerInitializeStockShaders(uiStockShaders);
 
 ///////////////////////////////////////////////////
 // Screen changes size or is initialized
-void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum, GLMatrixStack *projectionMatrix,
-                GLMatrixStack *modelViewMatrix, GLGeometryTransform *transformPipeline)
+void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum,
+                GLMatrixStack *projectionMatrix,
+                GLMatrixStack *modelViewMatrix,
+                GLGeometryTransform *transformPipeline)
 {
     // Create the projection matrix, and load it on the projection matrix stack
     glFrustumSetPerspective(viewFrustum, 35.0f, (float) nWidth / (float) nHeight, 1.0f, 100.0f);
-    glMatrixStackLoadMatrix(projectionMatrix, (const float *)glFrustumGetProjectionMatrix(viewFrustum));
+    glMatrixStackLoadMatrix(projectionMatrix,
+                            (const float *)glFrustumGetProjectionMatrix(viewFrustum));
     
     // Set the transformation pipeline to use the two matrix stacks
-    glGeometryTransformSetMatrixStacks(transformPipeline, modelViewMatrix, projectionMatrix);
+    glGeometryTransformSetMatrixStacks(transformPipeline, modelViewMatrix,
+                                       projectionMatrix);
 }
 
 
 }
 
 // Called to draw scene
-void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix, GLuint *uiStockShaders,
-                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch, GLTriangle *torusBatch,
+void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix,
+                 GLuint *uiStockShaders,
+                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch,
+                 GLTriangle *torusBatch,
                  GLTriangle *sphereBatch, GLFrame *cameraFrame)
 {
     // Color values
     glMatrixStackPushNewMatrix(modelViewMatrix, mCamera);
     
 	// Draw the ground
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vFloorColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vFloorColor);
     glBatchDraw(floorBatch);
     
     // Draw the spinning Torus
     
     // Apply a rotation and draw the torus
     glMatrixStackRotate(modelViewMatrix, yRot, 0.0f, 1.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vTorusColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vTorusColor);
     glTriangleBatchDraw(torusBatch);
     glMatrixStackPopMatrix(modelViewMatrix); // "Erase" the Rotation from before
     
     // Apply another rotation, followed by a translation, then draw the sphere
     glMatrixStackRotate(modelViewMatrix, yRot * -2.0f, 0.0f, 1.0f, 0.0f);
     glMatrixStackTranslate(modelViewMatrix, 0.8f, 0.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vSphereColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vSphereColor);
     glTriangleBatchDraw(sphereBatch);
     
 	// Restore the previous modleview matrix (the identity matrix)
     
     SDL_Window *mainwindow;
     SDL_GLContext maincontext;
-    
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-        sdldie("Unable to initalize SDL");
     /* Request opengl 3.2 context.
-     *      * SDL doesn't have the ability to choose which profile at this time of writing,
-     *           * but it should default to the core profile */
+     * SDL doesn't have the ability to choose which profile at this time of writing,
+     * but it should default to the core profile */
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     
     /* Turn on double buffering with a 24bit Z buffer.
-     *      * You may need to change this to 16 or 32 for your system */
+     * You may need to change this to 16 or 32 for your system */
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
     
+    if (SDL_Init(SDL_INIT_VIDEO) < 0)
+        sdldie("Unable to initalize SDL");
+    
     /* Create our window centered at 512x512 resolution */
-    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                                  800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
+    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED,
+                                  SDL_WINDOWPOS_CENTERED,
+                                  800, 600, SDL_WINDOW_OPENGL |
+                                  SDL_WINDOW_SHOWN);
     if (!mainwindow) /* Die if creation failed */
         sdldie("Unable to create window");
     
     }
     
     SetupRC(uiStockShaders, &floorBatch, &torusBatch, &sphereBatch);
-    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix, &transformPipeline);
+    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix,
+               &transformPipeline);
     while (gameRunning) {
         gameRunning = SpecialKeys(&cameraFrame);
-        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders, &transformPipeline, &floorBatch, &torusBatch, &sphereBatch, &cameraFrame);
+        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders,
+                    &transformPipeline, &floorBatch, &torusBatch,
+                    &sphereBatch, &cameraFrame);
         SDL_GL_SwapWindow(mainwindow);
     }
     SDL_GL_DeleteContext(maincontext);

File SphereWorld2Cube.c

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013,  Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 //////////////////////////////////////////////////////////////////
 // This function does any needed initialization on the rendering
 // context.
-void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch, GLTriangle *torusBatch,  GLTriangle *sphereBatch,
+void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch,
+             GLTriangle *torusBatch,  GLTriangle *sphereBatch,
              GLBatch *cubeBatch)
 {
 	// Initialze Shader Manager
 
 ///////////////////////////////////////////////////
 // Screen changes size or is initialized
-void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum, GLMatrixStack *projectionMatrix,
-                GLMatrixStack *modelViewMatrix, GLGeometryTransform *transformPipeline)
+void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum,
+                GLMatrixStack *projectionMatrix,
+                GLMatrixStack *modelViewMatrix,
+                GLGeometryTransform *transformPipeline)
 {
     // Create the projection matrix, and load it on the projection matrix stack
     glFrustumSetPerspective(viewFrustum, 35.0f, (float) nWidth / (float) nHeight, 1.0f, 100.0f);
 }
 
 // Called to draw scene
-void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix, GLuint *uiStockShaders,
-                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch, GLTriangle *torusBatch,
-                 GLTriangle *sphereBatch, GLBatch *cubeBatch, GLFrame *cameraFrame)
+void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix,
+                 GLuint *uiStockShaders,
+                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch,
+                 GLTriangle *torusBatch,
+                 GLTriangle *sphereBatch, GLBatch *cubeBatch,
+                 GLFrame *cameraFrame)
 {
     // Color values
     static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
     glMatrixStackPushNewMatrix(modelViewMatrix, mCamera);
     
 	// Draw the ground
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vFloorColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vFloorColor);
     glBatchDraw(floorBatch);
 
     // Draw the spinning Torus
     glMatrixStackPushMatrix(modelViewMatrix);
 
     // Draw the cube
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vSphereColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vSphereColor);
     glBatchDraw(cubeBatch);
     
     // Apply a rotation and draw the torus
     glMatrixStackRotate(modelViewMatrix, yRot, 0.0f, 1.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vTorusColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vTorusColor);
     glTriangleBatchDraw(torusBatch);
     glMatrixStackPopMatrix(modelViewMatrix); // "Erase" the Rotation from before
     
     // Apply another rotation, followed by a translation, then draw the sphere
     glMatrixStackRotate(modelViewMatrix, yRot * -2.0f, 0.0f, 1.0f, 0.0f);
     glMatrixStackTranslate(modelViewMatrix, 0.8f, 0.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vSphereColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vSphereColor);
     glTriangleBatchDraw(sphereBatch);
 
 	// Restore the previous modleview matrix (the identity matrix)
     SDL_Window *mainwindow;
     SDL_GLContext maincontext;
     
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-        sdldie("Unable to initalize SDL");
     /* Request opengl 3.2 context.
-     *      * SDL doesn't have the ability to choose which profile at this time of writing,
-     *           * but it should default to the core profile */
+     * SDL doesn't have the ability to choose which profile at this time of 
+     * writing, but it should default to the core profile */
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     
      *      * You may need to change this to 16 or 32 for your system */
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+    if (SDL_Init(SDL_INIT_VIDEO) < 0)
+        sdldie("Unable to initalize SDL");
     
     /* Create our window centered at 512x512 resolution */
-    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                                  800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
+    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED,
+                                  SDL_WINDOWPOS_CENTERED,
+                                  800, 600, SDL_WINDOW_OPENGL |
+                                  SDL_WINDOW_SHOWN);
     if (!mainwindow) /* Die if creation failed */
         sdldie("Unable to create window");
     
     }
     
     SetupRC(uiStockShaders, &floorBatch, &torusBatch, &sphereBatch, &cubeBatch);
-    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix, &transformPipeline);
+    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix,
+               &transformPipeline);
     while (gameRunning) {
         gameRunning = SpecialKeys(&cameraFrame, stateKeys);
-        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders, &transformPipeline, &floorBatch, &torusBatch, &sphereBatch, &cubeBatch, &cameraFrame);
+        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders,
+                    &transformPipeline, &floorBatch, &torusBatch, &sphereBatch,
+                    &cubeBatch, &cameraFrame);
         SDL_GL_SwapWindow(mainwindow);
     }
     SDL_GL_DeleteContext(maincontext);

File SphereWorld3.c

 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013,  Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 //////////////////////////////////////////////////////////////////
 // This function does any needed initialization on the rendering
 // context. 
-void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch, GLTriangle *torusBatch,
+void SetupRC(GLuint *uiStockShaders, GLBatch *floorBatch,
+             GLTriangle *torusBatch,
              GLTriangle *sphereBatch, GLFrame *spheres)
 {
 	// Initialze Shader Manager
 
 ///////////////////////////////////////////////////
 // Screen changes size or is initialized
-void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum, GLMatrixStack *projectionMatrix,
-                GLMatrixStack *modelViewMatrix, GLGeometryTransform *transformPipeline)
+void ChangeSize(int nWidth, int nHeight, GLFrustum *viewFrustum,
+                GLMatrixStack *projectionMatrix,
+                GLMatrixStack *modelViewMatrix,
+                GLGeometryTransform *transformPipeline)
 {
     // Create the projection matrix, and load it on the projection matrix stack
-    glFrustumSetPerspective(viewFrustum, 35.0f, (float) nWidth / (float) nHeight, 1.0f, 100.0f);
-    glMatrixStackLoadMatrix(projectionMatrix, (const float *)glFrustumGetProjectionMatrix(viewFrustum));
+    glFrustumSetPerspective(viewFrustum, 35.0f,
+                            (float) nWidth / (float) nHeight, 1.0f, 100.0f);
+    glMatrixStackLoadMatrix(projectionMatrix,
+                (const float *)glFrustumGetProjectionMatrix(viewFrustum));
     
     // Set the transformation pipeline to use the two matrix stacks
-    glGeometryTransformSetMatrixStacks(transformPipeline, modelViewMatrix, projectionMatrix);
+    glGeometryTransformSetMatrixStacks(transformPipeline, modelViewMatrix,
+                                       projectionMatrix);
 }
 
 
 // Called to draw scene
-void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix, GLuint *uiStockShaders,
-                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch, GLTriangle *torusBatch,
-                 GLTriangle *sphereBatch, GLFrame *cameraFrame, GLFrame *spheres)
+void RenderScene(CStopWatch *rotTimer, GLMatrixStack *modelViewMatrix,
+                 GLuint *uiStockShaders,
+                 GLGeometryTransform *transformPipeline, GLBatch *floorBatch,
+                 GLTriangle *torusBatch,
+                 GLTriangle *sphereBatch, GLFrame *cameraFrame,
+                 GLFrame *spheres)
 {
     // Color values
     static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
     glMatrixStackPushNewMatrix(modelViewMatrix, mCamera);
     
 	// Draw the ground
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vFloorColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+        glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+        vFloorColor);
     glBatchDraw(floorBatch);
     
     
     for(int i = 0; i < NUM_SPHERES; i++) {
         glMatrixStackPushMatrix(modelViewMatrix);
         glMatrixStackMultiplyMatrixFromFrame(modelViewMatrix, &spheres[i]);
-        glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vSphereColor);
-    
+        glShaderManagerUseStockShaderFlat(uiStockShaders,
+            glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+            vSphereColor);
         glTriangleBatchDraw(sphereBatch);
         glMatrixStackPopMatrix(modelViewMatrix);
     }
     
     // Apply a rotation and draw the torus
     glMatrixStackRotate(modelViewMatrix, yRot, 0.0f, 1.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vTorusColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+        glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+        vTorusColor);
     glTriangleBatchDraw(torusBatch);
     glMatrixStackPopMatrix(modelViewMatrix); // "Erase" the Rotation from before
     
     // Apply another rotation, followed by a translation, then draw the sphere
     glMatrixStackRotate(modelViewMatrix, yRot * -2.0f, 0.0f, 1.0f, 0.0f);
     glMatrixStackTranslate(modelViewMatrix, 0.8f, 0.0f, 0.0f);
-    glShaderManagerUseStockShaderFlat(uiStockShaders, glGeometryTransformGetModelViewProjectionMatrix(transformPipeline), vSphereColor);
+    glShaderManagerUseStockShaderFlat(uiStockShaders,
+        glGeometryTransformGetModelViewProjectionMatrix(transformPipeline),
+        vSphereColor);
     glTriangleBatchDraw(sphereBatch);
     
 	// Restore the previous modleview matrix (the identity matrix)
     SDL_Window *mainwindow;
     SDL_GLContext maincontext;
     
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-        sdldie("Unable to initalize SDL");
     /* Request opengl 3.2 context.
-     *      * SDL doesn't have the ability to choose which profile at this time of writing,
-     *           * but it should default to the core profile */
+     * SDL doesn't have the ability to choose which profile at this time of 
+     * writing, but it should default to the core profile */
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     
     /* Turn on double buffering with a 24bit Z buffer.
-     *      * You may need to change this to 16 or 32 for your system */
+     * You may need to change this to 16 or 32 for your system */
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+    if (SDL_Init(SDL_INIT_VIDEO) < 0)
+        sdldie("Unable to initalize SDL");
+
     
     /* Create our window centered at 512x512 resolution */
-    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                                  800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
+    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED,
+                                  SDL_WINDOWPOS_CENTERED,
+                                  800, 600, SDL_WINDOW_OPENGL |
+                                  SDL_WINDOW_SHOWN);
     if (!mainwindow) /* Die if creation failed */
         sdldie("Unable to create window");
     
     }
     
     SetupRC(uiStockShaders, &floorBatch, &torusBatch, &sphereBatch, spheres);
-    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix, &transformPipeline);
+    ChangeSize(800, 600, &viewFrustum, &projectionMatrix, &modelViewMatrix,
+               &transformPipeline);
     while (gameRunning) {
         gameRunning = SpecialKeys(&cameraFrame);
-        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders, &transformPipeline, &floorBatch, &torusBatch, &sphereBatch, &cameraFrame, spheres);
+        RenderScene(&rotTimer, &modelViewMatrix, uiStockShaders,
+                    &transformPipeline, &floorBatch, &torusBatch, &sphereBatch,
+                    &cameraFrame, spheres);
         SDL_GL_SwapWindow(mainwindow);
     }
     SDL_GL_DeleteContext(maincontext);
 
 See LICENSE.txt for full details of the MPL license.
 
-Copyright Todd V. Rovito 2013
+Copyright (c) 2013,  Todd V. Rovito
 https://bitbucket.org/rovitotv/sdl2-gltools
 
 
 
 #include "GLTools.h"            // OpenGL toolkit
 #include "GLShaderManager.h"    // Shader Manager Class
-#include "GLBatch.h"
-/*
- #ifdef __APPLE__
- #include <glut/glut.h>          // OS X version of GLUT
- #else
- #define FREEGLUT_STATIC
- #include <GL/glut.h>            // Windows FreeGlut equivalent
- #endif
- */
+#include "GLBatch.h"          // already included in GLTools.h
 #include <SDL.h>
 #define PROGRAM_NAME "SDLTriangle"
-//GLBatch	triangleBatch;
-//GLShaderManager	shaderManager;
+
 
 /* A simple function that prints a message, the error code returned by SDL,
  *  * and quits the application */
 #endif
 }
 
-
-///////////////////////////////////////////////////////////////////////////////
-// Window has changed size, or has just been created. In either case, we need
-// to use the window dimensions to set the viewport and the projection matrix.
-void ChangeSize(int w, int h)
-{
-	//glViewport(0, 0, w, h);
-}
-
-
 ///////////////////////////////////////////////////////////////////////////////
 // This function does any needed initialization on the rendering context.
 // This is the first opportunity to do any OpenGL related tasks.
 }
 
 
-
 ///////////////////////////////////////////////////////////////////////////////
 // Called to draw scene
 void RenderScene(GLuint *uiStockShaders, GLBatch *batch)
     glBatchDraw(batch);
 }
 
-
 ///////////////////////////////////////////////////////////////////////////////
 // Main entry point for GLUT based programs
 int main(int argc, char* argv[])
     
     glBatchInitBatch(&triangleBatch);
     
-    if (SDL_Init(SDL_INIT_VIDEO) < 0) /* Initialize SDL's Video subsystem */
-        sdldie("Unable to initialize SDL"); /* Or die on error */
-    
     /* Request opengl 3.2 context.
-     *      * SDL doesn't have the ability to choose which profile at this time of writing,
-     *           * but it should default to the core profile */
+     * SDL doesn't have the ability to choose which profile at this time of 
+     * writing,but it should default to the core profile */
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
     
     /* Turn on double buffering with a 24bit Z buffer.
-     *      * You may need to change this to 16 or 32 for your system */
+     * You may need to change this to 16 or 32 for your system */
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
     
+    if (SDL_Init(SDL_INIT_VIDEO) < 0) /* Initialize SDL's Video subsystem */
+        sdldie("Unable to initialize SDL"); /* Or die on error */
+    
+    
     /* Create our window centered at 512x512 resolution */
-    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                                  800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
+    mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED,
+                                  SDL_WINDOWPOS_CENTERED,
+                                  800, 600, SDL_WINDOW_OPENGL |
+                                  SDL_WINDOW_SHOWN);
     if (!mainwindow) /* Die if creation failed */
         sdldie("Unable to create window");
     
     checkSDLError(__LINE__);
     
     
-    /* This makes our buffer swap syncronized with the monitor's vertical refresh */
-    //SDL_GL_SetSwapInterval(1);
-    /*
-     glToolsSetWorkingDirectory(argv[0]);
-     
-     glutInit(&argc, argv);
-     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
-     glutInitWindowSize(800, 600);
-     glutCreateWindow("Triangle");
-     glutReshapeFunc(ChangeSize);
-     glutDisplayFunc(RenderScene);
-     */
     GLenum err = glewInit();
     if (GLEW_OK != err) {
         fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));