Skip to content

Commit

Permalink
Reorganize glut (preparation for glfw) (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Jul 29, 2018
1 parent 52120ed commit 84538aa
Show file tree
Hide file tree
Showing 65 changed files with 1,101 additions and 466 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Added voxel grid map: [#1076](https://github.com/dartsim/dart/pull/1076), [#1083](https://github.com/dartsim/dart/pull/1083)
* Added heightmap support: [#1069](https://github.com/dartsim/dart/pull/1069)

* GUI

* Reorganized OpenGL and GLUT files: [#1088](https://github.com/dartsim/dart/pull/1088)

### [DART 6.5.0 (2018-05-12)](https://github.com/dartsim/dart/milestone/41?closed=1)

* Common
Expand Down
4 changes: 2 additions & 2 deletions dart/collision/Option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#ifndef DART_COLLISION_OPTION_HPP_
#define DART_COLLISION_OPTION_HPP_

#warning "This header has been deprecated in DART 6.1. "\
"Please include CollisionOption.hpp intead."
#pragma message("This header has been deprecated in DART 6.1. "\
"Please include CollisionOption.hpp intead.")

#include "dart/collision/CollisionOption.hpp"

Expand Down
4 changes: 2 additions & 2 deletions dart/collision/Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#ifndef DART_COLLISION_RESULT_HPP_
#define DART_COLLISION_RESULT_HPP_

#warning "This header has been deprecated in DART 6.1. "\
"Please include CollisionResult.hpp intead."
#pragma message("This header has been deprecated in DART 6.1. "\
"Please include CollisionResult.hpp intead.")

#include "dart/collision/CollisionResult.hpp"

Expand Down
4 changes: 2 additions & 2 deletions dart/dynamics/MultiSphereShape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#ifndef DART_DYNAMICS_MULTISPHERESHAPE_HPP_
#define DART_DYNAMICS_MULTISPHERESHAPE_HPP_

#warning "This header has been deprecated in DART 6.2. "\
"Please include MultiSphereConvexHullShape.hpp intead."
#pragma message("This header has been deprecated in DART 6.2. "\
"Please include MultiSphereConvexHullShape.hpp intead.")

#include "dart/dynamics/MultiSphereConvexHullShape.hpp"

Expand Down
41 changes: 38 additions & 3 deletions dart/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@ else()
endif()

# Search all header and source files
file(GLOB hdrs "*.hpp")
file(GLOB srcs "*.cpp")
file(GLOB hdrs "*.hpp" "*.h" "detail/*.hpp")
file(GLOB srcs "*.cpp" "*.c" "detail/*.cpp")

function(dart_add_gui_headers)
dart_property_add(DART_GUI_HEADERS ${ARGN})
endfunction()

function(dart_add_gui_sources)
dart_property_add(DART_GUI_SOURCES ${ARGN})
endfunction()

# Add required subdirectory
add_subdirectory(glut)

get_property(dart_gui_headers GLOBAL PROPERTY DART_GUI_HEADERS)
get_property(dart_gui_sources GLOBAL PROPERTY DART_GUI_SOURCES)

# Set local target name
set(target_name ${PROJECT_NAME}-gui)
set(component_name gui)

# Add target
dart_add_library(${target_name} ${hdrs} ${srcs})
dart_add_library(${target_name}
${hdrs} ${srcs} ${dart_gui_headers} ${dart_gui_sources}
)
target_include_directories(
${target_name} SYSTEM
PUBLIC
Expand Down Expand Up @@ -62,6 +78,25 @@ add_subdirectory(osg)

# Generate header for this namespace
dart_get_filename_components(header_names "gui headers" ${hdrs})

# Remove deprecated files from the list
list(REMOVE_ITEM header_names
"GLFuncs.hpp"
"GlutWindow.hpp"
"GraphWindow.hpp"
"LoadGlut.hpp"
"MotionBlurSimWindow.hpp"
"SimWindow.hpp"
"SoftSimWindow.hpp"
"Win2D.hpp"
"Win3D.hpp"
)

set(
header_names
${header_names}
glut/glut.hpp
)
dart_generate_include_header_list(
gui_headers
"dart/gui/"
Expand Down
34 changes: 6 additions & 28 deletions dart/gui/GLFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,18 @@

#include <Eigen/Eigen>

#include "dart/common/Console.hpp"
#include "dart/math/Constants.hpp"
#include "dart/gui/LoadOpengl.hpp"
#include "dart/gui/LoadGlut.hpp"
#include "dart/gui/glut/GLUTFuncs.hpp"
// TODO(JS): remove once glut become an optional dependency

namespace dart {
namespace gui {

void drawStringOnScreen(float _x, float _y, const std::string& _s,
bool _bigFont) {
// draws text on the screen
GLint oldMode;
glGetIntegerv(GL_MATRIX_MODE, &oldMode);
glMatrixMode(GL_PROJECTION);

glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, 1.0, 0.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glRasterPos2f(_x, _y);
unsigned int length = _s.length();
for (unsigned int c = 0; c < length; c++) {
if (_bigFont)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, _s.at(c) );
else
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, _s.at(c) );
}
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(oldMode);
void drawStringOnScreen(float x, float y, const std::string& s, bool bigFont)
{
glut::drawStringOnScreen(x, y, s, bigFont);
}

// draw a 3D arrow starting from pt along dir, the arrowhead is on the other end
Expand Down
11 changes: 7 additions & 4 deletions dart/gui/GLFuncs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
#define DART_GUI_GLFUNCS_HPP_

#include <string>

#include <Eigen/Eigen>
#include "dart/common/Deprecated.hpp"

namespace dart {
namespace gui {

/// \brief
void drawStringOnScreen(float _x, float _y, const std::string& _s,
bool _bigFont = true);
/// \deprecated Deprecated in 6.6. Please use
/// dart::gui::glut::drawStringOnScreen() instead in
/// dart/gui/glut/GLUTFuncs.hpp file.
DART_DEPRECATED(6.6)
void drawStringOnScreen(float _x, float _y, const std::string& _s,
bool _bigFont = true);

/// \brief
void drawArrow3D(const Eigen::Vector3d& _pt, const Eigen::Vector3d& _dir,
Expand Down
63 changes: 7 additions & 56 deletions dart/gui/GlutWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,67 +33,18 @@
#ifndef DART_GUI_GLUTWINDOW_HPP_
#define DART_GUI_GLUTWINDOW_HPP_

#include <vector>
#pragma message("This header is deprecated as of DART 6.6. "\
"Please use dart/gui/glut/Window.hpp instead.")

#include "dart/gui/LoadOpengl.hpp"
#include "dart/gui/RenderInterface.hpp"
#include "dart/gui/glut/Window.hpp"
#include "dart/common/Deprecated.hpp"

namespace dart {
namespace gui {

/// \brief
class GlutWindow {
public:
GlutWindow();
virtual ~GlutWindow();
using GlutWindow DART_DEPRECATED(6.6) = ::dart::gui::glut::Window;

/// \warning This function should be called once.
virtual void initWindow(int _w, int _h, const char* _name);

// callback functions
static void reshape(int _w, int _h);
static void keyEvent(unsigned char _key, int _x, int _y);
static void specKeyEvent(int _key, int _x, int _y);
static void mouseClick(int _button, int _state, int _x, int _y);
static void mouseDrag(int _x, int _y);
static void mouseMove(int _x, int _y);
static void refresh();
static void refreshTimer(int _val);
static void runTimer(int _val);

static GlutWindow* current();
static std::vector<GlutWindow*> mWindows;
static std::vector<int> mWinIDs;

protected:
// callback implementation
virtual void resize(int _w, int _h) = 0;
virtual void render() = 0;
virtual void keyboard(unsigned char _key, int _x, int _y);
virtual void specKey(int _key, int _x, int _y);
virtual void click(int _button, int _state, int _x, int _y);
virtual void drag(int _x, int _y);
virtual void move(int _x, int _y);
virtual void displayTimer(int _val);
virtual void simTimer(int _val);

virtual bool screenshot();

int mWinWidth;
int mWinHeight;
int mMouseX;
int mMouseY;
double mDisplayTimeout;
bool mMouseDown;
bool mMouseDrag;
bool mCapture;
double mBackground[4];
gui::RenderInterface* mRI;
std::vector<unsigned char> mScreenshotTemp;
std::vector<unsigned char> mScreenshotTemp2;
};

} // namespace gui
} // namespace dart
} // namespace gui
} // namespace dart

#endif // DART_GUI_GLUTWINDOW_HPP_
29 changes: 5 additions & 24 deletions dart/gui/GraphWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,16 @@
#ifndef DART_GUI_GRAPHWINDOW_HPP_
#define DART_GUI_GRAPHWINDOW_HPP_

#include <vector>
#pragma message("This header is deprecated as of DART 6.6. "\
"Please use dart/gui/glut/GraphWindow.hpp instead.")

#include <Eigen/Dense>

#include "dart/gui/Win2D.hpp"
#include "dart/gui/glut/GraphWindow.hpp"
#include "dart/common/Deprecated.hpp"

namespace dart {
namespace gui {

/// \brief
class GraphWindow : public Win2D {
public:
/// \brief
GraphWindow();

/// \brief
virtual ~GraphWindow();

/// \brief
void draw() override;

/// \brief
void keyboard(unsigned char _key, int _x, int _y) override;

void setData(Eigen::VectorXd _data);

protected:
Eigen::VectorXd mData;
};
using GraphWindow DART_DEPRECATED(6.6) = ::dart::gui::glut::GraphWindow;

} // namespace gui
} // namespace dart
Expand Down
14 changes: 4 additions & 10 deletions dart/gui/LoadGlut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@
#ifndef DART_GUI_LOADGLUT_HPP_
#define DART_GUI_LOADGLUT_HPP_

#if defined(_WIN32)
#include <cstdlib> // To disable glut::exit() function
#include <GL/glut.h>
#elif defined(__linux__)
#include <GL/glut.h>
#elif defined(__APPLE__)
#include <GLUT/glut.h>
#else
#error "Load OpenGL Error: What's your operating system?"
#endif
#pragma message("This file is deprecated as of DART 6.6. "\
"Please use dart/gui/glut/LoadGlut.hpp instead.")

#include "dart/gui/glut/LoadGlut.hpp"

#endif // DART_GUI_LOADGLUT_HPP_
46 changes: 8 additions & 38 deletions dart/gui/MotionBlurSimWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,19 @@
#ifndef DART_GUI_MOTIONBLURSIMWINDOW_HPP_
#define DART_GUI_MOTIONBLURSIMWINDOW_HPP_

#include <vector>
#include <Eigen/Dense>
#pragma message("This header is deprecated as of DART 6.6. "\
"Please use dart/gui/glut/MotionBlurSimWindow.hpp instead.")

#include "dart/gui/SimWindow.hpp"
#include "dart/gui/glut/MotionBlurSimWindow.hpp"
#include "dart/common/Deprecated.hpp"

namespace dart {
namespace gui {

class MotionBlurSimWindow : public SimWindow
{
public:
using MotionBlurSimWindow DART_DEPRECATED(6.6) =
::dart::gui::glut::MotionBlurSimWindow;

/// \brief
MotionBlurSimWindow();

/// \brief
virtual ~MotionBlurSimWindow();

// Set the Quality of Motion Blur
// Default is 5 (record position of every frame)
// int from 0 (No motion blur) - 5 (Highest)
// The function takes value smaller than 0 as 0, larger than 5 as 5
void setMotionBlurQuality(int _val);

// Override the render function in dart/gui/Win3D.hpp
// To draw the motion image
// Render function is called once per GUI display time
// but in MotionBlurSimWindow, draw function will run in motion blur frequency
void render() override;

// Override the display timer,
// Move the part of "step" in world function to the render function
void displayTimer(int _val) override;

protected:
// Determines the frequency of the motion blur
// Default is 1, which means motion blur effect has the highest quality
// When set to m, motion blur record data every m frames
int mMotionBlurFrequency;

}; // End of Class Definition

} // namespace gui
} // namespace dart
} // namespace gui
} // namespace dart

#endif // DART_GUI_MOTIONBLURSIMWINDOW_HPP_
Loading

0 comments on commit 84538aa

Please sign in to comment.