Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jlamarche
committed
Oct 19, 2010
0 parents
commit 50364fb
Showing
108 changed files
with
42,475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
build | |||
*.xcodeproj/*.pbxuser | |||
*.xcodeproj/*.perspectivev3 | |||
.DS_Store | |||
.Spotlight-V100 | |||
*.hidden | |||
*.Trash | |||
/tmp/** | |||
*.hotfiles.btree | |||
/.vol | |||
.svn | |||
.svn/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,120 @@ | |||
#!BPY | |||
|
|||
""" | |||
Name: 'Objective-C Header (.h)' | |||
Blender: 244 | |||
Group: 'Export' | |||
Tooltip: 'Exports header file for use with the OpenGL ES template for iPhone available from http://iphonedevelopment.blogspot.com/' | |||
""" | |||
import Blender | |||
from Blender import * | |||
import bpy | |||
import bpy | |||
import os | |||
|
|||
|
|||
def write_obj(filepath): | |||
out = file(filepath, 'w') | |||
sce = bpy.data.scenes.active | |||
ob = sce.objects.active | |||
mesh = Mesh.New() | |||
mesh.getFromObject(ob.name) | |||
|
|||
editmode = Window.EditMode() | |||
if editmode: Window.EditMode(0) | |||
has_quads = False | |||
for f in mesh.faces: | |||
if len(f) == 4: | |||
has_quads = True | |||
break | |||
|
|||
if has_quads: | |||
oldmode = Mesh.Mode() | |||
Mesh.Mode(Mesh.SelectModes['FACE']) | |||
|
|||
mesh.sel = True | |||
tempob = sce.objects.new(mesh) | |||
mesh.quadToTriangle(0) # more=0 shortest length | |||
oldmode = Mesh.Mode(oldmode) | |||
sce.objects.unlink(tempob) | |||
|
|||
Mesh.Mode(oldmode) | |||
|
|||
objectname = ob.getData(True) | |||
basename = objectname.capitalize() | |||
|
|||
out.write('#import "OpenGLCommon.h"\n\n\n') | |||
|
|||
if (mesh.faceUV): | |||
out.write('static const TexturedVertexData3D %sVertexData[] = {\n' % basename) | |||
for face in mesh.faces: | |||
for (vert, uvert) in zip(face.verts, face.uv): | |||
out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.y, vert.co.z) ) | |||
out.write('/*n:*/{%f, %f, %f}, ' % (vert.no.x, vert.no.y, vert.no.z)) | |||
out.write('/*t:*/{%f, %f}' % ( uvert.x, uvert.y ) ) | |||
out.write('},\n') | |||
out.write('};\n\n') | |||
elif (mesh.vertexColors): | |||
out.write('static const ColoredVertexData3D %sVertexData[] = {\n' % basename) | |||
for face in mesh.faces: | |||
for (vert, color) in zip(face.verts, face.col): | |||
out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.y, vert.co.z) ) | |||
out.write('/*n:*/{%f, %f, %f}, ' % (vert.no.x, vert.no.y, vert.no.z)) | |||
out.write('/*c:*/{%f, %f, %f, %f}' % ( color.r / 255.0, color.g / 255.0, color.b / 255.0, color.a / 255.0) ) | |||
out.write('},\n') | |||
out.write('};\n\n') | |||
else: | |||
out.write | |||
out.write('static const VertexData3D %sVertexData[] = {\n' % basename) | |||
for face in mesh.faces: | |||
for vert in face.verts: | |||
out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.y, vert.co.z) ) | |||
out.write('/*n:*/{%f, %f, %f} ' % (vert.no.x, vert.no.y, vert.no.z)) | |||
out.write('},\n') | |||
out.write('};\n\n') | |||
|
|||
if editmode: Window.EditMode(1) | |||
out.write('#define k%sNumberOfVertices\t%i\n' % (basename, len(mesh.faces) * 3) ) | |||
|
|||
out.write('// Drawing Code:\n') | |||
out.write('// glEnableClientState(GL_VERTEX_ARRAY);\n') | |||
if (mesh.faceUV): | |||
out.write('// glEnableClientState(GL_TEXTURE_COORD_ARRAY);\n') | |||
elif (mesh.vertexColors): | |||
out.write('// glEnableClientState(GL_COLOR_ARRAY);\n') | |||
out.write('// glEnable(GL_COLOR_MATERIAL)\n') | |||
out.write('// glEnableClientState(GL_NORMAL_ARRAY);\n') | |||
out.write('// glVertexPointer(3, GL_FLOAT, sizeof(') | |||
if (mesh.faceUV): | |||
out.write('TexturedVertexData3D') | |||
elif (mesh.vertexColors): | |||
out.write('ColoredVertexData3D') | |||
else: | |||
out.write('VertexData3D') | |||
out.write('), &%sVertexData[0].vertex);\n' % basename) | |||
out.write('// glNormalPointer(GL_FLOAT, sizeof(') | |||
if (mesh.faceUV): | |||
out.write('TexturedVertexData3D') | |||
elif (mesh.vertexColors): | |||
out.write('ColoredVertexData3D') | |||
else: | |||
out.write('VertexData3D') | |||
out.write('), &%sVertexData[0].normal);\n' % basename) | |||
if (mesh.faceUV): | |||
out.write('// glTexCoordPointer(2, GL_FLOAT, sizeof(TexturedVertexData3D), &%sVertexData[0].texCoord);\n' % basename) | |||
elif (mesh.vertexColors): | |||
out.write('// glColorPointer(4, GL_FLOAT, sizeof(ColoredVertexData3D), &%sVertexData[0].color);\n' % basename) | |||
out.write('// glDrawArrays(GL_TRIANGLES, 0, k%sNumberOfVertices);\n' % basename) | |||
out.write('// glDisableClientState(GL_VERTEX_ARRAY);\n') | |||
if (mesh.faceUV): | |||
out.write('// glDisableClientState(GL_TEXTURE_COORD_ARRAY);\n') | |||
elif (mesh.vertexColors): | |||
out.write('// glDisableClientState(GL_NORMAL_ARRAY);\n') | |||
out.write('// glDisable(GL_COLOR_MATERIAL);\n') | |||
out.write('// glDisableClientState(GL_NORMAL_ARRAY);\n\n\n') | |||
|
|||
out.close() | |||
|
|||
|
|||
filename = os.path.splitext(Blender.Get('filename'))[0] | |||
Blender.Window.FileSelector(write_obj, "Export", '%s.h' % filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
#!BPY | |||
|
|||
""" | |||
Name: 'Objective-C Header (.h)' | |||
Blender: 244 | |||
Group: 'Export' | |||
Tooltip: 'Exports header file for use with the OpenGL ES template for iPhone available from http://iphonedevelopment.blogspot.com/' | |||
""" | |||
import Blender | |||
from Blender import Mathutils | |||
from Blender.Mathutils import * | |||
import bpy | |||
import os | |||
|
|||
def write_obj(filepath): | |||
out = file(filepath, 'w') | |||
sce = bpy.data.scenes.active | |||
ob = sce.objects.active | |||
mesh = ob.getData(mesh=1) | |||
objectname = ob.getData(True) | |||
basename = objectname.capitalize() | |||
|
|||
out.write('#import "OpenGLCommon.h"\n\n\n') | |||
out.write('static const TexturedVertexData3D %sVertexData[] = {\n' % basename) | |||
for face in mesh.faces: | |||
for (vert, uvert) in zip(face.v, face.uv): | |||
out.write('\t{/*v:*/{%f, %f, %f}, ' % (vert.co.x, vert.co.y, vert.co.z) ) | |||
out.write('/*n:*/{%f, %f, %f}, ' % (vert.no.x, vert.no.y, vert.no.z)) | |||
out.write('/*t:*/{%f, %f}' % ( uvert.x, uvert.y ) ) | |||
out.write('},\n') | |||
out.write('};\n\n') | |||
|
|||
out.write('#define k%sNumberOfVertices\t%i\n' % (basename, len(mesh.faces) * 3) ) | |||
|
|||
out.write('// Drawing Code:') | |||
out.write('// glEnableClientState(GL_VERTEX_ARRAY);\n') | |||
out.write('// glEnableClientState(GL_TEXTURE_COORD_ARRAY);\n') | |||
out.write('// glEnableClientState(GL_NORMAL_ARRAY);\n') | |||
out.write('// glVertexPointer(3, GL_FLOAT, sizeof(TexturedVertexData3D), &%sVertexData[0].vertex);\n' % basename) | |||
out.write('// glNormalPointer(GL_FLOAT, sizeof(TexturedVertexData3D), &%sVertexData[0].normal);\n' % basename) | |||
out.write('// glTexCoordPointer(2, GL_FLOAT, sizeof(TexturedVertexData3D), &%sVertexData[0].texCoord);\n' % basename) | |||
out.write('// glDrawArrays(GL_TRIANGLES, 0, k%sNumberOfVertices);\n' % basename) | |||
out.write('// glDisableClientState(GL_VERTEX_ARRAY);\n') | |||
out.write('// glDisableClientState(GL_TEXTURE_COORD_ARRAY);\n') | |||
out.write('// glDisableClientState(GL_NORMAL_ARRAY);\n\n\n') | |||
|
|||
out.close() | |||
|
|||
filename = os.path.splitext(Blender.Get('filename'))[0] | |||
Blender.Window.FileSelector(write_obj, "Export", '%s.h' % filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
// | |||
// UIColor-OpenGL.h | |||
// GLTest | |||
// | |||
// Created by Jeff LaMarche on 8/21/08. | |||
// Copyright 2008 __MyCompanyName__. All rights reserved. | |||
// | |||
|
|||
#import <UIKit/UIKit.h> | |||
#import <OpenGLES/EAGL.h> | |||
#import <OpenGLES/ES1/gl.h> | |||
#import <OpenGLES/ES1/glext.h> | |||
#import <OpenGLES/EAGLDrawable.h> | |||
|
|||
@interface UIColor(OpenGL) | |||
- (void)setOpenGLColor; | |||
- (void)setColorArrayToColor:(UIColor *)toColor; | |||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,79 @@ | |||
// | |||
// UIColor-OpenGL.m | |||
// GLTest | |||
// | |||
// Created by Jeff LaMarche on 8/21/08. | |||
// Copyright 2008 __MyCompanyName__. All rights reserved. | |||
// | |||
|
|||
#import "UIColor-OpenGL.h" | |||
|
|||
@implementation UIColor(OpenGL) | |||
- (void)setOpenGLColor | |||
{ | |||
int numComponents = CGColorGetNumberOfComponents(self.CGColor); | |||
const CGFloat *components = CGColorGetComponents(self.CGColor); | |||
if (numComponents == 2) | |||
{ | |||
CGFloat all = components[0]; | |||
CGFloat alpha = components[1]; | |||
glColor4f(all,all, all, alpha); | |||
} | |||
else | |||
{ | |||
|
|||
CGFloat red = components[0]; | |||
CGFloat green = components[1]; | |||
CGFloat blue = components[2]; | |||
CGFloat alpha = components[3]; | |||
glColor4f(red,green, blue, alpha); | |||
} | |||
|
|||
} | |||
- (void)setColorArrayToColor:(UIColor *)toColor | |||
{ | |||
GLfloat *colorArray = malloc(sizeof(GLfloat) * 8); | |||
|
|||
int numComponents = CGColorGetNumberOfComponents(self.CGColor); | |||
const CGFloat *components = CGColorGetComponents(self.CGColor); | |||
|
|||
|
|||
if (numComponents == 2) | |||
{ | |||
colorArray[0] = components[0]; | |||
colorArray[1] = components[0]; | |||
colorArray[2] = components[0]; | |||
colorArray[3] = components[1]; | |||
} | |||
else | |||
{ | |||
// Assuming RGBA if not grayscale | |||
colorArray[0] = components[0]; | |||
colorArray[1] = components[1]; | |||
colorArray[2] = components[2]; | |||
colorArray[3] = components[3]; | |||
} | |||
|
|||
int otherColorNumComponents = CGColorGetNumberOfComponents(toColor.CGColor); | |||
const CGFloat *otherComponents = CGColorGetComponents(toColor.CGColor); | |||
if (otherColorNumComponents == 2) | |||
{ | |||
colorArray[4] = otherComponents[0]; | |||
colorArray[5] = otherComponents[0]; | |||
colorArray[6] = otherComponents[0]; | |||
colorArray[7] = otherComponents[1]; | |||
} | |||
else | |||
{ | |||
// Assuming RGBA if not grayscale | |||
colorArray[4] = otherComponents[0]; | |||
colorArray[5] = otherComponents[1]; | |||
colorArray[6] = otherComponents[2]; | |||
colorArray[7] = otherComponents[3]; | |||
} | |||
|
|||
glColorPointer (4, GL_FLOAT, 4*sizeof(GLfloat), colorArray); | |||
free(colorArray); | |||
|
|||
} | |||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
/* | |||
* JDLGLUtils.h | |||
* Space Castle | |||
* | |||
* Created by Jeff LaMarche on 9/27/08. | |||
* Copyright 2008 __MyCompanyName__. All rights reserved. | |||
* | |||
*/ | |||
#import <Foundation/Foundation.h> | |||
#import <OpenGLES/ES1/gl.h> | |||
#import <CoreGraphics/CoreGraphics.h> | |||
|
|||
|
|||
void GLDrawCircle (int circleSegments, CGFloat circleSize, CGPoint center, bool filled); | |||
void GLDrawEllipse (int segments, CGFloat width, CGFloat height, CGPoint center, bool filled); | |||
void GLDrawSpokes (int spokeCount, CGFloat radius, CGPoint center); | |||
void GLDrawEllipticalSpokes(int spokeCount, CGFloat width, CGFloat height, CGPoint center); | |||
void GLDrawEllipticalSpokesWithGradient(int spokeCount, CGFloat width, CGFloat height, CGPoint center, UIColor *innerColor, UIColor *outerColor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
/* | |||
* JDLGLUtils.c | |||
* Space Castle | |||
* | |||
* Created by Jeff LaMarche on 9/27/08. | |||
* Copyright 2008 __MyCompanyName__. All rights reserved. | |||
* | |||
*/ | |||
|
|||
#include "JDLGLUtils.h" | |||
#include <math.h> | |||
#include "Constants.h" | |||
#include "UIColor-OpenGL.h" | |||
|
|||
void GLDrawCircle (int circleSegments, CGFloat circleSize, CGPoint center, bool filled) | |||
{ | |||
GLDrawEllipse(circleSegments, circleSize, circleSize, center, filled); | |||
} | |||
void GLDrawEllipse (int segments, CGFloat width, CGFloat height, CGPoint center, bool filled) | |||
{ | |||
glTranslatef(center.x, center.y, 0.0); | |||
GLfloat vertices[segments*2]; | |||
int count=0; | |||
for (GLfloat i = 0; i < 360.0f; i+=(360.0f/segments)) | |||
{ | |||
vertices[count++] = (cos(degreesToRadian(i))*width); | |||
vertices[count++] = (sin(degreesToRadian(i))*height); | |||
} | |||
glVertexPointer (2, GL_FLOAT , 0, vertices); | |||
glDrawArrays ((filled) ? GL_TRIANGLE_FAN : GL_LINE_LOOP, 0, segments); | |||
} | |||
void GLDrawSpokes (int spokeCount, CGFloat radius, CGPoint center) | |||
{ | |||
GLDrawEllipticalSpokes(spokeCount, radius, radius, center); | |||
} | |||
void GLDrawEllipticalSpokes(int spokeCount, CGFloat width, CGFloat height, CGPoint center) | |||
{ | |||
glTranslatef(center.x, center.y, 0.0); | |||
for (GLfloat i = 0; i < 360.0f; i+=(360.0f/spokeCount)) | |||
{ | |||
GLfloat vertices[4] = {0.0, 0.0, cos(degreesToRadian(i))*width, sin(degreesToRadian(i))*height}; | |||
glVertexPointer(2, GL_FLOAT, 0, vertices); | |||
glDrawArrays (GL_LINES, 0, 2); | |||
} | |||
} | |||
void GLDrawEllipticalSpokesWithGradient(int spokeCount, CGFloat width, CGFloat height, CGPoint center, UIColor *innerColor, UIColor *outerColor) | |||
{ | |||
glTranslatef(center.x, center.y, 0.0); | |||
for (GLfloat i = 0; i < 360.0f; i+=(360.0f/spokeCount)) | |||
{ | |||
glEnableClientState (GL_COLOR_ARRAY); | |||
[innerColor setColorArrayToColor:outerColor]; | |||
GLfloat vertices[4] = {0.0, 0.0, cos(degreesToRadian(i))*width, sin(degreesToRadian(i))*height}; | |||
glVertexPointer(2, GL_FLOAT, 0, vertices); | |||
glDrawArrays (GL_LINES, 0, 2); | |||
glDisableClientState(GL_COLOR_ARRAY); | |||
} | |||
} |
33 changes: 33 additions & 0 deletions
33
OpenGL ES 1.1 Project Template/Classes/ConstantsAndMacros.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
// | |||
// ConstantsAndMacros.h | |||
// Particles | |||
// | |||
|
|||
// How many times a second to refresh the screen | |||
#if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR | |||
#define kRenderingFrequency 15.0 | |||
#define kInactiveRenderingFrequency 5.0 | |||
#else | |||
#define kRenderingFrequency 30.0 | |||
#define kInactiveRenderingFrequency 3.0 | |||
#endif | |||
// For setting up perspective, define near, far, and angle of view | |||
#define kZNear 0.01 | |||
#define kZFar 1000.0 | |||
#define kFieldOfView 45.0 | |||
// Defines whether to setup and use a depth buffer | |||
#define USE_DEPTH_BUFFER 1 | |||
// Set to 1 if you want it to attempt to create a 2.0 context | |||
#define kAttemptToUseOpenGLES2 0 | |||
|
|||
#define QUATERNION_TRACE_ZERO_TOLERANCE 0.1 | |||
|
|||
// Macros | |||
#define DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0 * M_PI) | |||
|
|||
// Debug Loggers | |||
#define NSStubLog() NSLog(@"%s", __PRETTY_FUNCTION__) | |||
#define NSDebugPrintMatrix(matrix) for (int i = 0; i < 4; i ++) \ | |||
NSLog(@"[%f] [%f] [%f] [%f]", matrix[i], matrix[i+4], matrix[i+8], matrix[i+12]) | |||
|
|||
#define NSDebugPrintQuaternion(quat) NSLog(@"Quaternion: [%f] [%f] [%f] [%f]", quat.x, quat.y, quat.z, quat.w) |
Oops, something went wrong.