Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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
在GLKit(iOS 5)中使用GLU点_Ios_Opengl Es 2.0_Glkit - Fatal编程技术网

在GLKit(iOS 5)中使用GLU点

在GLKit(iOS 5)中使用GLU点,ios,opengl-es-2.0,glkit,Ios,Opengl Es 2.0,Glkit,OpenGL的新功能是,我在iOS5上使用GLKit和GL_LINE_循环成功地显示线条,但使用GL_点显示点给我带来了麻烦。具体来说,我只能显示一个像素。我在网上搜索都没有成功,所以我希望有人能指出我遗漏了什么 这是我的测试代码 //positions and colors, vertices and indices... typedef struct { float Position[2]; float Color[4]; } Vertex; const Vertex Ve

OpenGL的新功能是,我在iOS5上使用GLKit和GL_LINE_循环成功地显示线条,但使用GL_点显示点给我带来了麻烦。具体来说,我只能显示一个像素。我在网上搜索都没有成功,所以我希望有人能指出我遗漏了什么

这是我的测试代码

//positions and colors, vertices and indices...
typedef struct {
    float Position[2];
    float Color[4];
} Vertex;

const Vertex Vertices[] = {
    {{50, 50}, {0, 0, 1, 1}},
    {{200, 50}, {0, 0, 1, 1}},
    {{200, 200}, {0, 0, 1, 1}},
    {{50, 200}, {0, 0, 1, 1}}
};

const GLubyte Indices[] = {
    0, 1, 2, 3
};


@interface AppViewController() {
    GLuint _vertexBuffer;
    GLuint _indexBuffer;
}

...
//some unrelated properties, the @implementation and other methods
...

- (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;
    [EAGLContext setCurrentContext:self.context];

    self.effect = [[GLKBaseEffect alloc] init];

    GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(0, self.view.bounds.size.width, 0, self.view.bounds.size.height, -1024, 1024);
    self.effect.transform.projectionMatrix = projectionMatrix;

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);

    glGenBuffers(1, &_indexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {    
    glClearColor(1, 1, 1, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    [self.effect prepareToDraw];

    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);

    glEnableVertexAttribArray(GLKVertexAttribPosition);        
    glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
    glEnableVertexAttribArray(GLKVertexAttribColor);
    glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));

    //this worked for drawing my lines...
    //glLineWidth(10);
    //glDrawElements(GL_LINE_LOOP, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);

    //this does NOT work for drawing 10-pixel points. single pixel only.
    glEnable(GL_POINT_SMOOTH);
    glPointSize(10);
    glDrawElements(GL_POINTS, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
}

谢谢你的时间

我不认为
glPointSize()
是OpenGL ES 2.0的一部分

尝试设置

gl_PointSize = 10.0; //has to be a floating point value

…在顶点着色器中。

该值必须是浮点值,否则会出现“类型不匹配,无法从“int”转换为“float”错误。GLSL不是java,不单独转换值。