我使用以下代码行从A点到B点画一条线。
const GLfloat line[] = {
0.0f, 0.0f, //point A
2.5f, -1.0f, //point B
};
glColor4f(0.0f,1.0f,0.0f,1.0f);
glVertexPointer(2, GL_FLOAT, 0, line);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
但我的问题是线不会在B点结束。它通过B点并继续绘制。所以我得到一条没有终点的线。任何形式的帮助表示赞赏。 谢谢。
这就是我的整个功能的样子。
- (无效)popupCircles {
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
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);
glPushMatrix();
const GLfloat line[] = {
0.0f, 0.0f, //point A
2.5f, -1.0f, //point B
};
glColor4f(0.0f,1.0f,0.0f,1.0f); //line color
glVertexPointer(2, GL_FLOAT, 0, line);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
glPopMatrix();
glPushMatrix();
const GLfloat line2[] = {
0.0f, 0.0f, //point A
-2.5f, -1.0f, //point B
};
glColor4f(0.0f,1.0f,0.0f,1.0f); //line color
glVertexPointer(2, GL_FLOAT, 0, line2);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
glPopMatrix();
glPushMatrix();
const GLfloat line3[] = {
0.0f, 0.0f, //point A
1.0f, 3.0f, //point B
};
glColor4f(0.0f,1.0f,0.0f,1.0f); //line color
glVertexPointer(2, GL_FLOAT, 0, line3);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, 2);
glPopMatrix();
glVertexPointer(2, GL_FLOAT, 0, square);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glPushMatrix();
glScalef(trans, trans, trans);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
glPushMatrix();
glScalef(trans, trans, trans);
glTranslatef(2.5f, -1.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
glPushMatrix();
glScalef(trans, trans, trans);
glTranslatef(-2.5f, -1.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
glPushMatrix();
glScalef(trans, trans, trans);
glTranslatef(1.0f, 3.0f, 0.0f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glPopMatrix();
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
答案 0 :(得分:1)
如果未指定投影和模型视图矩阵,则B点位于视口之外,对于x和y维度,它在[-1,1]范围内。
编辑(响应修正后的问题): B点超出了glOrthof()
调用设置的界限,因此行应该视口的边缘。