我需要一点帮助来在屏幕上绘制像素。我编写的代码在模拟器上运行良好,但是当我在设备上部署时它会输出垃圾。所以这是我的代码:
我有 GLKViewController 设置,这是 viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.context];
self.effect = [[GLKBaseEffect alloc] init];
self.effect.useConstantColor = GL_TRUE;
self.effect.constantColor = GLKVector4Make(
0.0, // Red
0.0, // Green
0.0, // Blue
1.0f);// Alpha
GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(0, 480, 0, 320, -1024, 1024);
self.effect.transform.projectionMatrix = projectionMatrix;
}
这是我绘制点/像素的地方:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
GLfloat points[] =
{
110.0f, 110.0f,
111.0f, 110.0f,
110.0f, 111.0f,
111.0f, 111.0f,
112.0f, 112.0f,
113.0f, 112.0f,
112.0f, 113.0f,
113.0f, 113.0f,
};
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 0.0f);
self.effect.transform.modelviewMatrix = modelViewMatrix;
// Prepare the effect for rendering
[self.effect prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 2*4, points);
glDrawArrays(GL_POINTS, 0, 8);
}
当我在模拟器上运行时,它工作正常,即相应地绘制像素,但是当我在 iPod4 上部署时,它显示一些垃圾。我是初学者,所以需要帮助来显示简单的像素。