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
Details:"<<endl;

              }

       }

 

       //print information on screen

       cout<<"	Using GLEW "<<glewGetString(GLEW_VERSION)<<endl;

       cout<<"	Vendor: "<<glGetString (GL_VENDOR)<<endl;

       cout<<"	Renderer: "<<glGetString (GL_RENDERER)<<endl;

       cout<<"	Version: "<<glGetString (GL_VERSION)<<endl;

       cout<<"	GLSL: "<<glGetString (GL_SHADING_LANGUAGE_VERSION)<<endl;

 

       //initialization of OpenGL

       OnInit();

             

       //callback hooks

       glutCloseFunc(OnShutdown);

       glutDisplayFunc(OnRender);

       glutReshapeFunc(OnResize);

 

       //main loop call

       glutMainLoop();

 

       return 0;

}

 

书籍赠送说明

 

 

原文地址:https://www.cnblogs.com/rainbow70626/p/5557849.html