環境介紹
- 參考書目:計算機圖形學 第4版
- VS版本:2017
- OpenGL環境:GLUT庫
準備GLUT庫
下載下傳網址
https://www.opengl.org/resources/libraries/glut/glut_downloads.php#3.6
分類
- 将下載下傳後的檔案,安裝不同類型,建立dll lib include/gl子檔案夾
配置VS工程目錄(配置完成後就不需重複配置)
- 打開視圖菜單下的屬性管理器
- 選擇平台和編譯選項
- 點選use彈出屬性對話框
- 配置包含目錄和庫目錄
測試代碼
#include "pch.h"
#include <GL/glut.h>
void Init()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 100.0);
}
void Show()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2i(100, 0);
glVertex2i(0, 75);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL-ONE");
Init();
glutDisplayFunc(Show);
glutMainLoop();
return 0;
}