Print OpenGL error and description

Print OpenGL error:

1
2
3
4
GLenum err = glGetError();
if (err != GL_NO_ERROR) {
   NSLog(@"Error glGetError: glError: 0x%04X", err);
}

GL_INVALID_ENUM​, 0×0500: Given when an enumeration parameter is not a legal enumeration for that function. This is given only for local problems; if the spec allows the enumeration in certain circumstances, and other parameters or state dictate those circumstances, then GL_INVALID_OPERATION​ is the result instead.

GL_INVALID_VALUE​, 0×0501: Given when a value parameter is not a legal value for that function. This is only given for local problems; if the spec allows the value in certain circumstances, and other parameters or state dictate those circumstances, then GL_INVALID_OPERATION is the result instead.

GL_INVALID_OPERATION​, 0×0502: Given when the set of state for a command is not legal for the parameters given to that command. It is also given for commands where combinations of parameters define what the legal parameters are.

GL_OUT_OF_MEMORY​, 0×0503: Given when performing an operation that can allocate memory, but the memory cannot be allocated. The results of OpenGL functions that return this error are undefined; it is allowable for partial operations to happen.

GL_INVALID_FRAMEBUFFER_OPERATION​, 0×0506: Given when doing anything that would attempt to read from or write/render to a framebuffer that is not complete, as defined here.

GL_STACK_OVERFLOW​1, 0×0503: Given when a stack pushing operation cannot be done because it would overflow the limit of that stack’s size.

GL_STACK_UNDERFLOW​1, 0×0504: Given when a stack popping operation cannot be done because the stack is already at its lowest point.

GL_TABLE_TOO_LARGE​1, 0×8031: Part of the ARB_imaging extension.

Tags: ,

Leave a Comment

 

Switch developer folder

1
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

Tags:

Leave a Comment

 

Convert NSDictionary to XML Data

Convert NSDictionary to XML Data

1
2
3
4
NSStirng *error;
NSDate *xmlData = [NSPropertyListSerialization dataFromPropertyList:dictionary
                                                             format:NSPropertyListXMLFormat_v1_0
                                                   errorDescription:&error];

Tags: , ,

Leave a Comment

 

GLKit, Opengl ES 2.0 Picking Ray for select object

Solution for picking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
GLKVector4 normalisedVector = GLKVector4Make((2 * position.x / self.view.bounds.size.width - 1),
                                                 (2 * (self.view.bounds.size.height-position.y) / self.view.bounds.size.height - 1),  
                                                   -1,
                                                   1);

GLKMatrix4 inversedMatrix = GLKMatrix4Invert(_modelViewProjectionMatrix, nil);

GLKVector4 near_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector);

near_point.v[3] = 1.0/near_point.v[3];
near_point = GLKVector4Make(near_point.v[0]*near_point.v[3], near_point.v[1]*near_point.v[3], near_point.v[2]*near_point.v[3], 1);

normalisedVector.z = 1.0;
GLKVector4 far_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector);

far_point.v[3] = 1.0/far_point.v[3];
far_point = GLKVector4Make(far_point.v[0]*far_point.v[3], far_point.v[1]*far_point.v[3], far_point.v[2]*far_point.v[3], 1);

On Stackoverflow

Tags: , , , , , ,

Leave a Comment

 

Disable ARC for a single file in a project

It is possible to disable ARC for individual files by adding the

1
-fno-objc-arc

compiler flag for those files.

You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box.

[Read more...]

Tags: , ,

Leave a Comment

 

New Objective-C literal syntax (Apple LLVM 4.0 compiler in the Xcode 4.4 beta)

Copy from blog.ablepear.com.

If you’ve done any Objective-C programming, you’ve seen the NSString literal syntax:

1
2
3
4
5
6
// NSString literal
NSString *name1 = @"Lana Kane";

// creating NSString from a C string literal
NSString *name2 = [NSString stringWithCString:"Sterling Archer"
                                    encoding:NSUTF8StringEncoding];

[Read more...]

Tags: , , , , ,

Leave a Comment

 

iOS javascript device rotation

Tags: , , , ,

Leave a Comment

 

Download Tools for Xcode 4.3

If you need tools for Xcode 4.3, download tools!

Tags: , , , , ,

Leave a Comment

 

AsyncURLConnection with pause/resume and progress +block’s

I rewrite one class with async connection, and add progress block and pause/resume.

Example usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
NSString *comboUrl = @"http://support.apple.com/downloads/DL1484/en_US/MacOSXUpdCombo10.7.3.dmg";
AsyncURLConnection *aConnection = [AsyncURLConnection request:comboUrl
                  completeBlock:^(NSData *data, NSString *url) {
                      [data writeToFile:filename atomically:NO];
                  } errorBlock:^(NSError *error) {
                      NSLog(@"Error %f", error);
                  } progress:^(float progress) {
                      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                          /* process downloaded data in Concurrent Queue */
                          dispatch_async(dispatch_get_main_queue(), ^{
                              /* update UI on Main Thread */
                          });
                      });
                      NSLog(@"progress %f", progress);
                  }];

Very easy to use blocks of AsyncURLConnection (aka async URLConnection) and NSProgressIndicator indicator. You can implement progress bar of downloading in your mac os x application like this example.

1
2
3
4
5
6
7
8
NSProgressIndicator *horizontal = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(200, 300, 200, 12)];
    [horizontal setStyle:NSProgressIndicatorBarStyle];
    [horizontal setIndeterminate:NO];
    [horizontal setControlSize:NSSmallControlSize];
    [horizontal setDisplayedWhenStopped:YES];
    [horizontal setMaxValue:1];
    [self addSubview:horizontal];
    [horizontal release];

And just set progress value.

1
2
3
4
5
6
7
8
9
         progress:^(float progress) {
                          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                          /* process downloaded data in Concurrent Queue */
                          dispatch_async(dispatch_get_main_queue(), ^{
                              /* update UI on Main Thread */
                               [horizontal setDoubleValue:progress];
                          });
                      });
                  }];

[Read more...]

Tags: , , , , , , , ,

Leave a Comment

 

ANSI escape sequences for coloring

More about ANSI escape code

I modify my twitter script from previous post and now timeline looks like this:

Tags: , , , ,

Leave a Comment

 

Page 1 of 2012345...1020...Last »