OpenGL 4.3配置教程


OpenGL 4.3配置教程

下載開發包

需要下載的開發包主要包含如下幾個組件:freeglut+glew+ OpenGL.Development.Cookbook+源碼+GLM+SOIL.

Opengl SDK並不存在,尋找真正的OpenGL開發工具

1、下載

這些軟件需要翻牆才能下載,所以提供了完整壓縮包:

freeglut (latest version available from: http://freeglut.sourceforge.net)

GLEW (latest version available from: http://glew.sourceforge.net)

GLM (latest version available from: http://glm.g-truc.net)

SOIL (latest version available from: http://www.lonesock.net/soil.html)

OpenGL.Development.Cookbook 所需的庫

 

2、解壓

 

3、運行glew測試工具

 

4、查看信息

 

 說明:這些函數都封裝在glew中,我們完成一半了

編譯

 

 

 

 

 

配置OpenGL 4.3

 

下面是完整的源碼:

#include <GL/glew.h>

#include <GL/freeglut.h>

#include <iostream>

 

#pragma comment(lib, "glew32.lib")

 

using namespace std;

 

//screen size

const int WIDTH  = 500;

const int HEIGHT = 300;

 

//OpenGL initialization

void OnInit() {

       //set clear color to red

       glClearColor(1,0,0,0);

       cout<<"Initialization successfull"<<endl;

}

 

//release all allocated resources

void OnShutdown() {

       cout<<"Shutdown successfull"<<endl;

}

 

//handle resize event

void OnResize(int nw, int nh) {

 

}

 

//display callback function

void OnRender() {

       //clear colour and depth buffers

       glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

 

       //swap front and back buffers to show the rendered result

       glutSwapBuffers();

}

 

int main(int argc, char** argv) {

       //freeglut initialization calls

       glutInit(&argc, argv);

       glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

       glutInitContextVersion (4, 3);

       glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);

       glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);

       glutInitWindowSize(WIDTH, HEIGHT);

       glutCreateWindow("Getting started with OpenGL 4.3");

 

       //glew initialization

       glewExperimental = GL_TRUE;

       GLenum err = glewInit();

       if (GLEW_OK != err)   {

              cerr<<"Error: "<<glewGetErrorString(err)<<endl;

       } else {

              if (GLEW_VERSION_4_3)

              {

                     cout<<"Driver supports OpenGL 4.3\nDetails:"<<endl;

              }

       }

 

       //print information on screen

       cout<<"\tUsing GLEW "<<glewGetString(GLEW_VERSION)<<endl;

       cout<<"\tVendor: "<<glGetString (GL_VENDOR)<<endl;

       cout<<"\tRenderer: "<<glGetString (GL_RENDERER)<<endl;

       cout<<"\tVersion: "<<glGetString (GL_VERSION)<<endl;

       cout<<"\tGLSL: "<<glGetString (GL_SHADING_LANGUAGE_VERSION)<<endl;

 

       //initialization of OpenGL

       OnInit();

             

       //callback hooks

       glutCloseFunc(OnShutdown);

       glutDisplayFunc(OnRender);

       glutReshapeFunc(OnResize);

 

       //main loop call

       glutMainLoop();

 

       return 0;

}

 

書籍贈送說明

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM