重定形函数的应用

#include < GL /glut.h >
#include
< math .h >
#include
< stdlib .h >
const double TWO_PI=6.2831853;
//Initial display-window size
GLsizei winWidth=400,winHeight=400;
GLuint regHex;
class screenPt
{
private:
    GLint x,y;
public:
    //Defaut Constructor:initializes coordinate position to (0,0)
    screenPt()
    {
        x=y=0;
    }
    void setCoords(GLint xCoord,GLint yCoord)
    {
        x=xCoord;
        y=yCoord;
    }
    GLint getx()
    {
        return x;
    }
    GLint gety()
    {
        return y;
    }
};//注意别忘了这里有一个分号
static void init(void)
{
    screenPt hexVertex,cirCtr;
    GLdouble theta;
    GLint k;
    //set circle center coordinates.
    cirCtr.setCoords(winWidth/2,winHeight/2);
    glClearColor(1.0,1.0,1.0,0.0);//Display-window color=white.
    /*Set up a display list for a red regular hexagon.
    *Vettices for the hexagon are sex equally spaced
    *points around the circumference of a circle.
    */
    regHex=glGenLists(1);
    glNewList(regHex,GL_COMPILE);
       glColor3f(1.0,0.0,0.0);
       glBegin(GL_POLYGON);
          for(k=0;k
< 6 ;k++)
          {
              theta
=TWO_PI*k/6.0;
                 
hexVertex.setCoords(cirCtr.getx()+150*cos(theta),cirCtr.gety()+150*sin(theta));
                 glVertex2i(hexVertex.getx(),hexVertex.gety());
          }
          glEnd();
    glEndList();
}
void regHexagon(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glCallList(regHex);
    glFlush();
}
void winReshapeFcn(int newWidth,int newHeight)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,(GLdouble)newWidth,0.0,(GLdouble)newHeight);
    glClear(GL_COLOR_BUFFER_BIT);
}
void main(int argc,char** argv)//注意是char**
{
    glutInit(&argc,argv);//注意是char**
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(winWidth,winHeight);
    glutCreateWindow("Reshape-Function & Display-List Example");

    init();//访问类的公有成员,这就像访问普通函数一样,当然了,这里只有一个类
    glutDisplayFunc(regHexagon);
    glutReshapeFunc(winReshapeFcn);

    glutMainLoop();
}
<!--
http://f2.9612.org//vcpp/webinfo/WebInfoBata1.asp

QQ群:
34409541 讨论网页  
34409326 讨论JAVA 已满 
34408784 讨论VC++  
34409699 讨论VC++  
9143041 讨论MFC编程  
10614204 讨论C#  
10613030 讨论Win32编程  
10613067 讨论游戏开发  
18779860 讨论JAVA  
*/
--
>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值