Skip to content

Commit

Permalink
viewer: replace GLEW with GLAD
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Jan 3, 2025
1 parent 8dc7418 commit c5953c0
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 65 deletions.
31 changes: 11 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
########################################################################
#
# Project-wide settings
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 3.18)
IF(POLICY CMP0011)
# Included scripts do automatic cmake_policy() PUSH and POP.
CMAKE_POLICY(SET CMP0011 NEW)
ENDIF()
IF(POLICY CMP0072)
CMAKE_POLICY(SET CMP0072 NEW)
ENDIF()
IF(POLICY CMP0074)
# find_package() uses <PackageName>_ROOT variables.
CMAKE_POLICY(SET CMP0074 NEW)
ENDIF()
IF(POLICY CMP0104)
# Initialize CMAKE_CUDA_ARCHITECTURES when CMAKE_CUDA_COMPILER_ID is NVIDIA. Raise an error if CUDA_ARCHITECTURES is empty.
CMAKE_POLICY(SET CMP0104 NEW)
ENDIF()
IF(POLICY CMP0146)
CMAKE_POLICY(SET CMP0146 OLD) # not required, but forced by OpenCV old support for CUDA
# Use CMake's first-class CUDA language support instead of FindCUDA().
# note: not required, but forced by OpenCV old support for CUDA
CMAKE_POLICY(SET CMP0146 OLD)
ENDIF()
IF(POLICY CMP0167)
# The FindBoost module is removed.
CMAKE_POLICY(SET CMP0167 NEW)
ENDIF()

# List configuration options
Expand Down Expand Up @@ -100,17 +106,6 @@ if(OpenMVS_USE_OPENMP)
endif()
endif()

if(OpenMVS_USE_OPENGL)
FIND_PACKAGE(OpenGL)
if(OPENGL_FOUND)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
ADD_DEFINITIONS(${OpenGL_DEFINITIONS})
SET(_USE_OPENGL TRUE)
else()
MESSAGE("-- Can't find OpenGL. Continuing without it.")
endif()
endif()

if(OpenMVS_USE_CUDA)
INCLUDE(CheckLanguage)
CHECK_LANGUAGE(CUDA)
Expand Down Expand Up @@ -208,10 +203,6 @@ if(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
ADD_DEFINITIONS(${Boost_DEFINITIONS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
if(NOT MSVC AND DEFINED CMAKE_TOOLCHAIN_FILE)
# work around this missing library link in vcpkg
LIST(APPEND Boost_LIBRARIES zstd)
endif()
SET(_USE_BOOST TRUE)
if(OpenMVS_USE_PYTHON AND Boost_${Boost_EXTRA_COMPONENTS}_FOUND)
SET(_USE_BOOST_PYTHON TRUE)
Expand Down
20 changes: 6 additions & 14 deletions apps/Viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
if((NOT OpenMVS_USE_OPENGL) OR (NOT _USE_OPENGL))
RETURN()
endif()

if(NOT VIEWER_NAME)
set(VIEWER_NAME "Viewer")
endif()

# Find required packages
FIND_PACKAGE(GLEW QUIET)
if(GLEW_FOUND)
INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIRS})
ADD_DEFINITIONS(${GLEW_DEFINITIONS})
MESSAGE(STATUS "GLEW ${GLEW_VERSION} found (include: ${GLEW_INCLUDE_DIRS})")
FIND_PACKAGE(glad QUIET)
if(glad_FOUND)
MESSAGE(STATUS "GLAD ${glad_VERSION} found")
else()
MESSAGE("-- Can't find GLEW. Continuing without it.")
MESSAGE("-- Can't find GLAD. Continuing without it.")
RETURN()
endif()
FIND_PACKAGE(glfw3 QUIET)
if(glfw3_FOUND)
INCLUDE_DIRECTORIES(${glfw3_INCLUDE_DIRS})
ADD_DEFINITIONS(${glfw3_DEFINITIONS})
MESSAGE(STATUS "GLFW3 ${glfw3_VERSION} found (include: ${glfw3_INCLUDE_DIRS})")
MESSAGE(STATUS "GLFW3 ${glfw3_VERSION} found")
else()
MESSAGE("-- Can't find GLFW3. Continuing without it.")
RETURN()
Expand All @@ -35,7 +27,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;${OPENGL_LIBRARIES};${GLEW_LIBRARY};${GLFW_STATIC_LIBRARIES};GLEW::GLEW;${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;glad::glad;${GLFW_STATIC_LIBRARIES};${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Manually set Common.h as the precompiled header
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
Expand Down
11 changes: 3 additions & 8 deletions apps/Viewer/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@

// I N C L U D E S /////////////////////////////////////////////////

#include <GL/glew.h>
#include "../../libs/MVS/Common.h"
#include "../../libs/MVS/Scene.h"

#if defined(_MSC_VER)
#include <gl/GLU.h>
#elif defined(__APPLE__)
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif
#define GLAD_GL_IMPLEMENTATION
#include <glad/glad.h>
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>


Expand Down
3 changes: 2 additions & 1 deletion apps/Viewer/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ bool Scene::Init(const cv::Size& size, LPCTSTR windowName, LPCTSTR fileName, LPC
return false;
if (!window.Init(size, windowName))
return false;
if (glewInit() != GLEW_OK)
if (gladLoadGL() == 0)
return false;
VERBOSE("OpenGL: %s %s", glGetString(GL_RENDERER), glGetString(GL_VERSION));
name = windowName;
window.clbkOpenScene = DELEGATEBINDCLASS(Window::ClbkOpenScene, &Scene::Open, this);

Expand Down
11 changes: 0 additions & 11 deletions apps/Viewer/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ Window::~Window()
void Window::Release()
{
if (IsValid()) {
#ifdef _USE_NUKLEAR
nk_glfw3_shutdown();
#endif
glfwDestroyWindow(window);
window = NULL;
}
Expand Down Expand Up @@ -205,14 +202,6 @@ void Window::UpdateMousePosition(double xpos, double ypos)
}


void Window::GetFrame(Image8U3& image) const
{
image.create(GetSize());
glReadPixels(0, 0, image.width(), image.height(), GL_BGR_EXT, GL_UNSIGNED_BYTE, image.ptr());
cv::flip(image, image, 0);
}


cv::Size Window::GetSize() const
{
cv::Size _size;
Expand Down
2 changes: 0 additions & 2 deletions apps/Viewer/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ class Window
void UpdateView(const Eigen::Matrix3d& R, const Eigen::Vector3d& t);
void UpdateMousePosition(double xpos, double ypos);

void GetFrame(Image8U3&) const;

cv::Size GetSize() const;
void Resize(const cv::Size&);
static void Resize(GLFWwindow* window, int width, int height);
Expand Down
3 changes: 0 additions & 3 deletions build/Templates/ConfigLocal.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
// TIFF codec
#cmakedefine _USE_TIFF

// OpenGL support
#cmakedefine _USE_OPENGL

// OpenCL support
#cmakedefine _USE_OPENCL
#cmakedefine _USE_OPENCL_STATIC
Expand Down
4 changes: 2 additions & 2 deletions libs/MVS/DepthMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ bool DepthData::Load(const String& fileName, unsigned flags)
Camera camera;
if (!ImportDepthDataRaw(fileName, imageFileName, IDs, imageSize, camera.K, camera.R, camera.C, dMin, dMax, depthMap, normalMap, confMap, viewsMap, flags))
return false;
ASSERT(!IsValid() || (IDs.size() == images.size() && IDs.front() == GetView().GetID()));
ASSERT(!IDs.empty() && (!IsValid() || IDs.front() == GetView().GetID()));
ASSERT(depthMap.size() == imageSize);
ASSERT(depthMap.size() == size);
return true;
Expand Down Expand Up @@ -1834,7 +1834,7 @@ bool MVS::ExportDepthDataRaw(const String& fileName, const String& imageFileName
Depth dMin, Depth dMax,
const DepthMap& depthMap, const NormalMap& normalMap, const ConfidenceMap& confMap, const ViewsMap& viewsMap)
{
ASSERT(IDs.size() > 1 && IDs.size() < 256);
ASSERT(!IDs.empty() && IDs.size() < 256);
ASSERT(!depthMap.empty());
ASSERT(confMap.empty() || depthMap.size() == confMap.size());
ASSERT(viewsMap.empty() || depthMap.size() == viewsMap.size());
Expand Down
4 changes: 2 additions & 2 deletions libs/MVS/SceneReconstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <CGAL/Triangulation_cell_base_with_info_3.h>
#include <CGAL/Spatial_sort_traits_adapter_3.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_triangle_primitive.h>
#include <CGAL/AABB_traits_3.h>
#include <CGAL/AABB_triangle_primitive_3.h>
#include <CGAL/Polyhedron_3.h>

using namespace MVS;
Expand Down
3 changes: 1 addition & 2 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"default-features": false
},
"eigen3",
"glew",
"glad",
"glfw3",
"libpng",
{
Expand All @@ -24,7 +24,6 @@
"openexr"
]
},
"opengl",
"tiff",
"vcglib",
"zlib"
Expand Down

0 comments on commit c5953c0

Please sign in to comment.