rays 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/rays/bitmap.cpp +100 -33
- data/.doc/ext/rays/bounds.cpp +2 -2
- data/.doc/ext/rays/camera.cpp +2 -2
- data/.doc/ext/rays/color.cpp +2 -2
- data/.doc/ext/rays/color_space.cpp +3 -3
- data/.doc/ext/rays/font.cpp +5 -4
- data/.doc/ext/rays/image.cpp +1 -1
- data/.doc/ext/rays/matrix.cpp +4 -4
- data/.doc/ext/rays/painter.cpp +1 -1
- data/.doc/ext/rays/point.cpp +2 -2
- data/.doc/ext/rays/polygon.cpp +3 -3
- data/.doc/ext/rays/polyline.cpp +3 -3
- data/.doc/ext/rays/rays.cpp +10 -10
- data/.doc/ext/rays/shader.cpp +2 -2
- data/.github/workflows/release-gem.yml +2 -2
- data/.github/workflows/tag.yml +1 -1
- data/.github/workflows/test.yml +10 -1
- data/ChangeLog.md +14 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +17 -2
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +100 -33
- data/ext/rays/bounds.cpp +2 -2
- data/ext/rays/camera.cpp +2 -2
- data/ext/rays/color.cpp +2 -2
- data/ext/rays/color_space.cpp +3 -3
- data/ext/rays/defs.h +2 -0
- data/ext/rays/extconf.rb +4 -2
- data/ext/rays/font.cpp +5 -4
- data/ext/rays/image.cpp +1 -1
- data/ext/rays/matrix.cpp +4 -4
- data/ext/rays/painter.cpp +1 -1
- data/ext/rays/point.cpp +2 -2
- data/ext/rays/polygon.cpp +3 -3
- data/ext/rays/polyline.cpp +3 -3
- data/ext/rays/rays.cpp +10 -10
- data/ext/rays/shader.cpp +2 -2
- data/include/rays/color_space.h +4 -4
- data/include/rays/defs.h +7 -0
- data/include/rays/rays.h +8 -0
- data/include/rays/ruby/bitmap.h +2 -2
- data/include/rays/ruby/bounds.h +2 -2
- data/include/rays/ruby/camera.h +2 -2
- data/include/rays/ruby/color.h +2 -2
- data/include/rays/ruby/color_space.h +2 -2
- data/include/rays/ruby/exception.h +3 -3
- data/include/rays/ruby/font.h +2 -2
- data/include/rays/ruby/image.h +2 -2
- data/include/rays/ruby/matrix.h +2 -2
- data/include/rays/ruby/painter.h +2 -2
- data/include/rays/ruby/point.h +2 -2
- data/include/rays/ruby/polygon.h +2 -2
- data/include/rays/ruby/polyline.h +2 -2
- data/include/rays/ruby/rays.h +6 -6
- data/include/rays/ruby/shader.h +2 -2
- data/include/rays/ruby.h +3 -1
- data/include/rays.h +3 -0
- data/lib/rays/bitmap.rb +7 -0
- data/lib/rays/extension.rb +4 -0
- data/rays.gemspec +2 -2
- data/src/coord.h +2 -2
- data/src/font.cpp +1 -0
- data/src/image.cpp +0 -29
- data/src/ios/bitmap.mm +23 -30
- data/src/ios/font.mm +4 -1
- data/src/ios/opengl.mm +23 -10
- data/src/ios/rays.mm +5 -3
- data/src/matrix.h +1 -1
- data/src/opengl.h +7 -8
- data/src/osx/bitmap.mm +23 -30
- data/src/osx/font.mm +4 -1
- data/src/osx/opengl.mm +31 -19
- data/src/osx/rays.mm +5 -3
- data/src/painter.cpp +1 -0
- data/src/shader.cpp +3 -0
- data/src/texture.cpp +3 -25
- data/src/texture.h +0 -2
- data/src/win32/bitmap.cpp +167 -65
- data/src/win32/camera.cpp +119 -0
- data/src/win32/font.cpp +179 -40
- data/src/win32/gdi.cpp +2 -4
- data/src/win32/gdi.h +1 -1
- data/src/win32/opengl.cpp +127 -0
- data/src/win32/rays.cpp +16 -9
- data/test/helper.rb +2 -5
- data/test/test_bitmap.rb +3 -1
- data/test/test_image.rb +8 -14
- data/test/test_painter.rb +4 -4
- metadata +8 -8
- data/include/rays/opengl.h +0 -20
- data/src/win32/font.h +0 -24
@@ -0,0 +1,119 @@
|
|
1
|
+
#include "rays/camera.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include "rays/exception.h"
|
5
|
+
|
6
|
+
|
7
|
+
namespace Rays
|
8
|
+
{
|
9
|
+
|
10
|
+
|
11
|
+
struct Camera::Data
|
12
|
+
{
|
13
|
+
};// Camera::Data
|
14
|
+
|
15
|
+
|
16
|
+
std::vector<String>
|
17
|
+
get_camera_device_names ()
|
18
|
+
{
|
19
|
+
not_implemented_error(__FILE__, __LINE__);
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
Camera::Camera (
|
24
|
+
const char* device_name,
|
25
|
+
int min_width, int min_height, bool resize, bool crop)
|
26
|
+
{
|
27
|
+
not_implemented_error(__FILE__, __LINE__);
|
28
|
+
}
|
29
|
+
|
30
|
+
Camera::~Camera ()
|
31
|
+
{
|
32
|
+
not_implemented_error(__FILE__, __LINE__);
|
33
|
+
}
|
34
|
+
|
35
|
+
bool
|
36
|
+
Camera::start ()
|
37
|
+
{
|
38
|
+
not_implemented_error(__FILE__, __LINE__);
|
39
|
+
}
|
40
|
+
|
41
|
+
void
|
42
|
+
Camera::stop ()
|
43
|
+
{
|
44
|
+
not_implemented_error(__FILE__, __LINE__);
|
45
|
+
}
|
46
|
+
|
47
|
+
bool
|
48
|
+
Camera::is_active () const
|
49
|
+
{
|
50
|
+
not_implemented_error(__FILE__, __LINE__);
|
51
|
+
}
|
52
|
+
|
53
|
+
void
|
54
|
+
Camera::set_min_width (int width)
|
55
|
+
{
|
56
|
+
not_implemented_error(__FILE__, __LINE__);
|
57
|
+
}
|
58
|
+
|
59
|
+
int
|
60
|
+
Camera::min_width () const
|
61
|
+
{
|
62
|
+
not_implemented_error(__FILE__, __LINE__);
|
63
|
+
}
|
64
|
+
|
65
|
+
void
|
66
|
+
Camera::set_min_height (int height)
|
67
|
+
{
|
68
|
+
not_implemented_error(__FILE__, __LINE__);
|
69
|
+
}
|
70
|
+
|
71
|
+
int
|
72
|
+
Camera::min_height () const
|
73
|
+
{
|
74
|
+
not_implemented_error(__FILE__, __LINE__);
|
75
|
+
}
|
76
|
+
|
77
|
+
void
|
78
|
+
Camera::set_resize (bool resize)
|
79
|
+
{
|
80
|
+
not_implemented_error(__FILE__, __LINE__);
|
81
|
+
}
|
82
|
+
|
83
|
+
bool
|
84
|
+
Camera::is_resize () const
|
85
|
+
{
|
86
|
+
not_implemented_error(__FILE__, __LINE__);
|
87
|
+
}
|
88
|
+
|
89
|
+
void
|
90
|
+
Camera::set_crop (bool crop)
|
91
|
+
{
|
92
|
+
not_implemented_error(__FILE__, __LINE__);
|
93
|
+
}
|
94
|
+
|
95
|
+
bool
|
96
|
+
Camera::is_crop () const
|
97
|
+
{
|
98
|
+
not_implemented_error(__FILE__, __LINE__);
|
99
|
+
}
|
100
|
+
|
101
|
+
const Image*
|
102
|
+
Camera::image () const
|
103
|
+
{
|
104
|
+
not_implemented_error(__FILE__, __LINE__);
|
105
|
+
}
|
106
|
+
|
107
|
+
Camera::operator bool () const
|
108
|
+
{
|
109
|
+
return false;
|
110
|
+
}
|
111
|
+
|
112
|
+
bool
|
113
|
+
Camera::operator ! () const
|
114
|
+
{
|
115
|
+
return !operator bool();
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
}// Rays
|
data/src/win32/font.cpp
CHANGED
@@ -1,97 +1,236 @@
|
|
1
|
-
#include "font.h"
|
1
|
+
#include "../font.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <assert.h>
|
5
|
+
#include <set>
|
6
|
+
#include "rays/exception.h"
|
7
|
+
#include "gdi.h"
|
2
8
|
|
3
9
|
|
4
10
|
namespace Rays
|
5
11
|
{
|
6
12
|
|
7
13
|
|
8
|
-
struct
|
14
|
+
struct RawFont::Data
|
9
15
|
{
|
10
16
|
|
11
17
|
Win32::Font font;
|
12
18
|
|
13
|
-
|
19
|
+
String path;
|
20
|
+
|
21
|
+
};// RawFont::Data
|
14
22
|
|
15
23
|
|
16
|
-
|
24
|
+
typedef std::set<String> StringSet;
|
25
|
+
|
26
|
+
struct EnumFontFamiliesCallbackParams
|
17
27
|
{
|
18
|
-
}
|
19
28
|
|
20
|
-
|
29
|
+
StringSet* names;
|
30
|
+
|
31
|
+
bool fullname;
|
32
|
+
|
33
|
+
EnumFontFamiliesCallbackParams (StringSet* names, bool fullname)
|
34
|
+
: names(names), fullname(fullname)
|
35
|
+
{
|
36
|
+
}
|
37
|
+
|
38
|
+
};// EnumFontFamiliesCallbackParams
|
39
|
+
|
40
|
+
|
41
|
+
static int CALLBACK
|
42
|
+
enum_callback (
|
43
|
+
const ENUMLOGFONT* elf, const NEWTEXTMETRIC* ntm, DWORD font_type, LPARAM lp)
|
21
44
|
{
|
22
|
-
|
45
|
+
const auto* params = (EnumFontFamiliesCallbackParams*) lp;
|
46
|
+
const char* name = params->fullname
|
47
|
+
? (const char*) elf->elfFullName
|
48
|
+
: (const char*) elf->elfLogFont.lfFaceName;
|
49
|
+
|
50
|
+
if (name && *name != '\0' && *name != '@')
|
51
|
+
params->names->insert(name);
|
52
|
+
|
53
|
+
return TRUE;
|
23
54
|
}
|
24
55
|
|
25
|
-
|
56
|
+
static void
|
57
|
+
get_font_names (
|
58
|
+
StringSet* names, HDC hdc, const char* query = NULL, bool fullname = false)
|
26
59
|
{
|
60
|
+
assert(!query || strlen(query) < LF_FACESIZE);
|
61
|
+
|
62
|
+
LOGFONT lf = {0};
|
63
|
+
lf.lfCharSet = DEFAULT_CHARSET;
|
64
|
+
|
65
|
+
if (query) strcpy(lf.lfFaceName, query);
|
66
|
+
|
67
|
+
EnumFontFamiliesCallbackParams params(names, fullname);
|
68
|
+
EnumFontFamiliesEx(
|
69
|
+
hdc, &lf, (FONTENUMPROC) &enum_callback, (LPARAM) ¶ms, 0);
|
27
70
|
}
|
28
71
|
|
29
|
-
|
30
|
-
|
72
|
+
const FontFamilyMap&
|
73
|
+
get_font_families ()
|
31
74
|
{
|
32
|
-
|
75
|
+
static const FontFamilyMap MAP = []() {
|
76
|
+
Win32::DC dc(GetDC(NULL), true, Win32::DC::RELEASE_DC);
|
77
|
+
|
78
|
+
StringSet families;
|
79
|
+
get_font_names(&families, dc.handle());
|
80
|
+
|
81
|
+
StringSet faces;
|
82
|
+
FontFamilyMap map;
|
83
|
+
for (const auto& family : families)
|
84
|
+
{
|
85
|
+
faces.clear();
|
86
|
+
get_font_names(&faces, dc.handle(), family, true);
|
87
|
+
|
88
|
+
auto& list = map[family];
|
89
|
+
list.insert(list.end(), faces.begin(), faces.end());
|
90
|
+
}
|
91
|
+
|
92
|
+
return map;
|
93
|
+
}();
|
94
|
+
return MAP;
|
33
95
|
}
|
34
96
|
|
35
|
-
|
36
|
-
|
97
|
+
RawFont
|
98
|
+
RawFont_load (const char* path, coord size)
|
37
99
|
{
|
38
|
-
|
100
|
+
not_implemented_error(__FILE__, __LINE__);
|
39
101
|
}
|
40
102
|
|
41
|
-
|
42
|
-
|
103
|
+
|
104
|
+
RawFont::RawFont ()
|
43
105
|
{
|
44
|
-
return self->font.get_extent(width, height, str);
|
45
106
|
}
|
46
107
|
|
47
|
-
|
108
|
+
RawFont::RawFont (const char* name, coord size)
|
48
109
|
{
|
49
|
-
|
110
|
+
self->font = Win32::Font(name, size);
|
50
111
|
}
|
51
112
|
|
52
|
-
|
53
|
-
Font::operator ! () const
|
113
|
+
RawFont::RawFont (const This& obj, coord size)
|
54
114
|
{
|
55
|
-
|
115
|
+
const char* path = obj.self->path.empty() ? NULL : obj.self->path.c_str();
|
116
|
+
if (path)
|
117
|
+
*this = RawFont_load(path, size);
|
118
|
+
else
|
119
|
+
self->font = Win32::Font(obj.name().c_str(), size);
|
56
120
|
}
|
57
121
|
|
58
|
-
|
59
|
-
const Font&
|
60
|
-
get_default_font ()
|
122
|
+
RawFont::~RawFont ()
|
61
123
|
{
|
62
|
-
static const Font FONT(NULL);
|
63
|
-
return FONT;
|
64
124
|
}
|
65
125
|
|
66
|
-
|
67
126
|
void
|
68
|
-
|
69
|
-
|
70
|
-
const char* str, coord x, coord y)
|
127
|
+
RawFont::draw_string (
|
128
|
+
void* context, coord context_height,
|
129
|
+
const char* str, coord x, coord y) const
|
71
130
|
{
|
72
131
|
using namespace Win32;
|
73
132
|
|
74
|
-
|
133
|
+
HDC hdc = (HDC) context;
|
134
|
+
|
135
|
+
if (!hdc || !str)
|
75
136
|
argument_error(__FILE__, __LINE__);
|
76
137
|
|
77
138
|
if (*str == '\0') return;
|
78
139
|
|
140
|
+
if (!*this)
|
141
|
+
invalid_state_error(__FILE__, __LINE__);
|
142
|
+
|
79
143
|
coord width = 0, height = 0;
|
80
|
-
if (!font.get_extent(&width, &height, str))
|
81
|
-
rays_error(__FILE__, __LINE__, "
|
144
|
+
if (!self->font.get_extent(&width, &height, str))
|
145
|
+
rays_error(__FILE__, __LINE__, "failed to get font extent.");
|
146
|
+
|
147
|
+
DC dc = hdc;
|
148
|
+
Win32::Font font = dc.font();
|
149
|
+
COLORREF text_color = dc.text_color();
|
150
|
+
COLORREF back_color = dc.back_color();
|
82
151
|
|
83
|
-
|
84
|
-
|
85
|
-
|
152
|
+
dc.set_font(self->font.handle());
|
153
|
+
dc.set_text_color(RGB(255, 255, 255));
|
154
|
+
dc.set_back_color(RGB(0, 0, 0));
|
86
155
|
|
87
|
-
Win32::Font old = dc.font();
|
88
|
-
dc.set_font(font.self->font.handle());
|
89
156
|
BOOL ret = TextOutA(dc.handle(), x, y, str, strlen(str));
|
90
|
-
|
157
|
+
|
158
|
+
dc.set_font(font);
|
159
|
+
dc.set_text_color(text_color);
|
160
|
+
dc.set_back_color(back_color);
|
91
161
|
|
92
162
|
if (ret == FALSE)
|
93
163
|
rays_error(__FILE__, __LINE__, "drawing text failed.");
|
94
164
|
}
|
95
165
|
|
166
|
+
String
|
167
|
+
RawFont::name () const
|
168
|
+
{
|
169
|
+
if (!*this) return "";
|
170
|
+
return self->font.name();
|
171
|
+
}
|
172
|
+
|
173
|
+
coord
|
174
|
+
RawFont::size () const
|
175
|
+
{
|
176
|
+
if (!*this) return 0;
|
177
|
+
return self->font.size();
|
178
|
+
}
|
179
|
+
|
180
|
+
coord
|
181
|
+
RawFont::get_width (const char* str) const
|
182
|
+
{
|
183
|
+
if (!str)
|
184
|
+
argument_error(__FILE__, __LINE__);
|
185
|
+
|
186
|
+
if (!*this)
|
187
|
+
invalid_state_error(__FILE__, __LINE__);
|
188
|
+
|
189
|
+
if (*str == '\0') return 0;
|
190
|
+
|
191
|
+
coord width;
|
192
|
+
if (!self->font.get_extent(&width, NULL, str))
|
193
|
+
rays_error(__FILE__, __LINE__, "failed to get font width");
|
194
|
+
|
195
|
+
return width;
|
196
|
+
}
|
197
|
+
|
198
|
+
coord
|
199
|
+
RawFont::get_height (coord* ascent, coord* descent, coord* leading) const
|
200
|
+
{
|
201
|
+
if (!*this)
|
202
|
+
invalid_state_error(__FILE__, __LINE__);
|
203
|
+
|
204
|
+
if (ascent || descent || leading)
|
205
|
+
{
|
206
|
+
Win32::DC dc(GetDC(NULL), true, Win32::DC::RELEASE_DC);
|
207
|
+
dc.set_font(self->font);
|
208
|
+
|
209
|
+
TEXTMETRIC tm;
|
210
|
+
GetTextMetrics(dc.handle(), &tm);
|
211
|
+
|
212
|
+
if (ascent) *ascent = tm.tmAscent;
|
213
|
+
if (descent) *descent = tm.tmDescent;
|
214
|
+
if (leading) *leading = tm.tmExternalLeading;
|
215
|
+
}
|
216
|
+
|
217
|
+
coord height;
|
218
|
+
if (!self->font.get_extent(NULL, &height, "X"))
|
219
|
+
rays_error(__FILE__, __LINE__, "failed to get font height");
|
220
|
+
|
221
|
+
return height;
|
222
|
+
}
|
223
|
+
|
224
|
+
RawFont::operator bool () const
|
225
|
+
{
|
226
|
+
return self->font;
|
227
|
+
}
|
228
|
+
|
229
|
+
bool
|
230
|
+
RawFont::operator ! () const
|
231
|
+
{
|
232
|
+
return !operator bool();
|
233
|
+
}
|
234
|
+
|
96
235
|
|
97
236
|
}// Rays
|
data/src/win32/gdi.cpp
CHANGED
@@ -43,10 +43,8 @@ namespace Rays
|
|
43
43
|
|
44
44
|
typedef HANDLE Handle;
|
45
45
|
|
46
|
-
HandleObject (
|
47
|
-
|
48
|
-
DeleteHandleFunc delfun = delete_object)
|
49
|
-
: handle_(handle), delfun_(delfun)
|
46
|
+
HandleObject ()
|
47
|
+
: handle_(NULL), delfun_(NULL)
|
50
48
|
{
|
51
49
|
}
|
52
50
|
|
data/src/win32/gdi.h
CHANGED
@@ -0,0 +1,127 @@
|
|
1
|
+
#include "../opengl.h"
|
2
|
+
|
3
|
+
|
4
|
+
#include <xot/windows.h>
|
5
|
+
#include "rays/rays.h"
|
6
|
+
#include "rays/exception.h"
|
7
|
+
|
8
|
+
|
9
|
+
namespace Rays
|
10
|
+
{
|
11
|
+
|
12
|
+
|
13
|
+
static const char* WINDOW_CLASS = "Rays:OffscreenWindow";
|
14
|
+
|
15
|
+
|
16
|
+
struct OffscreenContext
|
17
|
+
{
|
18
|
+
|
19
|
+
HWND hwnd = NULL;
|
20
|
+
|
21
|
+
HDC hdc = NULL;
|
22
|
+
|
23
|
+
HGLRC hrc = NULL;
|
24
|
+
|
25
|
+
OffscreenContext ()
|
26
|
+
{
|
27
|
+
static const PIXELFORMATDESCRIPTOR PFD =
|
28
|
+
{
|
29
|
+
sizeof(PIXELFORMATDESCRIPTOR), 1,
|
30
|
+
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
|
31
|
+
PFD_TYPE_RGBA, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0,
|
32
|
+
PFD_MAIN_PLANE, 0, 0, 0, 0
|
33
|
+
};
|
34
|
+
|
35
|
+
WNDCLASS wc = {0};
|
36
|
+
wc.lpfnWndProc = DefWindowProc;
|
37
|
+
wc.hInstance = GetModuleHandle(NULL);
|
38
|
+
wc.lpszClassName = WINDOW_CLASS;
|
39
|
+
wc.style = CS_OWNDC;
|
40
|
+
if (!RegisterClass(&wc))
|
41
|
+
{
|
42
|
+
// It's OK to be registered by the duplicated Rays module
|
43
|
+
if (GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
|
44
|
+
system_error(__FILE__, __LINE__);
|
45
|
+
}
|
46
|
+
|
47
|
+
hwnd = CreateWindowEx(
|
48
|
+
WS_EX_LAYERED, WINDOW_CLASS, "", WS_POPUP, 0, 0, 1, 1,
|
49
|
+
NULL, NULL, GetModuleHandle(NULL), NULL);
|
50
|
+
if (!hwnd)
|
51
|
+
system_error(__FILE__, __LINE__);
|
52
|
+
|
53
|
+
hdc = GetDC(hwnd);
|
54
|
+
int pf = ChoosePixelFormat(hdc, &PFD);
|
55
|
+
if (!SetPixelFormat(hdc, pf, &PFD))
|
56
|
+
system_error(__FILE__, __LINE__);
|
57
|
+
|
58
|
+
hrc = wglCreateContext(hdc);
|
59
|
+
if (!hrc)
|
60
|
+
system_error(__FILE__, __LINE__);
|
61
|
+
}
|
62
|
+
|
63
|
+
~OffscreenContext ()
|
64
|
+
{
|
65
|
+
|
66
|
+
if (hrc && hrc == wglGetCurrentContext())
|
67
|
+
{
|
68
|
+
if (!wglMakeCurrent(NULL, NULL))
|
69
|
+
system_error(__FILE__, __LINE__);
|
70
|
+
}
|
71
|
+
|
72
|
+
if (!wglDeleteContext(hrc))
|
73
|
+
system_error(__FILE__, __LINE__);
|
74
|
+
|
75
|
+
if (!ReleaseDC(hwnd, hdc))
|
76
|
+
system_error(__FILE__, __LINE__);
|
77
|
+
|
78
|
+
if (!DestroyWindow(hwnd))
|
79
|
+
system_error(__FILE__, __LINE__);
|
80
|
+
}
|
81
|
+
|
82
|
+
};// OffscreenContext
|
83
|
+
|
84
|
+
|
85
|
+
static OffscreenContext*
|
86
|
+
get_opengl_offscreen_context ()
|
87
|
+
{
|
88
|
+
static OffscreenContext* context = NULL;
|
89
|
+
if (!context) context = new OffscreenContext();
|
90
|
+
return context;
|
91
|
+
}
|
92
|
+
|
93
|
+
void
|
94
|
+
OpenGL_init ()
|
95
|
+
{
|
96
|
+
activate_offscreen_context();
|
97
|
+
|
98
|
+
static bool glew_initialized = false;
|
99
|
+
if (!glew_initialized)
|
100
|
+
{
|
101
|
+
glew_initialized = true;
|
102
|
+
if (glewInit() != GLEW_OK)
|
103
|
+
opengl_error(__FILE__, __LINE__, "failed to initialize GLEW.");
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
void
|
108
|
+
OpenGL_fin ()
|
109
|
+
{
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
Context
|
114
|
+
get_offscreen_context ()
|
115
|
+
{
|
116
|
+
return get_opengl_offscreen_context();
|
117
|
+
}
|
118
|
+
|
119
|
+
void
|
120
|
+
activate_offscreen_context ()
|
121
|
+
{
|
122
|
+
const auto* c = get_opengl_offscreen_context();
|
123
|
+
wglMakeCurrent(c->hdc, c->hrc);
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
}// Rays
|
data/src/win32/rays.cpp
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
// -*- objc -*-
|
2
1
|
#include "rays/rays.h"
|
3
2
|
|
4
3
|
|
4
|
+
#include "rays/exception.h"
|
5
|
+
#include "../opengl.h"
|
6
|
+
|
7
|
+
|
5
8
|
namespace Rays
|
6
9
|
{
|
7
10
|
|
@@ -9,27 +12,31 @@ namespace Rays
|
|
9
12
|
namespace global
|
10
13
|
{
|
11
14
|
|
12
|
-
|
13
15
|
static bool initialized = false;
|
14
16
|
|
15
|
-
|
16
17
|
}// global
|
17
18
|
|
18
19
|
|
19
|
-
|
20
|
+
void
|
20
21
|
init ()
|
21
22
|
{
|
22
|
-
if (global::initialized)
|
23
|
+
if (global::initialized)
|
24
|
+
rays_error(__FILE__, __LINE__, "already initialized.");
|
25
|
+
|
23
26
|
global::initialized = true;
|
24
|
-
|
27
|
+
|
28
|
+
OpenGL_init();
|
25
29
|
}
|
26
30
|
|
27
|
-
|
31
|
+
void
|
28
32
|
fin ()
|
29
33
|
{
|
30
|
-
if (!global::initialized)
|
34
|
+
if (!global::initialized)
|
35
|
+
rays_error(__FILE__, __LINE__, "not initialized.");
|
36
|
+
|
37
|
+
OpenGL_fin();
|
38
|
+
|
31
39
|
global::initialized = false;
|
32
|
-
return true;
|
33
40
|
}
|
34
41
|
|
35
42
|
|
data/test/helper.rb
CHANGED
@@ -3,16 +3,13 @@
|
|
3
3
|
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
4
4
|
|
5
5
|
require 'xot/test'
|
6
|
+
require 'xot/util'
|
6
7
|
require 'rays'
|
7
8
|
|
8
9
|
require 'test/unit'
|
9
10
|
|
10
11
|
include Xot::Test
|
11
|
-
|
12
|
-
|
13
|
-
unless defined?($RAYS_NOAUTOINIT) && $RAYS_NOAUTOINIT
|
14
|
-
def Rays.fin!() end
|
15
|
-
end
|
12
|
+
include Xot::Util
|
16
13
|
|
17
14
|
|
18
15
|
def assert_equal_color(c1, c2, delta = 0.000001)
|
data/test/test_bitmap.rb
CHANGED
@@ -37,13 +37,15 @@ class TestBitmap < Test::Unit::TestCase
|
|
37
37
|
|
38
38
|
bmp.pixels = [0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00]
|
39
39
|
assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00], bmp.pixels
|
40
|
+
end
|
40
41
|
|
42
|
+
def test_pixels_float()
|
41
43
|
bmp = bitmap 2, 2, Rays::RGBA_float
|
42
44
|
assert_equal [0,0,0,0] * 4, bmp.pixels
|
43
45
|
|
44
46
|
bmp.pixels = [1,0,0,1, 0,1,0,1, 0,0,1,1, 1,1,0,1]
|
45
47
|
assert_equal [1,0,0,1, 0,1,0,1, 0,0,1,1, 1,1,0,1], bmp.pixels
|
46
|
-
end
|
48
|
+
end unless win32?
|
47
49
|
|
48
50
|
def test_at()
|
49
51
|
o = bitmap
|
data/test/test_image.rb
CHANGED
@@ -99,33 +99,27 @@ class TestImage < Test::Unit::TestCase
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_save_load()
|
102
|
-
|
102
|
+
get_image_type = -> filename {
|
103
103
|
`file #{filename}`.match(/#{filename}: ([^,]+),/)[1]
|
104
|
-
|
104
|
+
}
|
105
105
|
|
106
106
|
img = image(10, 10).paint {fill 1, 0, 0; ellipse 0, 0, 10}
|
107
107
|
pixels = img.bitmap.to_a
|
108
|
-
paths = %w[png jpg jpeg
|
108
|
+
paths = %w[png jpg jpeg bmp].map {|ext| "#{__dir__}/testimage.#{ext}"}
|
109
109
|
|
110
|
-
png, jpg, jpeg,
|
110
|
+
png, jpg, jpeg, bmp = paths
|
111
111
|
|
112
112
|
paths.each {|path| img.save path}
|
113
113
|
|
114
|
-
assert_equal 'PNG image data', get_image_type
|
115
|
-
assert_equal 'JPEG image data', get_image_type
|
116
|
-
assert_equal 'JPEG image data', get_image_type
|
117
|
-
assert_equal '
|
118
|
-
assert_equal 'PC bitmap', get_image_type(bmp)
|
119
|
-
assert_equal 'TIFF image data', get_image_type(tif)
|
120
|
-
assert_equal 'TIFF image data', get_image_type(tiff)
|
114
|
+
assert_equal 'PNG image data', get_image_type[png]
|
115
|
+
assert_equal 'JPEG image data', get_image_type[jpg]
|
116
|
+
assert_equal 'JPEG image data', get_image_type[jpeg]
|
117
|
+
assert_equal 'PC bitmap', get_image_type[bmp]
|
121
118
|
|
122
119
|
assert_equal pixels, load(png) .then {|o| o.bitmap.to_a}
|
123
120
|
assert_equal [10, 10], load(jpg) .then {|o| [o.width, o.height]}
|
124
121
|
assert_equal [10, 10], load(jpeg).then {|o| [o.width, o.height]}
|
125
|
-
assert_equal pixels, load(gif) .then {|o| o.bitmap.to_a}
|
126
122
|
assert_equal [10, 10], load(bmp) .then {|o| [o.width, o.height]}
|
127
|
-
assert_equal pixels, load(tif) .then {|o| o.bitmap.to_a}
|
128
|
-
assert_equal pixels, load(tiff).then {|o| o.bitmap.to_a}
|
129
123
|
|
130
124
|
paths.each {|path| File.delete path}
|
131
125
|
|
data/test/test_painter.rb
CHANGED
@@ -175,7 +175,7 @@ class TestPainter < Test::Unit::TestCase
|
|
175
175
|
pa.line_height = nil
|
176
176
|
assert_equal [h, -1], [pa.line_height, pa.line_height!]
|
177
177
|
|
178
|
-
pa.font "
|
178
|
+
pa.font "Arial", 100
|
179
179
|
assert_equal pa.font.height, pa.line_height
|
180
180
|
end
|
181
181
|
|
@@ -223,11 +223,11 @@ class TestPainter < Test::Unit::TestCase
|
|
223
223
|
|
224
224
|
def test_font_name_size()
|
225
225
|
pa = painter
|
226
|
-
pa.font "
|
227
|
-
assert_equal "
|
226
|
+
pa.font "Arial", 10
|
227
|
+
assert_equal "Arial", pa.font.name
|
228
228
|
assert_equal 10, pa.font.size
|
229
229
|
pa.font nil
|
230
|
-
assert_not_equal "
|
230
|
+
assert_not_equal "Arial", pa.font.name
|
231
231
|
pa.font nil, 20
|
232
232
|
assert_equal 20, pa.font.size
|
233
233
|
end
|