GLfloat size[2];
GLfloat step;
GLGetFloatv(GL_LINE_WIDTH_RANGE,size);
GLGetFloatv(GL_LINE_WIDTH_GRANULARITY,&step);
下面这个程序将演示如何调用这两个函数:
#include
void RenderScene(void)
{
GLfloat y;
GLfloat size[2];
GLfloat currSize;
glClear(GL_COLOR_BUFFER_BIT); //清除颜色
glGetFloatv(GL_LINE_WIDTH_RANGE,size);
currSize = size[0];
for(y = -90.0f; y < 90.0f; y += 20.0f) {
glLineWidth(currSize);
glBegin(GL_LINES);
glVertex2f(-80.0f, y);
glVertex2f(80.0f, y);
glEnd();
currSize += 1.0f;
}
glFlush(); //刷新
}
//当窗口大小变化时调用
void ChangeSize(GLsizei w,GLsizei h)
{
GLfloat aspectRatio;
if(0 == h)
h = 1;
//设置视口大小
glViewport(0,0,w,h);
//重置坐标系
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//建立裁剪区
aspectRatio = (GLfloat)w / (GLfloat)h;
if(w <= h)
glOrtho(-100.0,100.0,-100.0/aspectRatio,100/aspectRatio,1.0,-1.0);
else
glOrtho(-100.0*aspectRatio,100.0*aspectRatio,-100.0,100.0,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//设置渲染
void SetupRC(void)
{
glClearColor(0.0f,0.0f,1.0f,1.0f);
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("OpenGL Sample");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
SetupRC();
glutMainLoop();
return 0;
}
以下是程序运行截图:
.....