windows Visual Studio 2022 opengl开发环境配置

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

windows Visual Studio 2022 opengl开发环境配置_第1张图片

还需要premake生成visual studio solution

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

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

windows Visual Studio 2022 opengl开发环境配置_第2张图片

include头文件结构: 

 windows Visual Studio 2022 opengl开发环境配置_第3张图片

windows Visual Studio 2022 opengl开发环境配置_第4张图片

windows Visual Studio 2022 opengl开发环境配置_第5张图片

windows Visual Studio 2022 opengl开发环境配置_第6张图片

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

windows Visual Studio 2022 opengl开发环境配置_第7张图片

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

lib目录下放静态库*.lib

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

windows Visual Studio 2022 opengl开发环境配置_第8张图片

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

windows Visual Studio 2022 opengl开发环境配置_第9张图片

visual studio 2022创建console控制台项目

windows Visual Studio 2022 opengl开发环境配置_第10张图片

新建cpp文件

// simple_glfw.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#pragma comment(lib , "glew32d.lib")
// E:\library\OpenGLtemplate\bin\glew32d.dll, add "E:\library\OpenGLtemplate\bin" to Path env

#include 
#include 
#include 

using namespace std;

void init(GLFWwindow * window) {}

void display(GLFWwindow *window, double currentTime) {
    glClearColor(1.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
}

int main()
{
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
    GLFWwindow* window = glfwCreateWindow(600, 600, "Chapter2 - program1", NULL, NULL);
    glfwMakeContextCurrent(window);
    if (glewInit() != GLEW_OK) {
        exit(EXIT_FAILURE);
    }
    glfwSwapInterval(1);
    init(window);
    while (!glfwWindowShouldClose(window)) {
        display(window, glfwGetTime());
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   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
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

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

windows Visual Studio 2022 opengl开发环境配置_第11张图片

指定依赖的静态库    -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;
 

完整版:



  
    
      Debug
      Win32
    
    
      Release
      Win32
    
    
      Debug
      x64
    
    
      Release
      x64
    
  
  
    16.0
    Win32Proj
    {54721bc3-8a74-4187-8468-d0a3707553f1}
    simpleglfw
    10.0
  
  
  
    Application
    true
    v143
    Unicode
  
  
    Application
    false
    v143
    true
    Unicode
  
  
    Application
    true
    v143
    Unicode
  
  
    Application
    false
    v143
    true
    Unicode
  
  
  
  
  
  
  
    
  
  
    
  
  
    
  
  
    
  
  
  
    $(PublicIncludeDirectories);E:\library\OpenLtemplate\include;
    $(IncludePath);E:\library\OpenGLtemplate\include;
    $(ReferencePath)
    $(LibraryPath);E:\library\OpenGLtemplate\lib;
  
  
    
      Level3
      true
      WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
      true
    
    
      Console
      true
    
  
  
    
      Level3
      true
      true
      true
      WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
      true
    
    
      Console
      true
      true
      true
    
  
  
    
      Level3
      true
      _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
      true
    
    
      Console
      true
      %(AdditionalLibraryDirectories);E:\library\OpenGLtemplate\lib
      %(AdditionalDependencies);glew32d.lib;glfw3.lib;opengl32.lib;soil2-debug.lib;
    
  
  
    
      Level3
      true
      true
      true
      NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
      true
    
    
      Console
      true
      true
      true
    
  
  
    
  
  
  
  

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

等效进入Properties配置

windows Visual Studio 2022 opengl开发环境配置_第12张图片

Build

windows Visual Studio 2022 opengl开发环境配置_第13张图片

你可能感兴趣的:(windows)