Skip to content

Commit

Permalink
Rewrite font rendering in OpenGL 3, minor tweaks and features
Browse files Browse the repository at this point in the history
- Migrate to OpenGL 3 (adds support for OpenGL core profile). This also
means that this project no longer requires FTGL. Also, the text looks
better now.
- Use std::chrono instead of sys/time.h.
- Add support for configuring GLXOSD by specifying the path to
the configuration file.
  • Loading branch information
nickguletskii committed Jun 30, 2014
1 parent 9d8faa8 commit 9a589a7
Show file tree
Hide file tree
Showing 35 changed files with 1,773 additions and 330 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG

This file was deleted.

10 changes: 2 additions & 8 deletions CMakeLists.txt
Expand Up @@ -9,8 +9,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/modules/")
##### Compiler #####
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
##### Set version #####
set(GLXOSD_VERSION_MAJOR 1)
set(GLXOSD_VERSION_MINOR 4)
set(GLXOSD_VERSION_MAJOR 2)
set(GLXOSD_VERSION_MINOR 1)
set(GLXOSD_VERSION_PATCH 1)
set(GLXOSD_VERSION_STRING ${GLXOSD_VERSION_MAJOR}.${GLXOSD_VERSION_MINOR}.${GLXOSD_VERSION_PATCH})
##### Find the libraries #####
Expand All @@ -37,12 +37,6 @@ include_directories(${FONTCONFIG_INCLUDE_DIRS})
if(NOT FONTCONFIG_FOUND)
message(ERROR " FontConfig not found!")
endif(NOT FONTCONFIG_FOUND)
#Find FontConfig
find_package(FTGL REQUIRED)
include_directories(${FTGL_INCLUDE_DIRS})
if(NOT FTGL_FOUND)
message(ERROR " FTGL not found!")
endif(NOT FTGL_FOUND)
#Find X11
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIRS})
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -21,10 +21,10 @@ Before compiling, you need to make sure that you have GCC and CMake installed. O
sudo apt-get install build-essential cmake
```

We also need to make sure that the required libraries and their headers are installed. This project requires OpenGL, GLU, GLX, FontConfig, Freetype, Boost, FTGL and libsensors. To install them on Ubuntu, execute this:
We also need to make sure that the required libraries and their headers are installed. This project requires OpenGL, GLU, GLX, FontConfig, Freetype, Boost, and libsensors. To install them on Ubuntu, execute this:

```
sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libfontconfig1-dev libfreetype6-dev libsensors4-dev libboost-dev libftgl2 libftgl-dev
sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libfontconfig1-dev libfreetype6-dev libsensors4-dev libboost-dev
```

Then, compile:
Expand Down
56 changes: 42 additions & 14 deletions conf/glxosd.conf
Expand Up @@ -10,26 +10,53 @@

# The name of the font to be used.
font_name = CPMono_v07 Bold

# The size of the font to be used.
font_size_int = 16
# The colour of the text in RGB. 0 = no light, 255 = maximum light. For example:
# 0 , 0 , 0 is black.
# 255, 0 , 0 is red.
# 0 , 255, 0 is green.
# 0 , 0 , 255 is blue.
# 255, 255, 255 is white.

# DPI (horizontal). When this property is not set, GLXOSD will attempt to auto-detect
# the value from your first screen.
#font_dpi_horizontal_int = 72

# DPI (vertical). When this property is not set, GLXOSD will attempt to auto-detect
# the value from your first screen.
#font_dpi_vertical_int = 72

# The colour of the text in RGBA. 0 = no light, 255 = maximum light. For example:
# 0 , 0 , 0 , 255 is black.
# 255, 0 , 0 , 255 is red.
# 0 , 255, 0 , 255 is green.
# 0 , 0 , 255, 255 is blue.
# 255, 255, 255, 255 is white.
# 255, 0 , 255, 255 is magenta.
# 255, 255, 255, 128 is half-transparent white.
font_colour_r_int = 255
font_colour_g_int = 0
font_colour_b_int = 255
font_colour_a_int = 255

# The colour of the text outline in RGBA.
font_outline_colour_r_int = 0
font_outline_colour_g_int = 0
font_outline_colour_b_int = 0
font_outline_colour_a_int = 255

# Width of the outline, in points (pt). Can be a real number, e.g. 1.5
font_outline_width_float = 1

# Toggles the outline. Deprecated.
# Set to true and set width to zero if you don't want the outline.
show_text_outline_bool = true

# Position of the text in pixels, starting from the top left corner.
text_pos_x_int = 4
text_pos_y_int = 2
# Spacing between characters.
text_spacing_x_int = 2
# Spacing between lines.
text_spacing_y_int = 2
# If true, a black outline will be rendered around the text, making it easier to see the text.
show_text_outline_bool = true
text_pos_y_int = 4

# Spacing between characters, in points (pt). Can be a real number, e.g. 1.5
text_spacing_x_float = 0

# Spacing between lines, in points (pt). Can be a real number, e.g. 1.5
text_spacing_y_float = 0

##### GENERAL INFORMATION SETTINGS #####

Expand All @@ -47,6 +74,7 @@ temperature_format = %1$i C
# The format string that gets printed for each chip that reports temperature through libsensors.
# The only argument is the name of the chip.
libsensors_chip_format = %1%:\n

# The format string that prints the feature name and it's temperature.
# For each chip, there are different "features".
# For example, an Intel 2500k has 5 temperature sensors - one is a general sensor, and a sensor for each core.
Expand All @@ -56,7 +84,7 @@ libsensors_chip_feature_format = " %1%: %2%\n"

# This is a filter for features.
# If you don't want to see the temperatures of different cores, or something similar, this is for you.
# Features with names that match this regex (Boost variation) will not be displayed.
# Features with names that match this regex (Boost Xpressive variation) will not be displayed.
libsensors_chip_feature_filter = NULL
# For example, the following line contains a filter that will hide individual core information on a 2500k.
#libsensors_chip_feature_filter = Core.*
Expand Down
5 changes: 4 additions & 1 deletion launcher_template.sh
Expand Up @@ -3,6 +3,7 @@
function showHelp() {
echo "Usage: glxosd [options] command"
echo " -h or --help : show this help message"
echo " -c or --config : specify the path to the config"
echo " -s or --steam : inject Steam overlay"
echo " --steam-path [path] : set path to Steam"
echo "Also, you can set GLXOSD_PRELOAD in the same way as LD_PRELOAD, except that GLXOSD_PRELOAD will be in LD_PRELOAD before GLXOSD libraries."
Expand All @@ -19,11 +20,13 @@ while : ; do
-h|--help)
showHelp;
exit 0;;
-c|--config)
export GLXOSD_CONFIG_PATH="$2"
shift 2 ;;
-s|--steam)
INJECT_STEAM_OVERLAY=true;
shift 1;;
--steam-path)
[ -n "${STEAM_PATH}" ]
STEAM_PATH="$2"
shift 2 ;;
*)
Expand Down
11 changes: 0 additions & 11 deletions modules/FindFTGL.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion src/glinject/glinject.cpp
Expand Up @@ -9,8 +9,8 @@
*/

#include "glinject.hpp"
#include "elfhacks.hpp"
#include <dlfcn.h>
#include <elfhacks.hpp>
#include <GL/gl.h>
#include <stddef.h>
#include <cstdlib>
Expand Down
2 changes: 1 addition & 1 deletion src/glxosd-libsensors-support/CMakeLists.txt
@@ -1,7 +1,7 @@
SET(GLXOSD_LIBSENSORS_SUPPORT_SOURCE_FILES LibsensorsSensorDataProvider.cpp)
add_library(glxosd-libsensors-support SHARED ${GLXOSD_LIBSENSORS_SUPPORT_SOURCE_FILES})
add_dependencies(glxosd-libsensors-support glxosd)
target_link_libraries(glxosd-libsensors-support dl rt ${SENSORS_LIBRARIES} ${OUTPUT_DIR}/libglxosd.so)
target_link_libraries(glxosd-libsensors-support dl rt ${SENSORS_LIBRARIES} ${Boost_LIBRARIES} ${OUTPUT_DIR}/libglxosd.so)
set_target_properties(glxosd-libsensors-support PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR} LIBRARY_OUTPUT_NAME glxosd-plugins-libsensors-support)
set_target_properties(glxosd-libsensors-support PROPERTIES VERSION ${GLXOSD_VERSION_STRING}
SOVERSION ${GLXOSD_VERSION_MAJOR})
Expand Down
46 changes: 24 additions & 22 deletions src/glxosd-libsensors-support/LibsensorsSensorDataProvider.cpp
Expand Up @@ -8,44 +8,46 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "GLXOSD.hpp"
#include "LibsensorsSensorDataProvider.hpp"
#include "ConfigurationManager.hpp"
#include <boost/format.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <ConfigurationManager.hpp>
#include <GLXOSD.hpp>
#include <sensors/sensors.h>
#include "LibsensorsSensorDataProvider.hpp"
#include <sstream>
#include <string>

boost::format chipFormat;
boost::format libsensorsChipFeatureFormat;
boost::xpressive::sregex libsensorsChipFeatureFilter;
boost::format temperatureFormat;
void glxosdPluginConstructor(glxosd::GLXOSD *glxosd) {
glxosd->getConfigurationManager()->addDefaultConfigurationValue(
"libsensors_chip_format", boost::format("%1%:\n"));
glxosd->getConfigurationManager()->addDefaultConfigurationValue(
glxosd::ConfigurationManager &configurationManager =
glxosd->getConfigurationManager();
configurationManager.addDefaultConfigurationValue("libsensors_chip_format",
boost::format("%1%:\n"));
configurationManager.addDefaultConfigurationValue(
"libsensors_chip_feature_format", boost::format(" %1%: %2%\n"));
glxosd->getConfigurationManager()->addDefaultConfigurationValue(
configurationManager.addDefaultConfigurationValue(
"libsensors_chip_feature_filter",
boost::xpressive::sregex::compile("Core.*",
boost::xpressive::regex_constants::icase));
sensors_init(NULL);
}

std::string* glxosdPluginDataProvider(glxosd::GLXOSD *glxosdInstance) {

glxosd::ConfigurationManager* configurationManager =
glxosdInstance->getConfigurationManager();

auto chipFormat = configurationManager->getProperty<boost::format>(
chipFormat = configurationManager.getProperty<boost::format>(
"libsensors_chip_format");

auto libsensorsChipFeatureFormat = configurationManager->getProperty<
boost::format>("libsensors_chip_feature_format");

auto libsensorsChipFeatureFilter = configurationManager->getProperty<
libsensorsChipFeatureFormat =
configurationManager.getProperty<boost::format>(
"libsensors_chip_feature_format");
libsensorsChipFeatureFilter = configurationManager.getProperty<
boost::xpressive::sregex>("libsensors_chip_feature_filter");

auto temperatureFormat = configurationManager->getProperty<boost::format>(
temperatureFormat = configurationManager.getProperty<boost::format>(
"temperature_format");

sensors_init(NULL);
}

std::string* glxosdPluginDataProvider(glxosd::GLXOSD *glxosdInstance) {

sensors_chip_name const * chip;
int chipNumber = 0;

Expand Down
Expand Up @@ -7,6 +7,7 @@
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef LIBSENSORS_SENSOR_DATA_PROVIDER_HPP_
#define LIBSENSORS_SENSOR_DATA_PROVIDER_HPP_

Expand Down
39 changes: 23 additions & 16 deletions src/glxosd-nvidia-support/NvidiaSensorDataProvider.cpp
Expand Up @@ -7,6 +7,7 @@
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "NvidiaSensorDataProvider.hpp"
#include "ConfigurationManager.hpp"
#include "GLXOSD.hpp"
Expand All @@ -18,9 +19,15 @@
int numberOfGpus;
Display *display;
std::string errorResult;
boost::format nvidiaGPUFormat;
std::vector<std::string> displayNames;
void glxosdPluginConstructor(glxosd::GLXOSD *glxosd) {
glxosd->getConfigurationManager()->addDefaultConfigurationValue(
glxosd->getConfigurationManager().addDefaultConfigurationValue(
"nvidia_gpu_format", boost::format("%1% (%2%): %3%\n"));

nvidiaGPUFormat = glxosd->getConfigurationManager().getProperty < boost::format
> ("nvidia_gpu_format");

int event, error;

display = XOpenDisplay(NULL);
Expand All @@ -29,40 +36,40 @@ void glxosdPluginConstructor(glxosd::GLXOSD *glxosd) {
|| !XNVCTRLQueryTargetCount(display, NV_CTRL_TARGET_TYPE_GPU,
&numberOfGpus)) {
errorResult = "Couldn't read the number of NVIDIA GPUs.";
} else {
for (int i = 0; i < numberOfGpus; i++) {
char *name;
if (XNVCTRLQueryTargetStringAttribute(display,
NV_CTRL_TARGET_TYPE_GPU, i, 0,
NV_CTRL_STRING_PRODUCT_NAME, &name) != True) {
displayNames.push_back(std::string("unknown"));
} else {
displayNames.push_back(std::string(name));
}
}
}
}

std::string* glxosdPluginDataProvider(glxosd::GLXOSD *glxosdInstance) {
if (!errorResult.empty()) {
return new std::string(errorResult);
}
glxosd::ConfigurationManager* configurationManager =
glxosdInstance->getConfigurationManager();
std::stringstream stringBuilder;

for (int i = 0; i < numberOfGpus; i++) {
char *name;
int temperature;

if ((XNVCTRLQueryTargetAttribute(display,
NV_CTRL_TARGET_TYPE_GPU, i, 0,
NV_CTRL_GPU_CORE_TEMPERATURE, &temperature) != True)
|| (XNVCTRLQueryTargetStringAttribute(display,
NV_CTRL_TARGET_TYPE_GPU, i, 0,
NV_CTRL_STRING_PRODUCT_NAME, &name) != True)) {
NV_CTRL_GPU_CORE_TEMPERATURE, &temperature) != True)) {
stringBuilder
<< (boost::format(
configurationManager->getProperty < boost::format
> ("nvidia_gpu_format"))) % "unknown" % i
<< (boost::format(nvidiaGPUFormat)) % "unknown" % i
% "failed to get the temperature!";
} else {
stringBuilder
<< boost::format(

configurationManager->getProperty < boost::format
> ("nvidia_gpu_format")) % name % i
<< boost::format(nvidiaGPUFormat) % displayNames[i] % i
% (boost::format(
glxosdInstance->getConfigurationManager()->getProperty<
glxosdInstance->getConfigurationManager().getProperty<
boost::format>(
"temperature_format")) % temperature);
}
Expand Down
3 changes: 2 additions & 1 deletion src/glxosd-nvidia-support/NvidiaSensorDataProvider.hpp
Expand Up @@ -7,11 +7,12 @@
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef NVIDIA_SENSOR_DATA_PROVIDER_HPP_
#define NVIDIA_SENSOR_DATA_PROVIDER_HPP_
#include "GLXOSD.hpp"
#include <boost/format.hpp>
#include <X11/Xlib.h>
#include "GLXOSD.hpp"
class GLXOSD;

extern "C" void glxosdPluginConstructor(glxosd::GLXOSD *glxosd);
Expand Down
4 changes: 2 additions & 2 deletions src/glxosd/CMakeLists.txt
@@ -1,7 +1,7 @@
set(GLXOSD_SOURCE_FILES GLXOSD.cpp GLXOSDLoader.cpp OSDInstance.cpp ConfigurationManager.cpp Utils.cpp)
set(GLXOSD_SOURCE_FILES GLXOSD.cpp GLXOSDLoader.cpp OSDInstance.cpp ConfigurationManager.cpp Utils.cpp GLAttribState.cpp FontRenderer.cpp ShaderProgram.cpp VertexBuffer.cpp Colour.cpp)
add_library(glxosd SHARED ${GLXOSD_SOURCE_FILES})
add_dependencies(glxosd glinject)
target_link_libraries(glxosd dl rt ${FTGL_LIBRARY} ${FREETYPE_LIBRARIES} ${OPENGL_LIBRARIES} ${FONTCONFIG_LIBRARY} ${SENSORS_LIBRARIES} ${Boost_LIBRARIES} ${OUTPUT_DIR}/libglxosd-glinject.so)
target_link_libraries(glxosd dl rt ${FREETYPE_LIBRARIES} ${OPENGL_LIBRARIES} ${FONTCONFIG_LIBRARY} ${SENSORS_LIBRARIES} ${Boost_LIBRARIES} ${OUTPUT_DIR}/libglxosd-glinject.so)
set_target_properties(glxosd PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_DIR} LIBRARY_OUTPUT_NAME glxosd)
set_target_properties(glxosd PROPERTIES VERSION ${GLXOSD_VERSION_STRING}
SOVERSION ${GLXOSD_VERSION_MAJOR})
Expand Down

0 comments on commit 9a589a7

Please sign in to comment.