我遇到的问题是 glMultMatrix 在 glBegin 内部时似乎不起作用
不足为奇:
在 glBegin 和 glEnd 之间只能使用 GL 命令的子集。
命令是
顶点顶点,
颜色,
glSecondaryColor,
全局索引,
gl正常,
glFogCoord,
glTexCoord,
glMultiTexCoord,
glVertexAttrib,
glEvalCoord,
glEvalPoint,
glArrayElement,
gl材质,和
glEdgeFlag。
还,
可以接受使用
glCallList 或
glCallLists 执行
显示仅包含上述命令的列表。如果在 glBegin 和 glEnd 之间执行任何其他 GL 命令,
错误标志被设置并且命令被忽略。
glMultMatrix()
before glBegin()
:
//The matrixes that are applied to the circle of points
GLfloat M1[16]=
{
N1.x(),N1.y(),N1.z(),0,
B1.x(),B1.y(),B1.z(),0,
T1.x(),T1.y(),T1.z(),0,
fromPoint->x,fromPoint->y,fromPoint->z,1
};
GLfloat M2[16]=
{
N2.x(),N2.y(),N2.z(),0,
B2.x(),B2.y(),B2.z(),0,
T2.x(),T2.y(),T2.z(),0,
toPoint->x,toPoint->y,toPoint->z,1
};
GLfloat x, y;
GLfloat radius = 0.4f;
GLint pointCount = 180;
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount)
{
x = radius * cos(theta);
y = radius * sin(theta);
// Now push a matrix, multiply it, draw a point and pop the matrix
glPushMatrix();
glMultMatrixf(& M1[0]);
// Draw the point here
glBegin(GL_POINTS);
glVertex3f(x, y, 0);
glEnd();
glPopMatrix();
// Do the same again for the second section
glPushMatrix();
glMultMatrixf(& M2[0]);
glBegin(GL_POINTS);
glVertex3f(x, y, 0);
glEnd();
glPopMatrix();
}
或者在客户端应用变换并交给 OpenGL 一大块顶点来一次性渲染。
EDIT:或者将这些矩阵乘法完全拉到循环之外:
GLfloat x, y;
GLfloat radius = 0.4f;
GLint pointCount = 180;
glPushMatrix();
glMultMatrixf(& M1[0]);
glBegin(GL_POINTS);
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount)
{
x = radius * cos(theta);
y = radius * sin(theta);
// Draw the point here
glVertex3f(x, y, 0);
}
glEnd();
glPopMatrix();
glPushMatrix();
glMultMatrixf(& M2[0]);
glBegin(GL_POINTS);
for (GLfloat theta = 0; theta < 2*M_PI; theta += (2*M_PI)/pointCount)
{
x = radius * cos(theta);
y = radius * sin(theta);
// Draw the point here
glVertex3f(x, y, 0);
}
glEnd();
glPopMatrix();