正确输出显示器数量,以及显示模式
This commit is contained in:
parent
c4db898439
commit
b7248b3e97
@ -1,3 +1,3 @@
|
||||
add_executable(NullWindow main.cpp)
|
||||
|
||||
target_link_libraries(NullWindow PRIVATE MathGeoLib glfw GL)
|
||||
target_link_libraries(NullWindow PRIVATE MathGeoLib glfw GL ULRE.RenderDevice)
|
||||
|
@ -1,38 +1,68 @@
|
||||
#include<GLFW/glfw3.h>
|
||||
#include<hgl/render/device/RenderDevice.h>
|
||||
#include<iostream>
|
||||
|
||||
using namespace hgl;
|
||||
|
||||
void put(const struct VideoMode *vm)
|
||||
{
|
||||
std::cout<<"\t"<<vm->width<<"x"<<vm->height<<","<<vm->bit<<"bits,"<<vm->freq<<"hz";
|
||||
}
|
||||
|
||||
void put(const struct Display *disp)
|
||||
{
|
||||
std::cout<<"["<<disp->name.c_str()<<"]["<<disp->width<<"x"<<disp->height<<"]["<<disp->x<<","<<disp->y<<"]"<<std::endl;
|
||||
|
||||
std::cout<<"\tcurrent video mode: ";
|
||||
put(disp->GetCurVideoMode());
|
||||
std::cout<<std::endl;
|
||||
|
||||
const ObjectList<VideoMode> &vml=disp->GetVideoModeList();
|
||||
|
||||
for(int i=0;i<vml.GetCount();i++)
|
||||
{
|
||||
std::cout<<"\t"<<i<<" : ";
|
||||
put(vml[i]);
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
RenderDevice *device=CreateRenderDeviceGLFW();
|
||||
|
||||
/* Initialize the library */
|
||||
if (!glfwInit())
|
||||
return -1;
|
||||
|
||||
/* Create a windowed mode window and its OpenGL context */
|
||||
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
if(!device)
|
||||
{
|
||||
glfwTerminate();
|
||||
std::cerr<<"Create RenderDevice(GLFW) failed."<<std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Make the window's context current */
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
/* Loop until the user closes the window */
|
||||
while (!glfwWindowShouldClose(window))
|
||||
if(!device->Init())
|
||||
{
|
||||
/* Render here */
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
/* Swap front and back buffers */
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
/* Poll for and process events */
|
||||
glfwPollEvents();
|
||||
std::cerr<<"Init RenderDevice(GLFW) failed."<<std::endl;
|
||||
return -2;
|
||||
}
|
||||
|
||||
{
|
||||
const UTF8String device_name=device->GetName();
|
||||
|
||||
std::cout<<"RenderDevice: "<<device_name.c_str()<<std::endl;
|
||||
}
|
||||
|
||||
List<Display *> disp_list;
|
||||
|
||||
device->GetDisplayList(disp_list);
|
||||
|
||||
const int count=disp_list.GetCount();
|
||||
|
||||
std::cout<<"Device have "<<count<<" display."<<std::endl;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
std::cout<<"Display "<<i<<" ";
|
||||
put(GetObject(disp_list,i));
|
||||
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
virtual const VideoMode *GetCurVideoMode()=0;
|
||||
virtual const ObjectList<VideoMode> &GetVideoModeList()=0;
|
||||
virtual const VideoMode *GetCurVideoMode()const=0;
|
||||
virtual const ObjectList<VideoMode> &GetVideoModeList()const=0;
|
||||
};
|
||||
|
||||
struct WindowSetup
|
||||
@ -108,7 +108,7 @@ namespace hgl
|
||||
|
||||
virtual const UTF8String GetName()=0; ///<取得设备名称
|
||||
|
||||
virtual const void GetDisplayList(List<Display *> &); ///<取得显示屏列表
|
||||
virtual const void GetDisplayList(List<Display *> &)=0; ///<取得显示屏列表
|
||||
virtual const Display * GetDefaultDisplay()=0; ///<取得默认显示屏
|
||||
|
||||
public:
|
||||
|
@ -22,13 +22,13 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
const VideoMode *GetCurVideoMode()override{return cur_video_mode;}
|
||||
const ObjectList<VideoMode> &GetVideoModeList()override{return video_mode_list;}
|
||||
const VideoMode *GetCurVideoMode()const override{return cur_video_mode;}
|
||||
const ObjectList<VideoMode> &GetVideoModeList()const override{return video_mode_list;}
|
||||
};
|
||||
|
||||
VideoMode *ConvertVideoMode(const GLFWvidmode *mode)
|
||||
{
|
||||
if(mode)
|
||||
if(!mode)
|
||||
return nullptr;
|
||||
|
||||
VideoMode *vm=new VideoMode;
|
||||
@ -95,12 +95,12 @@ namespace hgl
|
||||
const bool Init()override{return true;}
|
||||
const void Close()override{};
|
||||
|
||||
const UTF8String GetName()override ///<取得设备名称
|
||||
const UTF8String GetName()override
|
||||
{
|
||||
return UTF8String("GLFW")+UTF8String(glfwGetVersionString());
|
||||
return UTF8String("GLFW ")+UTF8String(glfwGetVersionString());
|
||||
}
|
||||
|
||||
const void GetDisplayList(List<Display *> &disp_list) ///<取得显示屏列表
|
||||
const void GetDisplayList(List<Display *> &disp_list) override
|
||||
{
|
||||
int count=0;
|
||||
|
||||
@ -110,7 +110,7 @@ namespace hgl
|
||||
disp_list+=GetDisplayAttrib(ml[i]);
|
||||
}
|
||||
|
||||
const Display * GetDefaultDisplay()
|
||||
const Display * GetDefaultDisplay() override
|
||||
{
|
||||
if(!default_display)
|
||||
default_display=GetDisplayAttrib(glfwGetPrimaryMonitor());
|
||||
|
Loading…
x
Reference in New Issue
Block a user