• windows Visual Studio 2022 opengl开发环境配置


    1. 安装glew(GL), GLFW, glmsoil2-debug

    还需要premake生成visual studio solution

    cmake for windows也要安装一个, 但是不用安装MinGW64, bug多

    下载源码,找到xxx.sln文件用visual stidio打开solution编译代码,找到xxx.lib, xxx.dll文件

    include头文件结构: 

     

    编译完了创建目录  OpenGLtemplate/{include,lib,bin}

    动态库glew32d.dll放到bin目录下,并把E:\library\OpenGLtemplate\bin追加到path环境变量

    lib目录下放静态库*.lib

    glew32sd.lib是静态库,glew32d.lib其实是动态库,后缀改成dll放到bin目录

     或者把依赖的动态库放到项目编译完了.exe文件同级目录,方便发布

    visual studio 2022创建console控制台项目

    新建cpp文件

    1. // simple_glfw.cpp : This file contains the 'main' function. Program execution begins and ends there.
    2. //
    3. #pragma comment(lib , "glew32d.lib")
    4. // E:\library\OpenGLtemplate\bin\glew32d.dll, add "E:\library\OpenGLtemplate\bin" to Path env
    5. #include
    6. #include
    7. #include
    8. using namespace std;
    9. void init(GLFWwindow * window) {}
    10. void display(GLFWwindow *window, double currentTime) {
    11. glClearColor(1.0, 0.0, 0.0, 1.0);
    12. glClear(GL_COLOR_BUFFER_BIT);
    13. }
    14. int main()
    15. {
    16. if (!glfwInit()) {
    17. exit(EXIT_FAILURE);
    18. }
    19. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    20. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
    21. GLFWwindow* window = glfwCreateWindow(600, 600, "Chapter2 - program1", NULL, NULL);
    22. glfwMakeContextCurrent(window);
    23. if (glewInit() != GLEW_OK) {
    24. exit(EXIT_FAILURE);
    25. }
    26. glfwSwapInterval(1);
    27. init(window);
    28. while (!glfwWindowShouldClose(window)) {
    29. display(window, glfwGetTime());
    30. glfwSwapBuffers(window);
    31. glfwPollEvents();
    32. }
    33. glfwDestroyWindow(window);
    34. glfwTerminate();
    35. exit(EXIT_SUCCESS);
    36. }
    37. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
    38. // Debug program: F5 or Debug > Start Debugging menu
    39. // Tips for Getting Started:
    40. // 1. Use the Solution Explorer window to add/manage files
    41. // 2. Use the Team Explorer window to connect to source control
    42. // 3. Use the Output window to see build output and other messages
    43. // 4. Use the Error List window to view errors
    44. // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
    45. // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file

    直接修改.vcxproj文件,等效于Makefile文件

    指定依赖的静态库    -l

    %(AdditionalDependencies);glew32d.lib;glfw3.lib;opengl32.lib;soil2-debug.lib;

    指定-I, include目录,-L库的路径

     
        $(PublicIncludeDirectories);E:\library\OpenLtemplate\include;
        $(IncludePath);E:\library\OpenGLtemplate\include;
        $(ReferencePath)
        $(LibraryPath);E:\library\OpenGLtemplate\lib;
     

    完整版:

    1. "1.0" encoding="utf-8"?>
    2. "Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    3. "ProjectConfigurations">
    4. "Debug|Win32">
    5. Debug
    6. Win32
    7. "Release|Win32">
    8. Release
    9. Win32
    10. "Debug|x64">
    11. Debug
    12. x64
    13. "Release|x64">
    14. Release
    15. x64
    16. "Globals">
    17. 16.0
    18. Win32Proj
    19. {54721bc3-8a74-4187-8468-d0a3707553f1}
    20. simpleglfw
    21. 10.0
    22. "$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    23. "'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    24. Application
    25. true
    26. v143
    27. Unicode
    28. "'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    29. Application
    30. false
    31. v143
    32. true
    33. Unicode
    34. "'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    35. Application
    36. true
    37. v143
    38. Unicode
    39. "'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    40. Application
    41. false
    42. v143
    43. true
    44. Unicode
    45. "$(VCTargetsPath)\Microsoft.Cpp.props" />
    46. "ExtensionSettings">
    47. "Shared">
    48. "PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    49. "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    50. "PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    51. "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    52. "PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    53. "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    54. "PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    55. "$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    56. "UserMacros" />
    57. "'$(Configuration)|$(Platform)'=='Debug|x64'">
    58. $(PublicIncludeDirectories);E:\library\OpenLtemplate\include;
    59. $(IncludePath);E:\library\OpenGLtemplate\include;
    60. $(ReferencePath)
    61. $(LibraryPath);E:\library\OpenGLtemplate\lib;
    62. "'$(Configuration)|$(Platform)'=='Debug|Win32'">
    63. Level3
    64. true
    65. WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
    66. true
    67. Console
    68. true
    69. "'$(Configuration)|$(Platform)'=='Release|Win32'">
    70. Level3
    71. true
    72. true
    73. true
    74. WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
    75. true
    76. Console
    77. true
    78. true
    79. true
    80. "'$(Configuration)|$(Platform)'=='Debug|x64'">
    81. Level3
    82. true
    83. _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
    84. true
    85. Console
    86. true
    87. %(AdditionalLibraryDirectories);E:\library\OpenGLtemplate\lib
    88. %(AdditionalDependencies);glew32d.lib;glfw3.lib;opengl32.lib;soil2-debug.lib;
    89. "'$(Configuration)|$(Platform)'=='Release|x64'">
    90. Level3
    91. true
    92. true
    93. true
    94. NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
    95. true
    96. Console
    97. true
    98. true
    99. true
    100. "simple_glfw.cpp" />
    101. "$(VCTargetsPath)\Microsoft.Cpp.targets" />
    102. "ExtensionTargets">

    在界面上并不好找,不如直接改xml,reload solution

    等效进入Properties配置

    Build

    类似的libevent库安装

    wget wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz

    tar xvzf libevent-2.1.12-stable.tar.gz -C .

    cd libevent-2.1.12-stable

    ./autogen.sh

    ./configure

    make

    sudo make install

    Libraries have been installed in:
       /usr/local/lib

    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'

  • 相关阅读:
    关于iterm2的美化
    跑步装备推荐:2022年跑步装备选购清单
    Linux系统编程:编译过程以及GDB调试
    2022主流技术 Appium+IOS 自动化测试环境搭建
    Flink学习2:应用场景
    momerymap mmap 存储映射I/O
    Python教程:PyQt5需要学习,哪些知识点??
    【附源码】计算机毕业设计JAVA研究生入学考试备考辅助系统
    【重识云原生】第六章容器6.1.2节——容器安装部署
    Python NumPy 基础:数组和向量计算
  • 原文地址:https://blog.csdn.net/fareast_mzh/article/details/133063641