1. NSArray* familys = [UIFont familyNames];  
  2.   
  3. for (int i = 0; i<[familys count]; i++) {  
  4.       
  5.     NSString* family = [familys objectAtIndex:i];  
  6.     NSLog(@"\r\n\r\nFontfamily:%@\r\n=====",family);  
  7.   
  8.     NSArray* fonts = [UIFont fontNamesForFamilyName:family];  
  9.   
  10.     for (int j = 0; j<[fonts count]; j++) {  
  11.       
  12.         NSLog(@"%@",[fonts objectAtIndex:j]);  
  13.     }  

beanway 發表在 痞客邦 留言(0) 人氣()

http://www.slideshare.net/littlebtc/git-5528339


beanway 發表在 痞客邦 留言(0) 人氣()

http://gamerboom.com/archives/32002


beanway 發表在 痞客邦 留言(0) 人氣()

很多obj c 的 demo

beanway 發表在 痞客邦 留言(0) 人氣()

void ccFillPoly( CGPoint *poli, int points, BOOL closePolygon )
{
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// Needed states: GL_VERTEX_ARRAY,
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

beanway 發表在 痞客邦 留言(0) 人氣()

NSString *myNSString1 = [NSString stringWithUTF8String:"Hello"];

beanway 發表在 痞客邦 留言(0) 人氣()

-(void)draw{

  CGSize s = [[CCDirector sharedDirector] winSize];

beanway 發表在 痞客邦 留言(0) 人氣()

DeviceDetection import進來後就可直接使用,非常方便的工具

#import "DeviceDetection.h"

beanway 發表在 痞客邦 留言(0) 人氣()

/* cocos2d for iPhone
 *
 * http://www.cocos2d-iphone.org
 *
 * Copyright (C) 2009 Jason Booth
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the 'cocos2d for iPhone' license.
 *
 * You will find a copy of this license within the cocos2d for iPhone
 * distribution inside the "LICENSE" file.
 *
 */
 
#import <Foundation/Foundation.h>
#import "CocosNode.h"
#import "Sprite.h"
#import "OpenGL_Internal.h"
 
enum  
{
        kImageFormatJPG = 0,
        kImageFormatPNG = 1
};
 
 
/**
 RenderTexture is a generic rendering target. To render things into it,
 simply construct a render target, call begin on it, call visit on any cocos
 scenes or objects to render them, and call end. For convienience, render texture
 adds a sprite as it's display child with the results, so you can simply add
 the render texture to your scene and treat it like any other CocosNode.
 There are also functions for saving the render texture to disk in PNG or JPG format.
 */
@interface RenderTexture : CocosNode 
{
        GLuint fbo;
        GLint oldFBO;
        Texture2D* texture;
        Sprite* sprite;
}
 
/** sprite being used */
@property (readwrite, assign) Sprite* sprite;
 
/** creates a RenderTexture object with width and height */
+(id)renderTextureWithWidth:(int)width height:(int)height;
/** initializes a RenderTexture object with width and height */
-(id)initWithWidth:(int)width height:(int)height;
-(void)begin;
-(void)end;
/* get buffer as UIImage */
-(UIImage *)getUIImageFromBuffer;
/** saves the texture into a file */
-(BOOL)saveBuffer:(NSString*)name;
/** saves the texture into a file. The format can be JPG or PNG */
-(BOOL)saveBuffer:(NSString*)name format:(int)format;
/** clears the texture with a color */
-(void)clear:(float)r g:(float)g b:(float)b a:(float)a;
@end
 
 
 
 
 
/* cocos2d for iPhone
 *
 * http://www.cocos2d-iphone.org
 *
 * Copyright (C) 2009 Jason Booth
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the 'cocos2d for iPhone' license.
 *
 * You will find a copy of this license within the cocos2d for iPhone
 * distribution inside the "LICENSE" file.
 *
 */
 
#import "RenderTexture.h"
#import "cocos2d.h"
#include "glu.h"
 
@implementation RenderTexture
 
@synthesize sprite;
 
+(id)renderTextureWithWidth:(int)w height:(int)h
{
  self = [[[RenderTexture alloc] initWithWidth:w height:h] autorelease];
  return self;
}
 
-(id)initWithWidth:(int)w height:(int)h
{
        self = [super init];
        if (self)
        {
                glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
                Texture2DPixelFormat format = kTexture2DPixelFormat_RGBA8888;  
                // textures must be power of two squared
                int pow = 8;
                while (pow < w || pow < h) pow*=2;
 
                void *data = malloc((int)(pow * pow * 4));
                memset(data, 0, (int)(pow * pow * 4));
                texture = [[[Texture2D alloc] initWithData:data pixelFormat:format pixelsWide:pow pixelsHigh:pow contentSize:CGSizeMake(w, h)] autorelease];
                free( data );
 
                // generate FBO
                glGenFramebuffersOES(1, &fbo);
                glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);
 
                // associate texture with FBO
                glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture.name, 0);
 
                // check if it worked (probably worth doing :) )
                GLuint status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
                if (status != GL_FRAMEBUFFER_COMPLETE_OES)
                {
                  [NSException raise:@"Render Texture" format:@"Could not attach texture to framebuffer"];
                }
                sprite = [Sprite spriteWithTexture:texture];
                [sprite setScaleY:-1];
                [self addChild:sprite];
                glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
        }
        return self;
}
 
-(void)dealloc
{
        [self removeAllChildrenWithCleanup:YES];
        glDeleteFramebuffersOES(1, &fbo);
        [super dealloc];
}
 
-(void)begin
{
        glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbo);//Will direct drawing to the frame buffer created above
        glDisable(GL_DITHER);
}
 
-(void)clear:(float)r g:(float)g b:(float)b a:(float)a
{
        [self begin];
        glColorMask(TRUE, TRUE, TRUE, TRUE);
        glClearColor(r, g, b, a);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glColorMask(TRUE, TRUE, TRUE, FALSE);
        [self end];
}
 
-(void)end
{       
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
}
 
-(BOOL)saveBuffer:(NSString*)name
{
        return [self saveBuffer:name format:kImageFormatJPG];
}
 
-(BOOL)saveBuffer:(NSString*)fileName format:(int)format
{
        UIImage *myImage                                = [self getUIImageFromBuffer];
 
        NSArray *paths                                  = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory    = [paths objectAtIndex:0];
        NSString *fullPath                              = [documentsDirectory stringByAppendingPathComponent:fileName];
 
        NSData *data;
 
        if (format == kImageFormatPNG)
                data = UIImagePNGRepresentation(myImage);
        else
                data = UIImageJPEGRepresentation(myImage, 1.0f);
 
        return [data writeToFile:fullPath atomically:YES];
}
 
/* get buffer as UIImage */
-(UIImage *)getUIImageFromBuffer
{
        int tx = texture.contentSize.width;
        int ty = texture.contentSize.height;
 
        int bitsPerComponent                    = 8;
        int bitsPerPixel                                = 32;
        int bytesPerPixel                               = (bitsPerComponent * 4)/8;
        int bytesPerRow                                 = bytesPerPixel * tx;
        NSInteger myDataLength                  = bytesPerRow * ty;
 
        unsigned char buffer[myDataLength];
 
        [self begin];
        glReadPixels(0,0,tx,ty,GL_RGBA,GL_UNSIGNED_BYTE, &buffer);
        [self end];
        /*
         CGImageCreate(size_t width, size_t height,
         size_t bitsPerComponent, size_t bitsPerPixel, size_t bytesPerRow,
         CGColorSpaceRef space, CGBitmapInfo bitmapInfo, CGDataProviderRef provider,
         const CGFloat decode[], bool shouldInterpolate,
         CGColorRenderingIntent intent)
         */
        // make data provider with data.
 
        CGBitmapInfo bitmapInfo                 = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault;
        CGDataProviderRef provider              = CGDataProviderCreateWithData(NULL, buffer, myDataLength, NULL);
        CGColorSpaceRef colorSpaceRef   = CGColorSpaceCreateDeviceRGB();
        CGImageRef iref                                 = CGImageCreate(tx, ty,
                                                                                        bitsPerComponent, bitsPerPixel, bytesPerRow,
                                                                                        colorSpaceRef, bitmapInfo, provider,
                                                                                        NULL, false,
                                                                                        kCGRenderingIntentDefault);
        /* Create a bitmap context. The context draws into a bitmap which is `width'
         pixels wide and `height' pixels high. The number of components for each
         pixel is specified by `colorspace', which may also specify a destination
         color profile. The number of bits for each component of a pixel is
         specified by `bitsPerComponent'. The number of bytes per pixel is equal
         to `(bitsPerComponent * number of components + 7)/8'. Each row of the
         bitmap consists of `bytesPerRow' bytes, which must be at least `width *
         bytes per pixel' bytes; in addition, `bytesPerRow' must be an integer
         multiple of the number of bytes per pixel. `data' points a block of
         memory at least `bytesPerRow * height' bytes. `bitmapInfo' specifies
         whether the bitmap should contain an alpha channel and how it's to be
         generated, along with whether the components are floating-point or
         integer.
 
         CGContextRef CGBitmapContextCreate(void *data, size_t width,
         size_t height, size_t bitsPerComponent, size_t bytesPerRow,
         CGColorSpaceRef colorspace, CGBitmapInfo bitmapInfo)
         */
        uint32_t* pixels                                = (uint32_t *)malloc(myDataLength);
        CGContextRef context                    = CGBitmapContextCreate(pixels, tx,
                                                                                                                        ty, CGImageGetBitsPerComponent(iref), CGImageGetBytesPerRow(iref),
                                                                                                                        CGImageGetColorSpace(iref), bitmapInfo);
        CGContextTranslateCTM(context, 0.0, ty);
        CGContextScaleCTM(context, 1.0, -1.0);
        CGContextDrawImage(context, CGRectMake(0.0, 0.0, tx, ty), iref);   
        CGImageRef outputRef                    = CGBitmapContextCreateImage(context);
        UIImage* image                                  = [[UIImage alloc] initWithCGImage:outputRef];
 
        free(pixels);
        CGImageRelease(iref);
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpaceRef);
        CGDataProviderRelease(provider);
        CGImageRelease(outputRef);
 
        return [image autorelease];
}
@end

 


beanway 發表在 痞客邦 留言(0) 人氣()

-(CCTexture2D*) UIImageToCCTexture2D

{

beanway 發表在 痞客邦 留言(0) 人氣()

1 23