Wednesday, May 26, 2010
Working on Blobs&Globs
Sunday, January 17, 2010
Textures, Lighting, and Future Approach
Sunday, December 6, 2009
Drawing Rotating Pyramids (Tutorial)
#import
#include
#include
//Color Depth
#define BITS_PER_PIXEL 32.0
//Depth of Z Buffer
#define DEPTH_SIZE 32.0
//Frames per Second
#define DEFAULT_FRAME_RATE 60.0f
@interface MyOpenGLView : NSOpenGLView
{
//The timer that runs 60 times/second
NSTimer *renderTimer;
}
//Keep track of rotation angle
float rotTri = 0.0f;
//Initialization function for OpenGL
- (void)initGL;
//Function to draw a pyramid
static void drawAnObject();
@end
//Run at start
-(void)awakeFromNib
{
NSOpenGLPixelFormat *nsglFormat;
//Specify Attributes to allow screen to use various buffers
NSOpenGLPixelFormatAttribute attr[] =
{
//Enable Z sorting (make sure that polygons in front will overlap those in back)
NSOpenGLPFADoubleBuffer,
//Use Hardware Acceleration for graphics
NSOpenGLPFAAccelerated,
//Specify color depth
NSOpenGLPFAColorSize, BITS_PER_PIXEL,
//Specify Z depth
NSOpenGLPFADepthSize, DEPTH_SIZE,
//Anti-Aliasing:
NSOpenGLPFASampleBuffers, 8,
NSOpenGLPFASamples, 32,
NSOpenGLPFAMultisample,
0
};
//Set pixel format to include the attributes specified in the array attr[]
nsglFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
//Use the pixel format for the openGL view
[self setPixelFormat:nsglFormat];
//Initialize the view
[self initGL];
//Redraw view when window changes size
[self setPostsFrameChangedNotifications: YES];
//Update every 60 times a second
renderTimer = [NSTimer timerWithTimeInterval:1.0/60.0
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
//Activate timer to fire
[[NSRunLoop currentRunLoop] addTimer:renderTimer
forMode:NSDefaultRunLoopMode];
//Ensure timer fires during resize
[[NSRunLoop currentRunLoop] addTimer:renderTimer
forMode:NSEventTrackingRunLoopMode];
}
//Action to run when the timer is fired
- (void)timerFired:(id)sender
{
//Increase the rotation angle
rotTri += 1.0f;
//Tell the screen it needs to refresh
[self setNeedsDisplay:YES];
}
//Setup OpenGL view
- (void)initGL
{
printf("initGL\n");
// Synchronize buffer swaps with vertical refresh rate
GLint swapInt = 1;
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
//Apply Future Operations to The Projection Matrix
glMatrixMode(GL_PROJECTION);
//Reset The Projection Matrix
glLoadIdentity();
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,640.0f/480.0f,0.1f,100.0f);
//Select The Modelview Matrix
glMatrixMode(GL_MODELVIEW);
// Reset The Modelview Matrix
glLoadIdentity();
glShadeModel(GL_SMOOTH); //Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //set clear color to black
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}
//Function to draw a pyramid
static void drawAnObject()
{
//Draw a 3-sided pyramid
glBegin(GL_TRIANGLES);
//DAC (counterclockwise points)
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
//DCB
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
//CAB
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
//BAD
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glEnd();
}
//Draw Loop
- (void) drawRect: (NSRect) bounds
{
//Clear the screen and depth buffer
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//Reset the current modelview matrix
glLoadIdentity();
//Move along the x and z axis
glTranslatef( -1.0f, 0.0f, -5.0f );
//rotate the modelview matrix by an angle of rotTri around the vector <1,>
glRotatef( rotTri,1.0f, 1.0f, 1.0f );
//Draw a pyramid to the buffers
drawAnObject();
//Reset Modelview
glLoadIdentity();
glTranslatef( 1.2f, 0.5f, -5.0f );
glRotatef( -5.0f*rotTri,0.0f, 1.0f, 0.0f );
drawAnObject();
//Display the buffer content to the screen
[ [ self openGLContext ] flushBuffer ];
}
Sunday, November 29, 2009
First Steps into 3D
//Draw a 3-sided pyramid
glBegin(GL_TRIANGLES);
//DAC (points must be listed in counterclockwise order)
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
//DCB
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
//CAB
glColor3f(0.0f, 0.0f,1.0f); //BLUE
glVertex3f(-1.0f, -1.0f,-0.798f); //C
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
//BAD
glColor3f(1.0f, 0.0f,1.0f); //Violet
glVertex3f(0.0f,1.0f,-0.798f); //B
glColor3f(0.0f, 1.0f,0.0f); //GREEN
glVertex3f(0.0f, -0.333f,0.798f); //A
glColor3f(1.0f, 0.0f,0.0f); //RED
glVertex3f(1.0f, -1.0f,-0.798f); //D
glEnd();
Beginning OpenGL
Saturday, April 18, 2009
CINGO! Version 1.0 is in the App Store!
Friday, April 10, 2009
Post Immersion Update sqrt(9)
"Dear True Star Design,As you can see, my application was rejected from the App Store. When I tested my application, I found nothing wrong with it. Then, I deleted it from my iPhone Simulator and was able to produce the error instantly. It turns out that the file responsible for displaying the "Change Game Look" button had somehow moved to a sub-directory of my main project folder, and the OS could not locate it. I had not detected this error because the file had been present in an earlier version and was not cleared whenever I simply rebuilt the code for the application. Other than that I now probably have to wait for another week for my application to be approved, no harm done: I uploaded a new binary with the file moved to the correct folder.
At this time, CINGO! cannot be posted to the App Store because it is crashing on iPhone OS 2.2.1 and Mac OS X 10.5.6.
Steps to Reproduce:
1. Launch App
2. Press "Change Game Lock" and the app crashes
In order for your application to be reconsidered for the App Store, please resolve this issue and upload your new binary to iTunes Connect."
Wednesday, April 8, 2009
Post Immersion Update 0002
Sunday, March 29, 2009
Post Immersion Update 0001
Monday, March 23, 2009
Post Immersion Update 0000
Friday, March 13, 2009
Thursday, March 12, 2009
iPhone Journal (asc(Q)-63)
Wednesday, March 11, 2009
iPhone Journal (asc(R)-65)
Today, I planned to finish the undo functionality, add instructions, and to reduce memory leaks. I was able to accomplish all this and more. I finished the undo button much more rapidly than I had hoped and reduced some of the memory problems at the same time. I then created the instructions view. I soon discovered that the instructions cannot all be displayed on the same page, and so I modified the view controller for the instructions to handle multiple pages. During this process, I discovered a much simpler way to add and remove views than I had been using previously. I also fixed a major error present in the game view in regard to promoting a diamond to a mixed "power" piece.