用OpenGL在 visual studio 2005 下画简单的二维函数图像
来源:互联网 发布:台湾旅游业 知乎 编辑:程序博客网 时间:2024/06/02 11:04
书上又一例子,画公式 f(x) = e-x cos(2*pi*x) 的曲线,效果如下:
这是我在visual studio 2005 下编译通过的源代码:
// Draw the "dot plots" of a function
//P52 in <Computer Graphics Using OpenGL(Second Edition)>
#include<math.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
//----------Initialization--------------
void init(void)
...{
glClearColor(1.0,1.0,1.0,0.0); // Set white background color
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);
// Set values used for scaling and shifting
A = screenWidth/4.0;
B = 0.0;
C = D = screenHeight/2.0;
}
// --------Draw the "dot plots" of a function------
void dotPlots(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();
// Draw a horizontal line
glBegin(GL_LINES);
glVertex2i(0,screenHeight/2);
glVertex2i(screenWidth,screenHeight/2);
glEnd();
glFlush(); //send all output to display
}
//--------main-----------
void main(int argc,char** argv)
...{
glutInit(&argc, argv); // Initialize the toolkit
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); // Set display mode
glutInitWindowPosition(100, 150); // Set window pozition on screen
glutInitWindowSize(screenWidth, screenHeight); // Set window size
glutCreateWindow("Dot plot of a Function"); // Open the screen window
glutDisplayFunc(dotPlots); // Register redraw function
init();
glutMainLoop(); // Go into a perpetual loop
}
//P52 in <Computer Graphics Using OpenGL(Second Edition)>
#include<math.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
//----------Initialization--------------
void init(void)
...{
glClearColor(1.0,1.0,1.0,0.0); // Set white background color
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);
// Set values used for scaling and shifting
A = screenWidth/4.0;
B = 0.0;
C = D = screenHeight/2.0;
}
// --------Draw the "dot plots" of a function------
void dotPlots(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();
// Draw a horizontal line
glBegin(GL_LINES);
glVertex2i(0,screenHeight/2);
glVertex2i(screenWidth,screenHeight/2);
glEnd();
glFlush(); //send all output to display
}
//--------main-----------
void main(int argc,char** argv)
...{
glutInit(&argc, argv); // Initialize the toolkit
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); // Set display mode
glutInitWindowPosition(100, 150); // Set window pozition on screen
glutInitWindowSize(screenWidth, screenHeight); // Set window size
glutCreateWindow("Dot plot of a Function"); // Open the screen window
glutDisplayFunc(dotPlots); // Register redraw function
init();
glutMainLoop(); // Go into a perpetual loop
}
在上面的 dotPlot()中的for循环里做一些更改就可以画另一个函数图了
- 用OpenGL在 visual studio 2005 下画简单的二维函数图像
- opengl在windows下的visual studio配置
- [转载]在visual studio 2005 下建立openGL开发环境
- 在visual studio 2005 下建立openGL开发环境( 转载)
- 在visual studio 2005 下建立openGL开发环境
- Visual Studio下的openGL exe发布
- 在Visual Studio 2013下利用MFC框架配置OpenGL
- OpenGL实用函数工具包GLUT在Visual Studio上的配置
- 在visual studio 2005 下建立openGL开发环境 - [学习日志]
- opengl来画二维图像
- 题目:Visual Studio 2015在opencv 3.1.0下,使用OpenCV函数 HoughCircles 在一幅图像中检测圆
- visual studio 2015下OpenGL库的配置教程
- 如何在 Visual Studio 2005 下打开 Visual Studio 2008 的项目
- zlib 在 Visual Studio 2005 下编译失败的解决办法
- zlib 在 Visual Studio 2005 下编译失败的解决办法
- zlib 在 Visual Studio 2005 下编译失败的解决办法
- zlib 在 Visual Studio 2005 下编译失败的解决办法
- zlib 在 Visual Studio 2005 下编译失败的解决办法
- 预告
- APUE学习笔记(1)——UNIX基础知识(第一章)
- StoneAgeDict现阶段设计小结
- C++中的文件操作
- C/C++语言误区一 —— void main( )(转贴)
- 用OpenGL在 visual studio 2005 下画简单的二维函数图像
- 在QTP中巧用WebTable对象的ChildItem方法进行测试
- 一条我喜欢的短信
- 答师弟问
- 上善若水 厚德载物
- 主数据管理 之未来维护 (Master Data Management Maintenance)
- Asp.net 中从服务端代码中通过Request可得到的路径
- 汪国真诗歌摘选
- Silverlight入门教程(基于Asp.net运行环境示例)[示例代码下载]