Reputation: 1150
I need a little help with drawing pixels on screen. The code I have written works fine on simulator but when I deploy on device it output garbage. So here's my code:
I have GLKViewController setup and here's the 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;
}
And here is where I am drawing points/pixels:
- (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);
}
When I run on simulator it works fine i.e. draw the pixels accordingly, but when I deploy on iPod4 it display some garbage. I am a beginner so need help displaying simple pixels.
Upvotes: 1
Views: 1893
Reputation: 1215
I believe the issue here is that you need to set the built-in gl_PointSize
variable in the vertex shader, as the default values are different on the simulator and the device.
The answer to this question explains further.
Upvotes: 2