Cherno视频:https://www.youtube.com/watch?v=HFyHIc89z1g&t=498s
下载Glad:
修改Hazel\premake5.lua,把Glad链接进Hazel
workspace "Hazel"
architecture "x64"
configurations{
"Debug",
"Release",
"Dist"
}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" --Debug-Windows-x64
-- include directory relative to root folder (solution directory)
IncludeDir = {}
IncludeDir["GLFW"] = "Hazel/vendor/GLFW/include"
IncludeDir["Glad"] = "Hazel/vendor/Glad/include"
include "Hazel/vendor/GLFW" --include Hazel/vendor/GLFW/premake5.lua
include "Hazel/vendor/Glad"
project "Hazel"
location "Hazel"
kind "SharedLib" --dll
language "C++"
targetdir("bin/" .. outputdir .. "/%{prj.name}")
objdir("bin-int/" .. outputdir .. "/%{prj.name}")
pchheader "hzpch.h"
pchsource "Hazel/src/hzpch.cpp"
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
}
includedirs
{
"%{prj.name}/vendor/spdlog/include",
"%{prj.name}/src",
"%{IncludeDir.GLFW}",
"%{IncludeDir.Glad}",
}
links{
"GLFW",
"Glad",
"opengl32.lib"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "Off" --linking the runtime library
systemversion "latest"
defines
{
"HZ_BUILD_DLL",
"HZ_PLATFORM_WINDOWS",
}
--create a postbuild step to put the .dll where we want to be
postbuildcommands{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" ..outputdir.. "/Sandbox")
}
filter "configurations:Debug" --only apply to Debug configurations
defines "HZ_DEGUG"
--buildoptions "/MDd"
symbols "On"
filter "configurations:Release" --only apply to Debug configurations
defines "HZ_RELEASE"
--buildoptions "/MD"
optimize "On"
filter "configurations:Dist" --only apply to Debug configurations
defines "HZ_DIST"
--buildoptions "/MD"
optimize "On"
project "Sandbox"
location "Sandbox"
kind "ConsoleApp" --.exe
language "C++"
targetdir("bin/" .. outputdir .. "/%{prj.name}")
objdir("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
}
includedirs
{
"Hazel/vendor/spdlog/include",
"Hazel/src"
}
links{
"Hazel"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "Off" --linking the runtime library
systemversion "latest"
defines
{
"HZ_PLATFORM_WINDOWS",
}
filter "configurations:Debug" --only apply to Debug configurations
defines "HZ_DEGUG"
--buildoptions "/MDd"
symbols "On"
filter "configurations:Release" --only apply to Debug configurations
defines "HZ_RELEASE"
--buildoptions "/MD"
optimize "On"
filter "configurations:Dist" --only apply to Debug configurations
defines "HZ_DIST"
--buildoptions "/MD"
optimize "On"
同时,给Glad写一个premak5.lua
Hazel\Hazel\vendor\Glad\premake5.lua
project "Glad"
kind "StaticLib"
language "C"
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"
staticruntime "On"
filter { "system:windows", "configurations:Release" }
buildoptions "/MT"
这里可能会出现错误:
原因是 glad.h和glfw3.h都include了gl.h
glfw3.h:
所以我们只要定义 GLFW_INCLUDE_NONE,让glfw3.h不包含 gl.h,每次要用gl.h只需include"glad.h"即可
project "Hazel"
location "Hazel"
kind "SharedLib" --dll
language "C++"
targetdir("bin/" .. outputdir .. "/%{prj.name}")
objdir("bin-int/" .. outputdir .. "/%{prj.name}")
pchheader "hzpch.h"
pchsource "Hazel/src/hzpch.cpp"
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
}
includedirs
{
"%{prj.name}/vendor/spdlog/include",
"%{prj.name}/src",
"%{IncludeDir.GLFW}",
"%{IncludeDir.Glad}",
}
links{
"GLFW",
"Glad",
"opengl32.lib"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "Off" --linking the runtime library
systemversion "latest"
defines
{
"HZ_BUILD_DLL",
"HZ_PLATFORM_WINDOWS",
"GLFW_INCLUDE_NONE",
}
--create a postbuild step to put the .dll where we want to be
postbuildcommands{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" ..outputdir.. "/Sandbox")
}
filter "configurations:Debug" --only apply to Debug configurations
defines "HZ_DEGUG"
--buildoptions "/MDd"
symbols "On"
filter "configurations:Release" --only apply to Debug configurations
defines "HZ_RELEASE"
--buildoptions "/MD"
optimize "On"
filter "configurations:Dist" --only apply to Debug configurations
defines "HZ_DIST"
--buildoptions "/MD"
optimize "On"
加载glad
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
HZ_CORE_ASSET(status, "Failed to initialize GLAD");