OpenGL 4.3配置教程

时间:2023-12-26 09:53:43

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 所需的库

OpenGL 4.3配置教程

2、解压

OpenGL 4.3配置教程

3、运行glew测试工具

OpenGL 4.3配置教程

4、查看信息

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

说明:这些函数都封装在glew中,我们完成一半了

编译

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

配置OpenGL 4.3

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

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  = ;

const int HEIGHT = ;

//OpenGL initialization

void OnInit() {

       //set clear color to red

       glClearColor(,,,);

       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 (, );

       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 ;

}

OpenGL 4.3配置教程

OpenGL 4.3配置教程

OpenGL 4.3配置教程

书籍赠送说明

OpenGL 4.3配置教程