Modern OpenGl(glad)
本节主要进行 glad 的安装
首先下载 glad
将 glad 解压到 Hazel/vendor/Glad 后,配置 premake 文件:
project "Glad"
kind "StaticLib"
language "C"
staticruntime "off"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"include/glad/glad.h",
"include/KHR/khrplatform.h",
"src/glad.c"
}
includedirs
{
"include"
}
filter "system:windows"
systemversion "latest"
filter "configurations:Debug"
runtime "Debug"
symbols "on"
filter "configurations:Release"
runtime "Release"
optimize "on"
filter "configurations:Dist"
runtime "Release"
optimize "on"
symbols "off"
然后配置 Hazel 的 premake 文件:
添加:
IncludeDir["Glad"] = "Hazel/vendor/Glad/include"
include "Hazel/vendor/Glad"
includedirs
{
...
"%{IncludeDir.Glad}"
}
links
{
...
"Glad"
}
defines
{
...
"GLFW_INCLUDE_NONE" --包含glad头文件的时候就不用再包含glfw了
}
在WindowsWindow.cpp
中的 Init 函数中添加
void WindowsWindow::Init(const WindowProps& props)
{
...
m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(m_Window);
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
HZ_CORE_ASSERT(status, "Failed to initialize GLAD!");
...
}
);
Application.cpp 中去掉头文件 GLFW 添加 glad.h 然后运行,能够正常跑起来说明添加成功。