VC++ OpenGL 開發環境配置

來源:互聯網
上載者:User

1. 下載GLUT工具包

 http://www.opengl.org/resources/libraries/glut/

2. 進入VC安裝目錄  
VC\include\GL,將工具包中的.h檔案複製進來。

    將.lib檔案複製到VC安裝目錄下的 \VC\lib

    將.dll檔案複製到系統目錄下的system32檔案夾

3. 建立C++工程,測試如下代碼成功,則環境配置成功

#include
<GL/glut.h>
#include <GL/gl.h>
#include <GL/glaux.h>
#pragma comment(lib, "opengl32.lib" )
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glaux.lib")
#include <Windows.h>

void myinit(void);
void CALLBACK myReshape(GLsizei w,GLsizei h);
void CALLBACK display(void);

void myinit(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
}

void CALLBACK myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if(w<=h)
glOrtho(-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-1.5*(GLfloat)h/(GLfloat)w,
1.5*(GLfloat)h/(GLfloat)w,-1.5,1.5,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void CALLBACK display(void)
{
glColor3f(1.0,1.0,0.0);
auxWireSphere(1.0);
glFlush();
}

void main(void)
{
//設定顯示模式:單緩衝|RGBA顏色模式
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
//初始化視窗位置
auxInitPosition(400,200,500,500);
//設定視窗標題
auxInitWindowA("OpenGL程式");
myinit();
auxReshapeFunc(myReshape);
auxMainLoop(display);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.