重定形函数的应用

来源:互联网 发布:滨州行知中学是私立吗 编辑:程序博客网 时间:2024/05/29 17:19
#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  
*/
--
>
 
原创粉丝点击