重定形函數的應用

#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  
*/
--
>
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章