1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
bool SoftPixelDeviceLinux::openGraphicsScreen(
const dim::size2di &Resolution, s32 ColorDepth,
const io::stringc &Title, bool isFullScreen, const SDeviceFlags &Flags)
{
/* Open an X-server display */
Display_ = XOpenDisplay(0);
if (!Display_)
{
io::Log::error("Could not open display, need running X Server");
return false;
}
RootWnd_ = DefaultRootWindow(Display_);
/* Choose the visual */
s32 major, minor;
if (!glXQueryExtension(Display_, &major, &minor))
{
io::Log::error("GLX is not supported, OpenGL will not work");
return false;
}
s32 Attributes[] = {
GLX_RGBA, GL_TRUE,
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_ALPHA_SIZE, 1,
GLX_DEPTH_SIZE, 24,
GLX_DOUBLEBUFFER, GL_TRUE,
GLX_STENCIL_SIZE, 1,
None
};
Visual_ = glXChooseVisual(Display_, 0, Attributes);
if (!Visual_)
{
io::Log::error("Could not choose visual mode");
return false;
}
/* Create the colormap */
ColorMap_ = XCreateColormap(Display_, RootWnd_, Visual_->visual, AllocNone);
/* Get all video modes */
s32 ModesCount, BestMode = 0;
XF86VidModeModeInfo** modes;
XF86VidModeGetAllModeLines(Display_, Screen_, &ModesCount, &modes);
DesktopVideoMode_ = *modes[0];
SetWndAttrb_.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
/* Create the window */
if (isFullscreen_)
{
/* Find suitable video mode */
for (s32 i = 0; i < ModesCount; ++i)
{
if (modes[i]->hdisplay == Resolution_.Width && modes[i]->vdisplay == Resolution_.Height)
BestMode = i;
}
/* Switch to fullscreen mode */
Screen_ = DefaultScreen(Display_);
XF86VidModeSwitchToMode(Display_, Screen_, modes[BestMode]);
XF86VidModeSetViewPort(Display_, Screen_, 0, 0);
XFree(modes);
/* Set window attributes */
SetWndAttrb_.colormap = ColorMap_;
SetWndAttrb_.event_mask |= StructureNotifyMask;
SetWndAttrb_.override_redirect = true;
/* Create the window */
Window_ = XCreateWindow(
Display_,
RootWnd_,
0,
0,
Resolution_.Width,
Resolution_.Height,
0,
Visual_->depth,
InputOutput,
Visual_->visual,
CWColormap | CWEventMask | CWOverrideRedirect,
&SetWndAttrb_
);
/* Grab keyboard and mouse */
XMapRaised(Display_, Window_);
XGrabKeyboard(Display_, Window_, true, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(
Display_, Window_, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, Window_, None, CurrentTime
);
}
else
{
/* Set window attributes */
SetWndAttrb_.colormap = ColorMap_;
/* Create the window */
Window_ = XCreateWindow(
Display_,
RootWnd_,
(DesktopVideoMode_.hdisplay/2 - Resolution_.Width/2),
(DesktopVideoMode_.vdisplay/2 - Resolution_.Height/2),
Resolution_.Width,
Resolution_.Height,
0,
Visual_->depth,
InputOutput,
Visual_->visual,
CWColormap | CWEventMask,
&SetWndAttrb_
);
}
__Screen_Width = Resolution_.Width;
__Screen_Height = Resolution_.Height;
/* Set resizablility */
if (!Flags.isResizAble)
{
XSizeHints* Hints = XAllocSizeHints();
Hints->flags = PSize | PMinSize | PMaxSize;
Hints->min_width = Hints->max_width = Hints->base_width = Resolution_.Width;
Hints->min_height = Hints->max_height = Hints->base_height = Resolution_.Height;
XSetWMNormalHints(Display_, Window_, Hints);
XFree(Hints);
}
/* Show the window and set its title */
XMapWindow(Display_, Window_);
XStoreName(Display_, Window_, Title_.c_str());
/* Position the window */
if (!isFullscreen_)
{
XWindowChanges ChangeAttributes;
{
ChangeAttributes.x = (DesktopVideoMode_.hdisplay/2 - Resolution_.Width/2);
ChangeAttributes.y = (DesktopVideoMode_.vdisplay/2 - Resolution_.Height/2);
}
XConfigureWindow(Display_, Window_, CWX | CWY, &ChangeAttributes);
}
/* Create OpenGL context */
Context_ = glXCreateContext(Display_, Visual_, 0, GL_TRUE);
glXMakeCurrent(Display_, Window_, Context_);
/* Share the device context members */
__spVideoDriver->Display_ = Display_;
__spVideoDriver->Window_ = &Window_;
return true;
}
|