We need three files:
- glut.h
- glut32.lib
- glut32.dll
They can be downloaded from http://user.xmission.com/~nate/glut.html (The file named *-bin.zip).
And put
- .lib to PATH_TO_YOUR_VS\VC\lib (EX:C:\Program Files\Microsoft Visual Studio 11.0\VC\lib)
- .h to PATH_TO_YOUR_VS\VC\include
- .dll to C:\WINDOWS\system32 for 32-bits OS, to C:\WINDOWS\SysWOW64 for 64-bits OS
Then we can use visual studio to create the new Project.
We should chose “Win32 Console Application”, type also is “Console Application” and chose “empty project”.
Test the program:
#include <glut.h>void Display(void)
{
glPushMatrix();
glBegin (GL_TRIANGLES); // 開始劃三角形
glColor3f (1.0f, 0.0f, 0.0f); // 設定輸出色為紅色
glVertex2f (0.0f, 1.0f); //(x1,y1)=(0, 1)
glColor3f (0.0f, 1.0f, 0.0f); // 設定輸出色為綠色
glVertex2f (0.87f, -0.5f); //(x2,y2)=(0.87,-0.5)
glColor3f (0.0f, 0.0f, 1.0f); // 設定輸出色為藍色
glVertex2f (-0.87f, -0.5f); //(x3,y3)=(-0.87,-0.5)
glEnd (); // 結束劃三角形
glPopMatrix();
glutSwapBuffers();
}int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowPosition(100, 100); // 設定視窗位置
glutInitWindowSize(400, 400); // 設定視窗大小
glutCreateWindow(“Colorful Triangle “); // 設定視窗標題
glutDisplayFunc(Display); // 呼叫函數
glutMainLoop();
return 0;
}
Reference:
http://www.cs.nccu.edu.tw/~mtchi/course/3d13/lab/3d13-lab1.pdf
http://www.cc.ntu.edu.tw/chinese/epaper/0024/20130320_2410.html
http://cg2010studio.wordpress.com/2011/07/03/opengl-visual-c-%E5%AE%89%E8%A3%9D-opengl/
http://takeabreak.pixnet.net/blog/post/35452243-opengl%E5%9C%A8visual-studio-2010%E5%BA%95%E4%B8%8B%E7%9A%84%E9%85%8D%E7%BD%AE
http://www.cs.nccu.edu.tw/~mtchi/course/3d13/