应用在模拟器中运行而不是在ipad ..!
问题描述:
A'm stucked一个很奇怪的问题.....真的不能得到如何走出与.. !!应用在模拟器中运行而不是在ipad ..!
我正在开发iPad应用中,我画用OpenGL编程为iPad一个3D立方体....一切都好....我用不同的颜色绘制的立方体,也有色这....这一切我在模拟器上测试过的东西,一切都很棒。但是当我试图在iPad上测试时,我的立方体正在绘制,但着色部分不起作用... !!!
预先感谢帮助.. !!
答
UPDATE:我的示例代码
MyViewController.h
CubeView *cubeView;
MyViewController.m
cubeView = [[CubeView alloc] initWithFrame:CGRectMake(250, 60, 450, 600)];
cubeView.multipleTouchEnabled = YES;
cubeView.backgroundColor = [UIColor clearColor];
[self.view addSubview:cubeView];
CubeView.m
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
[self setMultipleTouchEnabled:YES];
// self.frame = CGRectMake(20, 30, 500, 500);
renderer = nil;
if (!renderer)
{
renderer = [[CubeRenderer alloc] init];
if (!renderer)
{
[self release];
return nil;
}
}
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
[self setMultipleTouchEnabled:YES];
renderer = nil;
if (!renderer)
{
renderer = [[CubeRenderer alloc] init];
if (!renderer)
{
[self release];
return nil;
}
}
}
return self;
}
CubeRenderer.m
- (id)init
{
if ((self = [super init]))
{
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context])
{
[self release];
return nil;
}
currentCalculatedMatrix = CATransform3DIdentity;
// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
}
return self;
}
static const GLfloat cubeVertices[] = {
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
};
static const GLushort cubeIndicesFaceFront[] = {
0, 1, 2, 3, 0
};
static const GLushort cubeIndicesFaceBack[] = {
4, 5, 6, 7, 4
};
static const GLushort cubeIndicesFaceLeft[] = {
0, 4, 7, 3, 0
};
static const GLushort cubeIndicesFaceRight[] = {
1, 5, 6, 2, 1
};
static const GLushort cubeIndicesFaceTop[] = {
3, 2, 6, 7, 3
};
static const GLushort cubeIndicesFaceBottom[] = {
0, 1, 5, 4, 0
};
[EAGLContext setCurrentContext:context];
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-2.0, 2.0, -2.0 * 480.0/320.0, 2.0 * 480.0/320.0, -3.0, 3.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glVertexPointer(3, GL_FLOAT, 0, cubeVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeColorsBlueFace);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceFront);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceFront);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceBack);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBack);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBack);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceLeft);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceLeft);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceLeft);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceRight);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceRight);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceRight);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceTop);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceTop);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceTop);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeFillColorsFaceBottom);
glEnableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLE_FAN, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBottom);
//glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, cubeIndicesFaceBottom);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
的OpenGL具有模拟器和设备之间的一些细微差异。发布您的绘图代码。 – 2010-07-21 15:46:28
这个drawProperties有什么区别吗? eaglLayer.drawableProperties = [NSDictionary的dictionaryWithObjectsAndKeys: [NSNumber的numberWithBool:FALSE],kEAGLDrawablePropertyRetainedBacking,kEAGLColorFormatRGBA8,kEAGLDrawablePropertyColorFormat,零]。 – rohanparekh 2010-07-22 04:11:51
嘿,我发现我是用plist文件着色一个problem..actually。就像,当用户选择在那个时候我存储的plist该颜色值,然后在我的渲染器类我是以颜色的值从plist中的任何颜色。所以当我在模拟器上工作时一切都很好,但是当我在设备上调试同样的东西时,我无法从渲染器类的plist中获得颜色的值。 plist是否有一些限制在实际设备中使用? – rohanparekh 2010-07-23 03:34:47