Skip to content

Commit

Permalink
Fix simple_demo on Windows (#987)
Browse files Browse the repository at this point in the history
Signed-off-by: Silvio Traversaro <[email protected]>
  • Loading branch information
traversaro authored Apr 15, 2024
1 parent 8128bb8 commit ef05935
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion examples/simple_demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ if (NOT APPLE)
link_directories(${GLEW_LIBRARY_DIRS})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()

add_executable(simple_demo Main.cc GlutWindow.cc)

Expand Down
23 changes: 22 additions & 1 deletion examples/simple_demo/GlutWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
#include <OpenGL/gl.h>
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#elif _WIN32
#define NOMINMAX
#include <windows.h>
#include <GL/glew.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "Wingdi.h"
#else
#include <GL/glew.h>
#include <GL/gl.h>
Expand Down Expand Up @@ -57,6 +64,10 @@ bool g_initContext = false;
CGLContextObj g_context;
CGLContextObj g_glutContext;
#elif _WIN32
HGLRC g_context = 0;
HDC g_display = 0;
HGLRC g_glutContext = 0;
HDC g_glutDisplay = 0;
#else
GLXContext g_context;
Display *g_display;
Expand All @@ -73,7 +84,7 @@ double g_offset = 0.0;
void updateCameras()

{
double angle = g_offset / 2 * M_PI;
double angle = g_offset / 2 * GZ_PI;
double x = sin(angle) * 3.0 + 3.0;
double y = cos(angle) * 3.0;
for (ir::CameraPtr camera : g_cameras)
Expand All @@ -91,6 +102,11 @@ void displayCB()
#if __APPLE__
CGLSetCurrentContext(g_context);
#elif _WIN32
if (!wglMakeCurrent(g_display, g_context))
{
std::cerr << "Error calling wglMakeCurrent" << '\n';
exit(-1);
}
#else
if (g_display)
{
Expand All @@ -103,6 +119,7 @@ void displayCB()
#if __APPLE__
CGLSetCurrentContext(g_glutContext);
#elif _WIN32
wglMakeCurrent(g_glutDisplay, g_glutContext);
#else
glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext);
#endif
Expand Down Expand Up @@ -182,6 +199,8 @@ void run(std::vector<ir::CameraPtr> _cameras)
#if __APPLE__
g_context = CGLGetCurrentContext();
#elif _WIN32
g_context = wglGetCurrentContext();
g_display = wglGetCurrentDC();
#else
g_context = glXGetCurrentContext();
g_display = glXGetCurrentDisplay();
Expand All @@ -196,6 +215,8 @@ void run(std::vector<ir::CameraPtr> _cameras)
#if __APPLE__
g_glutContext = CGLGetCurrentContext();
#elif _WIN32
g_glutContext = wglGetCurrentContext();
g_glutDisplay = wglGetCurrentDC();
#else
g_glutDisplay = glXGetCurrentDisplay();
g_glutDrawable = glXGetCurrentDrawable();
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_demo/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glut.h>
#else
#include <GL/glut.h>
#endif

#include <iostream>
Expand Down

0 comments on commit ef05935

Please sign in to comment.