重定形函数的应用
来源:互联网 发布:滨州行知中学是私立吗 编辑:程序博客网 时间: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
*/
-->
#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
*/
-->
- 重定形函数的应用
- OpenGl学习之显示窗口重定形函数
- 计算机图形学(二)输出图元_19_显示窗口重定形函数
- JS去重函数的扩展应用
- 小波分解函数和重构函数的应用和区别
- Oracle之分析函数 去重 应用
- 关于移植过程中,存在大量LCD log(不定形参...)等调试属性函数宏定义到printf
- 重学C++Primer笔记9---回调函数与函数指针的应用
- 不可重入的函数
- 函数的另一重写法
- ubuntu最终定形软件列表
- 数据库重启,应用服务器需要重启的解决方法
- 避免重启你的应用
- Shell 重定向Redirection的应用
- servlet的重定向方法及应用
- 单链表的应用1(去重)
- Android 应用 重启的方法
- android重启应用的方法
- aml 做的 scs曲线计算径流模型
- JavaEE without Ajax
- 从办公桌可以看透一个人
- 关于Oracle SQL Tuning的一个培训大纲
- 5-2 从QWidget继承新类(Subclassing QWidget)
- 重定形函数的应用
- 数据点折线和多点标记绘制
- 显示窗口和由示例程序生成的线段
- 绘制直方图
- 对复选框全选
- The passage of time
- Emacs 中文化指南
- JDBC连接各种数据库经验技巧集萃
- 開博的第一篇