win10+vs2019+OpenGL的glut库的简单使用
对于老旧的glut,使用起来多有不便。这里介绍一下使用通过freeglut使用glut库的简单方法。
下载freeglut源码进行编译:
这里下载3.2.1
使用cmake,并修改安装目录至d:\software\freeglut\
编译安装有:
需要指出的是,debug和release都需要编译安装一遍,并且需要在设置环境变量PATH:
加入:
并需要重启电脑使路径生效。
建立测试工程:
CMakeLists.txt:
cmake_minimum_required ( VERSION 3.15 )
project ( glut_test LANGUAGES CXX )
set ( PRJ_SRC_LIST test.cpp )
set ( PRJ_LIBRARIES )
set ( PRJ_INCLUDE_DIRS )
set ( MY_DEBUG true )
set ( MY_IMPORT_PREFIX "d:/software/freeglut" )
set ( MY_GLUT_LIB_RELEASE "${MY_IMPORT_PREFIX}/lib/freeglut.lib" )
set ( MY_GLUT_LIB_DEBUG "${MY_IMPORT_PREFIX}/lib/freeglutd.lib" )
set ( MY_GLUT_INC "${MY_IMPORT_PREFIX}/include" )
if ( MY_DEBUG )
set ( MY_GLUT_LIB "${MY_GLUT_LIB_DEBUG}" )
else ()
set ( MY_GLUT_LIB "${MY_GLUT_LIB_RELEASE}" )
endif ()
list ( APPEND PRJ_INCLUDE_DIRS . )
list ( APPEND PRJ_INCLUDE_DIRS ${MY_GLUT_INC} )
list ( APPEND PRJ_LIBRARIES ${MY_GLUT_LIB} )
add_executable ( ${PROJECT_NAME} ${PRJ_SRC_LIST} )
target_include_directories ( ${PROJECT_NAME}
PRIVATE
${PRJ_INCLUDE_DIRS}
)
target_link_libraries ( ${PROJECT_NAME}
PRIVATE
${PRJ_LIBRARIES}
)
test.cpp:
#include <GL/freeglut.h>
void Display(void)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
glutWireTeapot( 0.5 );
glutSwapBuffers();
}
int main ( int argc, char* argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
glutInitWindowSize( 640, 480 );
glutInitWindowPosition( 100, 100 );
glutCreateWindow( &#34;Hello FreeGLUT!&#34; );
glutDisplayFunc( Display );
glutMainLoop();
return 0;
}
win10下打开powershell:
运行cmake ../
有:
PS D:\work\AntTweakBar_work\test\build> cmake ../
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/work/AntTweakBar_work/test/buildcmake --build .
有:
PS D:\work\AntTweakBar_work\test\build> cmake --build .
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.11.0+0538acc04
版权所有(C) Microsoft Corporation。保留所有权利。
Checking Build System
Building Custom Rule D:/work/AntTweakBar_work/test/CMakeLists.txt
test.cpp
glut_test.vcxproj -> D:\work\AntTweakBar_work\test\build\Debug\glut_test.exe
Building Custom Rule D:/work/AntTweakBar_work/test/CMakeLists.txt运行:
PS D:\work\AntTweakBar_work\test\build> .\Debug\glut_test.exe有:
可见,在Win10下使用GLUT库的编译配置,运行简单glurt代码成功。为进一步重构打下了基础。 这个是为了前后处理做准备嘛? 是的,万里长征的一小步,我还不太会用,要经过几个点或者几千几万个点的重构到达目标[大笑] 为啥不用package manager? 没用过,不会用[大笑]
页:
[1]