如需转载,请注明来源:http://hi.baidu.com/yowsah/
GLUT 代表OpenGL Utility Tookit。Mark J.Kilgard 为了使OpenGL应用程序结构能够真正独立于窗口系统构思了GLUT库。
Freeglut是一个GLUT的开源实现。
本文介绍VS2008环境下的Freeglut 2.6.0配置:
1. 下载Freeglut:http://freeglut.sourceforge.net/,http://prdownloads.sourceforge.net/freeglut/freeglut-2.6.0.tar.gz?download
2. 下载到的文件为freeglut-2.6.0.tar.gz,解压到任意目录,使用Visual Studio 2008打开freeglut-2.6.0\VisualStudio2008\freeglut.vcproj,使用Release执行编译。这时会生 成Release目录。
3. 将Release目录中的freeglut.dll复制到system32下。
4. 查找gl.h位置(默认在C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl),将freeglut-2.6.0\include\GL中的.h文件复制进去。
5.查找GlU32.Lib位置(默认在C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib),将Release目录下的freeglut.lib文件复制进去。
完成配置。
通过以下程序可测试是否成功并查看OpenGL版本:
#include <stdio.h> #include <windows.h> #include <gl/glut.h> int main(int argc, char** argv) { glutInit(&argc,argv); //显示模式初始化 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); //定义窗口大小 glutInitWindowSize(300,300); //定义窗口位置 glutInitWindowPosition(100,100); //创建窗口 glutCreateWindow("testgl"); const char* version = (const char*)glGetString(GL_VERSION); printf("OpenGL 版本:%s\n", version); glutMainLoop(); return 0; }
下面的程序是利用OpenGL画公式
的曲线:
转载自:http://blog.csdn.net/wangwei200508/archive/2008/03/09/2160189.aspx
// 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 //在上面的 dotPlot()中的for循环里做一些更改就可以画另一个函数图了 }
Additional comments powered by BackType

还没有评论呢。