Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用OpenGL ES在iOS上绘制头发细线_Ios_Opengl Es_Drawing_Line - Fatal编程技术网

使用OpenGL ES在iOS上绘制头发细线

使用OpenGL ES在iOS上绘制头发细线,ios,opengl-es,drawing,line,Ios,Opengl Es,Drawing,Line,我试图用OpenGL在iOS上画一条1像素宽的线,我遇到了一个问题 这就是在模拟器中绘制的线(缩放)的样子: iPhone4S iphone6plus 正如你们所看到的,这条线的宽度超过了1个像素,而且它是平滑的。 我认为,问题不在于OpenGL,而在于屏幕比例因子。 我希望在所有类型的屏幕上,线条都是一个像素 这就是我的底线 - (void)drawView { [EAGLContext setCurrentContext:context]; glBindFramebuf

我试图用OpenGL在iOS上画一条1像素宽的线,我遇到了一个问题

这就是在模拟器中绘制的线(缩放)的样子:

iPhone4S

iphone6plus

正如你们所看到的,这条线的宽度超过了1个像素,而且它是平滑的。 我认为,问题不在于OpenGL,而在于屏幕比例因子。 我希望在所有类型的屏幕上,线条都是一个像素

这就是我的底线

- (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];
}
看看

这表明iPhone 6 Plus使用了一个缩放因子,并表示可以通过“将GLKView的contentScaleFactor设置为UIScreen.nativeScale的值”来禁用缩放

希望这能解决你的问题