'Objective-C & OpenGL ES'에 해당되는 글 6건
- 2009/08/25 [cocos2d] Menu - 사용법
- 2009/08/05 [iphone,sqlite3] no such table 오류가 날 경우 / 연동방법
- 2009/07/30 Texture2D 확장해서 스프라이트 에니...
- 2009/07/28 [Objective-C] Categories 의 활용
- 2009/07/25 [Objective-c NSArray] 사용법
- 2009/07/22 [iPhone,Objective-C,OpenGL ES] 2의 승수 사이즈가 필요 한가..
Menu *menu = [Menu menuWithItems:image, nil];
image.position = cpv( -135, -185);
[self addChild: menu z:2];
[iphone,sqlite3] no such table 오류가 날 경우 / 연동방법

-(void) readAnimalsFromDatabase {
// Setup the database object
sqlite3 *database;
// Init the animals Array
// animals = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([[self dataFilePath] UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
NSString* sqlStatement = [NSString stringWithFormat:@"select * from s1"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
int idx = sqlite3_column_int( compiledStatement, 0 );
int level = sqlite3_column_int( compiledStatement, 1 );
int c1 = sqlite3_column_int( compiledStatement, 2 );
int c2 = sqlite3_column_int( compiledStatement, 3 );
int c3 = sqlite3_column_int( compiledStatement, 4 );
// Create a new animal object with the data from the database
// Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
// Add the animal object to the animals Array
// [animals addObject:animal];
// [animal release];
}
}
else
{
NSString* msg = [[NSString alloc] initWithFormat:@"%s", sqlite3_errmsg( database )];
NSLog( @"Failed to open database with message '%s'.", sqlite3_errmsg( database ) );
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
** 연동 방법에 대해서는 따로 적지를 않았습니다.
-(void) checkAndCreateDatabase{
// Check if the SQL database has already been saved to the users phone, if not then copy it over
BOOL success;
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:[self dataFilePath]];
// If the database already exists then return without doing anything
if(success) return;
// If not then proceed to copy the database from the application to the users filesystem
// Get the path to the database in the application package
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kFilename];
// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:databasePathFromApp toPath:[self dataFilePath] error:nil];
[fileManager release];
}
위의 코드를 수행하게 되면 document에 데이터가 없다면 복사를 수행하라는 의미의 코드인듯 합니다.( 사실 이 부분은 아직 잘 모름 )
그래서 위의 함수를 적용 및 호출을 아래와 같이 해주니까.
제대로 데이터가 불러와 지더군요.
- (id) init
{
if (self = [super init])
{
touchPos = CGPointMake(0, 0);
gameState = kLogo;
logoBack = [[LogoBack alloc] init];
// Execute the "checkAndCreateDatabase" function
[self checkAndCreateDatabase];
// Query the database for all animal records and construct the "animals" array
[self readAnimalsFromDatabase];
}
return self;
}
위의 내용에 대해서 실제적인 코드는 여기 압축을 해서 올리지 못하지만,
sqlite3의 내용을 조금 숙지 하셨다면 금방 이해 하시리라 믿습니다. ^^
이거 가지고 조금 삽질을 했네요.
다행이 이 코드를 보면서 다른 면을 보게 되서 더 기쁘네요 ^^
#import <Foundation/Foundation.h>
#import "Texture2D.h"
@interface Texture2DEx2 : Texture2D {
CGPoint tileSize;
CGPoint frameSize;
int curIndex;
int Delay;
int Tick;
}
@property CGPoint tileSize;
@property CGPoint frameSize;
@property int curIndex;
@property int Delay;
@property int Tick;
- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay;
- (void) drawAtPointTest:(CGPoint)point;
@end
#import "Texture2DEx2.h"
@implementation Texture2DEx2
@synthesize tileSize;
@synthesize frameSize;
@synthesize curIndex;
@synthesize Delay;
@synthesize Tick;
- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay
{
self.tileSize = ts;
self.frameSize = fs;
self.Delay = delay;
self.Tick = 0;
}
- (void) drawAtPointTest:(CGPoint)point
{
if( Tick > Delay )
{
Tick = 0;
curIndex++;
if( curIndex >= frameSize.x )
{
curIndex = 0;
}
}
Tick++;
GLfloat leftTc = tileSize.x * curIndex / _width;
GLfloat rightTc = tileSize.x * (curIndex+1) / _width;
GLfloat coordinates[] = { leftTc, _maxT,
rightTc, _maxT,
leftTc, 0,
rightTc, 0 };
// 넓이와 높이는 타일의 사이즈로 교체
GLfloat width = tileSize.x,
height = tileSize.y;
GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,
width / 2 + point.x, -height / 2 + point.y, 0.0,
-width / 2 + point.x, height / 2 + point.y, 0.0,
width / 2 + point.x, height / 2 + point.y, 0.0 };
glBindTexture(GL_TEXTURE_2D, _name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@end
Texture2DEx2 *bluePlaneEx;
@property (nonatomic, retain) Texture2DEx2 *bluePlaneEx;
if (bluePlaneEx == nil) { self.bluePlaneEx = [[Texture2DEx2 alloc] initWithImage: [UIImage imageNamed:@"bluePlane2.png"]]; glBindTexture(GL_TEXTURE_2D, sprite.name); // 타일 사이즈, 이미지 내부 프레임 개수, 딜레이 타임(호출타임) [self.bluePlaneEx TileSize:CGPointMake(63.0, 55.0) FrameSize:CGPointMake(3, 1) Delay:10]; } [bluePlaneEx drawAtPointTest:CGPointMake(Pos.x, Pos.y)];
#import <Foundation/Foundation.h>
#import "Texture2D.h"
@interface Texture2D (SpriteAnimation)
- (void) drawAtPointTest:(CGPoint)point;
@end
#import "Texture2DEx.h"
@implementation Texture2D (SpriteAnimation)
- (void) drawAtPointTest:(CGPoint)point
{
_maxS = 63.0 / 256.0; // test
GLfloat coordinates[] = { 0, _maxT,
_maxS, _maxT,
0, 0,
_maxS, 0 };
GLfloat width = (GLfloat)_width * _maxS,
height = (GLfloat)_height * _maxT;
width = 63.0; // test
GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,
width / 2 + point.x, -height / 2 + point.y, 0.0,
-width / 2 + point.x, height / 2 + point.y, 0.0,
width / 2 + point.x, height / 2 + point.y, 0.0 };
glBindTexture(GL_TEXTURE_2D, _name);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
@end
## Style1
NSArray* array = [NSArray arrayWithObjects:object1, object2, object3 nil];
NSEnumerator* enumerator = [array objectEnumerator];
NSString* aString = @"son";
id anObject = [enumerator nextObject];
while (anObject != nil)
{
[anObject doSomethingWithString:aString];
anObject = [enumerator nextObject];
}
## Style2
NSArray* array = [NSArray arrayWithObjects:object1, object2, object3 nil];
NSEnumerator* enumerator = [array objectEnumerator];
NSString* aString = @"son";
id anObject = nil;
while ((anObject = [enumerator nextObject]))
{
[anObject doSomethingWithString:aString];
}
##Style3
NSArray* array = ''';
for(id object in someContainer)
{
...
}
[iPhone,Objective-C,OpenGL ES] 2의 승수 사이즈가 필요 한가..

CrashingLanding 인가..
그 소스를 기반 코드로 해서 지금 다른 프로그램을 좀 만들고 있다.
Objective-C의 코딩도 아직 익숙하지 않고,
하지만.. 오픈지엘 코드는 조금은.. 손에 익은 터라..
오늘 작업 하면서 비행기의 스프라이트가 한 이미지에 3장 짜리로 구성되어져 있었다.
189 * 55 인데..
즉. 가로 63 사이즈로 3장이 있는 것이다.
이것을 로그해서 드로잉을 해보니 제대로 나왔다.
즉, 189라는 2의 승수가 아닌 정보를 2의 승수로 내부적 처리를 하게 되는거 같다.
하지만.. 이때 텍스처의 좌표를 3등분해서 추가를 해보면..
값이 제대로 표시가 되지 않는다.
내부적으로 다르게 처리 되어지는거 같았다.
그래서 이미지를 189 * 55를 256 * 55 로 크롭을 시켜서
이미지를 확장 시켰다.
그 이후에 63.0 / 256.0 으로 해서 텍스트 좌표를 추가 하니까.. 제대로 표시가 되었다.
소스 코드 및 관련 이미지들은.. 솔직히 맥에서 어떻게 스크린샷을 뜨는지도 몰겠고 ^^..
그래서 걍 패스..
혹시나 관련 질문이 있으시면 코멘트 부탁 해요..
Prev
Rss Feed