序文
opengl学習では、glfw + gladは現在比較的大きな組み合わせです
。glew+ freeglutが必要な場合は、他のopenGL環境の構築も確認できます。
本質的に、Clion + glew + freeglut + mingwでも同じことが機能します。
1.ライブラリをダウンロード
うれしい
ライブラリを自分でダウンロードするか、オンライン構成を使用できます。
ここでは、オンライン構成の有効な
オンライン構成を示します。openglのAPIバージョンが3.3以上と互換性を持つようにするに
は、次の構成オプション
を選択してください。モード選択コア拡張は選択できません
次に、generateはzipファイルをダウンロードし、解凍してincludeおよびsrcを取得します。
glfwダウンロード
glfw
は、Cmakeでコンパイルする
か、プリコンパイルバージョン
をダウンロードできます。プリコンパイルバージョンをダウンロードします。
2.設定
1. gladのincludeフォルダーの内容をglfwのincludeフォルダーにコピーできます
これは一緒に含めることができます
2.インクルードフォルダーに再接続することもできます
プロジェクトにglad.cファイルパスを自由に追加します
cmake_minimum_required(VERSION 3.15)
project(C__test)
set(CMAKE_CXX_STANDARD 14)
link_directories("D:/computerGraph/glfw/lib-mingw-w64")
#1. glad的include和glfw的include文件夹合并了
include_directories("D:/computerGraph/glfw/include")
#2.glad的include文件夹另外设置 inlcude_directories("D:/computerGraph/glad/include")
# 添加 glad.c为可执行
add_executable(C__test main.cpp src/glad.c)
# 衔接库
target_link_libraries(C__test libglfw3.a)
3.テスト
# 源码来源https://learnopengl.com/
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow *window)
{
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
4.テストチャート
やや