#include <windows.h> // use proper includes for your system
#include <math.h>
#include <gl/Gl.h>
#include <gl/glut.h>
const int screenWidth = 640; // width of screen window in pixels
const int screenHeight = 480; // height of screen window in pixels
GLdouble A, B, C, D; // values used for scaling and shifting
//<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // background color is white
glColor3f(0.0f, 0.0f, 0.0f); // drawing color is black
glPointSize(2.0); // a 'dot' is 2 by 2 pixels
glMatrixMode(GL_PROJECTION); // set "camera shape"
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
A = screenWidth / 4.0; // set values used for scaling and shifting
B = 0.0;
C = D = screenHeight / 2.0;
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glBegin(GL_POINTS);
for(GLdouble x = 0; x < 4.0 ; x += 0.005)
{
GLdouble func = exp(-x) * cos(2 * 3.14159265 * x);
glVertex2d(A * x + B, C * func + D);
}
glEnd();
glFlush(); // send all output to display
}
//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(screenWidth, screenHeight); // set window size
glutInitWindowPosition(100, 150); // set window position on screen
glutCreateWindow("Dot Plot of a Function"); // open the screen window
glutDisplayFunc(myDisplay); // register redraw function
myInit();
glutMainLoop(); // go into a perpetual loop
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Computer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cppComputer Graphics: Using OpenGL cpp
资源推荐
资源详情
资源评论
收起资源包目录
CHAP2.rar (14个子文件)
CHAP2
FIG2_10.CPP 1KB
FIG2_41.CPP 493B
FIG2_14.CPP 471B
FIG2_30.CPP 260B
FIG2_16.CPP 2KB
FIG2_29.CPP 495B
FIG2_28.CPP 224B
FIG2_27.CPP 106B
FIG2_24.CPP 418B
FIG2_22.CPP 636B
FIG2_38.CPP 683B
FIG2_25.CPP 575B
FIG2_31.CPP 549B
FIG2_40.CPP 786B
共 14 条
- 1
资源评论
tonglijing
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功