[英]Draw hair thin line on iOS, using OpenGL ES
I'm trying to draw a 1 pixel width line on iOS, using OpenGL and I faced a problem. 我正在尝试使用OpenGL在iOS上绘制1像素宽度的线,但遇到了问题。
That's how drawn line (zoomed) looks like in simulator: 这就是模拟器中绘制的线(放大)的样子:
iPhone 4S iPhone 4S
iPhone 6 Plus iPhone 6 Plus
As you can see, line is more then 1 pixel width and also it's smoothed. 如您所见,线条的宽度大于1像素,并且也被平滑了。 I think, that problem is not in OpenGL, but in screen scale factor.
我认为,这个问题不在OpenGL中,而是在屏幕比例因子中。 I want that the line is a one-pixel on all types of screens.
我希望该线在所有类型的屏幕上均为一像素。
That's how I draw the line 我就是这样划定界线的
- (void)drawView {
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
GLfloat vertices[4];
vertices[0] = -0.5;
vertices[1] = 0;
vertices[2] = 0.5;
vertices[3] = 0;
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
glLineWidthx(1.0f);
glDrawArrays(GL_LINE_STRIP, 0, 2);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
Have a look at http://oleb.net/blog/2014/11/iphone-6-plus-screen/ 看看http://oleb.net/blog/2014/11/iphone-6-plus-screen/
This shows that the iPhone 6 Plus uses a scaling factor and says that you can disable the scaling by "set the contentScaleFactor of your GLKView to the value of UIScreen.nativeScale" 这表明iPhone 6 Plus使用缩放比例,并表示可以通过“将GLKView的contentScaleFactor设置为UIScreen.nativeScale的值”来禁用缩放比例。
Hopefully that will fix your problem 希望能解决您的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.