From 3b1abf635ea54ea7566b2a1e5678073cdcc30872 Mon Sep 17 00:00:00 2001 From: laurentgom Date: Thu, 12 Mar 2009 21:01:50 +0000 Subject: [PATCH] Implemented proper video mode depth detection on Linux git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1045 4e206d99-4929-0410-ac5d-dfc041789085 --- samples/window/Window.cpp | 3 ++- src/SFML/Window/Linux/VideoModeSupport.cpp | 27 ++++++++++++++-------- src/SFML/Window/Linux/WindowImplX11.cpp | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/samples/window/Window.cpp b/samples/window/Window.cpp index 0f457413b..af9efd30a 100644 --- a/samples/window/Window.cpp +++ b/samples/window/Window.cpp @@ -5,6 +5,7 @@ #include #include +#include //////////////////////////////////////////////////////////// /// Entry point of application @@ -15,7 +16,7 @@ int main() { // Create the main window - sf::Window App(sf::VideoMode(640, 480, 32), "SFML Window"); + sf::Window App(sf::VideoMode(640, 480, 1), "SFML Window"); // Create a clock for measuring the time elapsed sf::Clock Clock; diff --git a/src/SFML/Window/Linux/VideoModeSupport.cpp b/src/SFML/Window/Linux/VideoModeSupport.cpp index d3287020b..b301fd124 100644 --- a/src/SFML/Window/Linux/VideoModeSupport.cpp +++ b/src/SFML/Window/Linux/VideoModeSupport.cpp @@ -63,15 +63,24 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector& Modes) XRRScreenSize* Sizes = XRRConfigSizes(Config, &NbSizes); if (Sizes && (NbSizes > 0)) { - // Add them to the video modes array - for (int i = 0; i < NbSizes; ++i) + // Get the list of supported depths + int NbDepths = 0; + int* Depths = XListDepths(Disp, Screen, &NbDepths); + if (Depths && (NbDepths > 0)) { - // Convert to sfVideoMode - VideoMode Mode(Sizes[i].width, Sizes[i].height, 32); - - // Add it only if it is not already in the array - if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end()) - Modes.push_back(Mode); + // Combine depths and sizes to fill the array of supported modes + for (int i = 0; i < NbDepths; ++i) + { + for (int j = 0; j < NbSizes; ++j) + { + // Convert to sfVideoMode + VideoMode Mode(Sizes[j].width, Sizes[j].height, Depths[i]); + + // Add it only if it is not already in the array + if (std::find(Modes.begin(), Modes.end(), Mode) == Modes.end()) + Modes.push_back(Mode); + } + } } } @@ -120,7 +129,7 @@ VideoMode VideoModeSupport::GetDesktopVideoMode() int NbSizes; XRRScreenSize* Sizes = XRRConfigSizes(Config, &NbSizes); if (Sizes && (NbSizes > 0)) - DesktopMode = VideoMode(Sizes[CurrentMode].width, Sizes[CurrentMode].height, 32); + DesktopMode = VideoMode(Sizes[CurrentMode].width, Sizes[CurrentMode].height, DefaultDepth(Disp, Screen)); // Free the configuration instance XRRFreeScreenConfigInfo(Config); diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index e63763d27..a01c0b28a 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -659,6 +659,8 @@ bool WindowImplX11::CreateContext(const VideoMode& Mode, XVisualInfo& ChosenVisu glXGetConfig(ourDisplay, &Visuals[i], GLX_SAMPLE_BUFFERS_ARB, &MultiSampling); glXGetConfig(ourDisplay, &Visuals[i], GLX_SAMPLES_ARB, &Samples); +std::cout << "Red = " << Red << " Green = " << Green << " Blue = " << Blue << std::endl; + // First check the mandatory parameters if ((RGBA == 0) || (DoubleBuffer == 0)) continue;