-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.cpp
More file actions
794 lines (663 loc) · 18.3 KB
/
bridge.cpp
File metadata and controls
794 lines (663 loc) · 18.3 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
// bridge (.Cpp)
// -----------------
// Bridge code (used to add some handy RGBA code as well as wrap around some PTK functions)
#include <vector>
#include <list>
#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include "string.h"
#include "math.h"
#include <filesystem>
#include <string>
#include <algorithm>
#include <unordered_map>
#include "raylib.h"
using namespace std;
#include "bridge.hpp"
#include "scene.hpp"
#include "game.hpp"
#include "log.hpp"
// Necessary objects.
extern void _sleep(int milliseconds);
// Rgba class:
//Rgba Rgba::BLACK = Rgba( 0.0, 0.0, 0.0, 1.0 );
//Rgba Rgba::WHITE = Rgba( 1.0, 1.0, 1.0, 1.0 );
//Rgba Rgba::RED = Rgba( 1.0, 0.0, 0.0, 1.0 );
//Rgba Rgba::YELLOW = Rgba( 1.0, 1.0, 0.0, 1.0 );
//Rgba Rgba::GREEN = Rgba( 0.0, 1.0, 0.0, 1.0 );
//Rgba Rgba::BLUE = Rgba( 0.0, 0.0, 1.0, 1.0 );
Rgba Rgba::INVISIBLE = Rgba( 0.0, 0.0, 0.0, 0.0 );
Rgba Rgba::
MixWith( const Rgba &other, float factor ) const {
float red = r + (other.r - r) * factor;
float green = g + (other.g - g) * factor;
float blue = b + (other.b - b) * factor;
float alpha = a + (other.a - a) * factor;
return Rgba( red, green, blue, alpha );
}
int Rgba::
SpecialPacked() const {
return (Rgba::CompToI(a) << 24) | (Rgba::CompToI(r) << 16) | (Rgba::CompToI(g) << 8) | Rgba::CompToI(b);
}
Rgba::
Rgba( int col, bool notUsed )
: r( CompToF(( col >> 16 ) & 0xff)), g( CompToF(( col >> 8 ) & 0xff)),
b( CompToF( col & 0xff)), a( CompToF(( col >> 24 ) & 0xff)) {
notUsed = true;
}
Rgba::
Rgba( bool invalidiate )
: r( -1.0 ), g( -1.0 ), b( -1.0 ), a( -1.0 ) {
invalidiate = true;
}
bool Rgba::
IsValid() {
return r >= 0.0 && g >= 0.0 && b >= 0.0 && a >= 0.0;
}
int Rgba::
Packed() const {
return NULL;
}
struct rand_info rand_info;
// RandomNum code:
void Seed(unsigned int newSeed)
{
rand_info.seed = newSeed;
}
unsigned int SeedFromTime(void)
{
rand_info.seed = time(0);
return rand_info.seed;
}
unsigned long Rand()
{
rand_info.seed = (201 * rand_info.seed + 11) % 4294967295;
return (ABS(rand_info.seed) % 65535);
}
// Returns a Floating point random number between min and max.
float FRand( float min, float max )
{
return min + float(Rand())/float(65535) * (max-min);
}
int IRand(int min, int max)
{
if (min > max) return max + (Rand() % (min + 1 - max));
return min + (Rand() % (max + 1 - min));
}
namespace fs = std::filesystem;
vector < Texture2D *> LoadListOfBitmaps( string filenameBegin, string extension, unsigned int numNumbers)
{
vector< Texture2D *> bitmapList;
for( int index = 1;; index++ )
{
stringstream stream;
stream << index;
string numbers = stream.str();
while( numbers.size() < numNumbers )
{
numbers = string("0") + numbers;
}
fs::path path = filenameBegin;
path /= (numbers + string(".") + extension);
string filename = path.generic_string();
Texture2D *frame = new Texture2D();
Image img = LoadImage(GetFullPath(filename.c_str()));
if (img.format != PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
{
ImageFormat(&img, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
}
Texture2D tex = LoadTextureFromImage(img);
memcpy(frame, &tex, sizeof(Texture2D));
UnloadImage(img);
if( !IsTextureValid(*frame))
{
UnloadTexture(*frame);
delete frame;
break;
}
//TODO:
//frame->setTextureQuality( true );
bitmapList.push_back( frame );
}
return bitmapList;
}
int LoadAndAddBitmaps(vector< Texture2D *> *bitmapList, string filenameBegin, string extension)
{
int num = 0;
for( int index = 0;; index++ )
{
stringstream stream;
stream << index;
string numbers = stream.str();
fs::path path = filenameBegin;
path /= (numbers + string(".") + extension);
string filename = path.generic_string();
Texture2D* frame = new Texture2D();
Texture2D temp = LoadTexture(GetFullPath(filename.c_str()));
memcpy(frame, &temp, sizeof(Texture2D));
if (!IsTextureValid(*frame))
{
UnloadTexture(*frame);
delete frame;
break;
}
//TODO:
//frame->setTextureQuality( true );
//frame->setAlphaMode( 0 );
bitmapList->push_back(frame );
num++;
}
return num;
}
bool CheckQuit(void)
{
return WindowShouldClose();
}
bool CheckWindowFocus(void)
{
return IsWindowFocused();
}
//void RestoreWindow(void)
//{
// RestoreWindow();
//}
void Rest(int time)
{
#if !defined __APPLE__
_sleep(time);
#endif
}
bool CreateGameScreen(int width, int height, const char* ico, bool window, bool dx)
{
Image icon = LoadImage(GetFullPath(ico));
SetWindowIcon(icon);
UnloadImage(icon);
// Open DirectX or OpenGL gfx context.
//if (dx == false) gwin = KPTK::createKWindow( K_OPENGL );
//if ( dx == true) gwin = KPTK::createKWindow( K_DIRECTX );
RendererTexture = LoadRenderTexture(1280, 960);
//Fix texture bleeding
SetTextureWrap(RendererTexture.texture, TEXTURE_WRAP_CLAMP);
SetTextureFilter(RendererTexture.texture, TEXTURE_FILTER_BILINEAR);
// Now try to open screen with requested details.
SetWindowSize(width, height);
SetWindowTitle("Chaos Groove");
if (!IsWindowReady()) return false;
if (!window && !IsWindowFullscreen())
{
ToggleFullscreen();
}
int x = (GetMonitorWidth(GetCurrentMonitor()) - width) / 2;
int y = (GetMonitorHeight(GetCurrentMonitor()) - height) / 2;
SetWindowPosition(x,y);
// Clear newly created screen.
BeginDrawing();
ClearScreen();
DrawText("INITIALIZING...", 20, height/1.1, 40, RAYWHITE);
EndDrawing();
ClearWindowState(FLAG_WINDOW_HIDDEN);
game.opengl = 1 - dx;
//webGL setup?
//SetTargetFPS(140);
return true;
}
void ListScreenModes(void)
{
for (int i; i < GetMonitorCount(); i++) {
ListDisplays(i);
}
}
bool ListDisplays(int display)
{
log( "%d %d - %d hz" , GetMonitorWidth(display), GetMonitorHeight(display), GetMonitorRefreshRate(display));
return true ;
}
int get_desktop_resolution(int *width, int *height)
{
/* same thing for the desktop resolution:
*
* DEVMODE display_mode;
*
* display_mode.dmSize = sizeof(DEVMODE);
* display_mode.dmDriverExtra = 0;
* if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &display_mode) == 0)
* return -1;
*
* *width = display_mode.dmPelsWidth;
* *height = display_mode.dmPelsHeight;
*
* return 0;
*/
//#if !defined __APPLE__
// HDC dc;
// dc = GetDC(NULL);
// *width = GetDeviceCaps(dc, HORZRES);
// *height = GetDeviceCaps(dc, VERTRES);
// ReleaseDC(NULL, dc);
// return 0;
//#endif
*width = GetMonitorWidth(GetCurrentMonitor());
*height = GetMonitorHeight(GetCurrentMonitor());
return 0;
}
int ScreenWidth(void)
{
return GetScreenWidth();
}
int ScreenHeight(void)
{
return GetScreenHeight();
}
void ClearScreen(void)
{
// Clear newly created screen.
ClearBackground(BLACK);
}
void MessageBox(char *title, char *maintext)
{
// Display messagebox with error details.
DrawText(title, ScreenWidth() / 2, ScreenHeight() / 2, 10, RED);
DrawText(maintext, ScreenWidth() / 2, ScreenHeight() / 2+10, 10, RED);
// Record error in logfile too.
log("");
log("Messagebox error :");
log(title);
log("--");
log(maintext);
log("");
}
//void UpdateScreen(void)
//{
// // Flip screen buffer.
// gwin->flipBackBuffer( false ) ;
// gwin->processEvents( ) ;
//}
bool Key(int key)
{
return IsKeyPressed(key);
}
bool LeftMouseButton(void)
{
return IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
}
bool RightMouseButton(void)
{
return IsMouseButtonPressed(MOUSE_BUTTON_RIGHT);
}
void GetMouseMickeys(float *x, float *y, bool lock)
{
float fx, fy;
#if defined(__EMSCRIPTEN__)
if (GetTouchPointCount() > 0)
{
Vector2 pos = GetTouchPosition(0);
float scale = fminf((float)ScreenWidth() / RendererTexture.texture.width,
(float)ScreenHeight() / RendererTexture.texture.height);
float w = (int)(RendererTexture.texture.width * scale);
float h = (int)(RendererTexture.texture.height * scale);
fx = (ScreenWidth() - w) / 2;
fy = (ScreenHeight() - h) / 2;
*x = (pos.x - fx) / scale;
*y = (pos.y - fy) / scale;
return;
}
Vector2 delta = GetMouseDelta();
fx = delta.x;
fy = delta.y;
AccelerateMouseMickeys(&fx, &fy, 20, 40);
*x += fx;
*y += fy;
#else
if (lock)
{
fx = (GetMouseX() - (ScreenWidth() / 2)) * 4;
fy = (GetMouseY() - (ScreenHeight() / 2)) * 4;
if (IsWindowFocused()) SetMousePosition(ScreenWidth() / 2, ScreenHeight() / 2);
AccelerateMouseMickeys(&fx, &fy, 20, 40);
*x += fx;
*y += fy;
}
else
{
float scale = fminf((float)ScreenWidth() / RendererTexture.texture.width,
(float)ScreenHeight() / RendererTexture.texture.height);
float w = (int)(RendererTexture.texture.width * scale);
float h = (int)(RendererTexture.texture.height * scale);
fx = (ScreenWidth() - w) / 2;
fy = (ScreenHeight() - h) / 2;
*x = (GetMouseX() - fx) / scale;
*y = (GetMouseY() - fy) / scale;
}
#endif
}
void AccelerateMouseMickeys(float *x, float *y, float scale, float scale_accel)
{
float dist;
scale = scale * 0.015;
scale_accel = (scale_accel * 0.01) + 1.0;
dist = *x * *x + *y * *y;
// Acceleration Threshold 1
if (dist > 7*7)
{
*x *= (scale_accel * 0.8); // Scale movements.
*y *= (scale_accel * 0.8);
}
// Acceleration Threshold 2
if (dist > 16*16)
{
*x *= scale_accel; // Scale movements.
*y *= scale_accel;
}
// Scale overall speed (while stopping scale being so low that movement is stopped).
if (*x > 0) *x = MAX(0.1, *x * scale);
if (*x < 0) *x = MIN(-0.1, *x * scale);
if (*y > 0) *y = MAX(0.1, *y * scale);
if (*y < 0) *y = MIN(-0.1, *y * scale);
}
long FileSize(char *FileName)
{
struct stat file;
if(!stat(FileName,&file))
{
return file.st_size;
}
return 0;
}
const char* path_to_portable(const char* input) {
static char buffer[1024];
size_t i = 0;
if (!input) return NULL;
for (; input[i] && i < sizeof(buffer) - 1; i++) {
buffer[i] = (input[i] == '\\') ? '/' : input[i];
}
buffer[i] = '\0';
return buffer; // const char*
}
// lowercase helper
static std::string lower(const std::string& s) {
std::string out = s;
std::transform(out.begin(), out.end(), out.begin(),
[](unsigned char c) { return std::tolower(c); });
return out;
}
// Fixes a whole path case-insensitively.
// Example: FixPathInsensitive("assets/Textures/PLAYER.PNG");
std::string FixPathInsensitive(const std::string& inputPath)
{
static bool init = true;
static std::unordered_map<std::string, std::string> cache;
if(init)
{
init = false;
fs::path acc = fs::current_path().root_path();
for (const auto& part : fs::current_path().relative_path()) {
acc /= part;
cache[path_to_portable(lower(acc.string()).c_str())] = acc.string();
}
}
//auto it = cache.find(lower(inputPath));
//if (it != cache.end())
// return it->second;
fs::path p = inputPath;
fs::path resolved;
// If path is relative → start at current dir
if (!p.is_absolute())
{
resolved = fs::current_path();
auto p_it = cache.find(path_to_portable(lower((resolved / p).string()).c_str()));
if (p_it != cache.end())
return p_it->second;
}
else
{
resolved = fs::path(p.root_path()); // "/" or "C:\"
auto i_it = cache.find(path_to_portable(lower(inputPath).c_str()));
if (i_it != cache.end())
return i_it->second;
}
// Iterate over each component ("assets", "textures", "player.png")
for (const auto& part : p.relative_path()) {
if (part.empty()) continue; // skip no-op parts
std::string target = lower(part.string());
auto part_it = cache.find(path_to_portable(lower((resolved / part).string()).c_str()));
if (part_it != cache.end()) {
resolved = part_it->second;
continue;
}
bool matched = false;
// List entries inside 'resolved'
if (fs::is_directory(resolved))
{
for (auto& entry : fs::directory_iterator(resolved))
{
std::string entryNameLower = lower(entry.path().filename().string());
if (!entryNameLower.empty())
{
cache[path_to_portable(lower(entry.path().string()).c_str())] = entry.path().string();
}
if (entryNameLower == target) {
resolved /= entry.path().filename();
matched = true;
break;
}
}
}
if (!matched) {
// Not found (path component doesn't exist)
//cache[inputPath] = "";
return "";
}
}
return resolved.generic_string(); // consistent "/" separators
}
const char* GetFullPath(const char* filePath)
{
static char result[MAX_STRING];
const char* new_path = path_to_portable(filePath);
std::string final_path = FixPathInsensitive(new_path);
strncpy(result, final_path.c_str(), MAX_STRING);
return result;
}
void Draw(Texture2D* tex, Rectangle dest)
{
DrawTexturePro(*tex, Rectangle{ 0, 0, (float)tex->width, (float)tex->height }, dest, Vector2{ 0,0 }, 0, WHITE);
}
void Draw(Texture2D* tex, Rectangle dest, float alpha)
{
DrawTexturePro(*tex, Rectangle{ 0, 0, (float)tex->width, (float)tex->height }, dest, Vector2{ 0,0 }, 0, ColorFromNormalized({ 1.0, 1.0, 1.0, alpha }));
}
void Draw(Texture2D* tex, Rectangle dest, Color color)
{
DrawTexturePro(*tex, Rectangle{ 0, 0, (float)tex->width, (float)tex->height }, dest, Vector2{ 0,0 }, 0, color);
}
void Draw(Texture2D* tex, Rectangle source, Rectangle dest)
{
DrawTexturePro(*tex, source, dest, Vector2{ 0,0 }, 0, WHITE);
}
void Draw(Texture2D* tex, Rectangle source, Rectangle dest, float alpha)
{
DrawTexturePro(*tex, source, dest, Vector2{ 0,0 }, 0, ColorFromNormalized({ 1.0, 1.0, 1.0, alpha }));
}
void Draw(Texture2D* tex, Rectangle source, Rectangle dest, Color color)
{
DrawTexturePro(*tex, source, dest, Vector2{ 0,0 }, 0, color);
}
void BlitTransform(Texture2D *bmp, float x, float y, float w, float h, float angle, Rgba rgba)
{
int width, height;
float zoom;
width = bmp->width;
height = bmp->height;
//// Different Width and Height.
//x -= (w / 2);
//y -= (h / 2);
//// need -1 for dx2 and dy2 in directX, but not in OpenGL! PTK bug..
//bmp->stretchAlphaRect( 0, 0, width, height, x, y, (x + w) - (1 - game.opengl), (y + h) - (1 - game.opengl),
//alpha, 360.0 - RAD_TO_DEG( angle ));
DrawTexturePro(*bmp, Rectangle{ 0, 0, (float)width, (float)height }, Rectangle{ x, y, w , h },
Vector2{ w / 2.0f,h / 2.0f },
RAD_TO_DEG(angle),
ColorFromNormalized({ rgba.r, rgba.g, rgba.b, rgba.a }));
return;
/*
if (w == h)
{
if (angle != 0.0 || alpha < 1.0)
{
// Rotated..
// Same Width and Height, so we can use zoom.
x -= (float)width / 2;
y -= (float)height / 2;
zoom = w / (float)width;
bmp->blitAlphaRectFxF( 0, 0, (float)width, (float)height, x, y, 360.0 - RAD_TO_DEG( angle ), zoom, alpha, false, false, 0, 0 );
}
else
{
// full alpha, no rotation, possible stretching.
x -= (float)width / 2;
y -= (float)height / 2;
zoom = w / (float)width;
bmp->blitAlphaRectFxF( 0, 0, (float)width, (float)height, (int)x, (int)y, 0.0, zoom, alpha, false, false, 0, 0 );
}
}
else
{
// Different Width and Height.
x -= (w / 2);
y -= (h / 2);
// need -1 for dx2 and dy2 in directX, but not in OpenGL! PTK bug..
bmp->stretchAlphaRect( 0, 0, width, height, x, y, (x + w) - (1 - game.opengl), (y + h) - (1 - game.opengl),
alpha, 360.0 - RAD_TO_DEG( angle ));
}
*/
}
void SetSolidColour(Rgba col)
{
BeginBlendMode(BLEND_ALPHA);
BeginShaderMode(Shaders[SHADER_SOLID]);
//GLfloat texcols[4];
//bmp->setBlitColor(col.r, col.g, col.b, 1.0);
//if (game.opengl)
//{
// glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
// texcols[0] = col.r;
// texcols[1] = col.g;
// texcols[2] = col.b;
//
// glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texcols);
//}
//else
//{
// Demo version of PTK doesn't allow D3D handle.. :'(
//Texture2DD3D::_d3d->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
//Texture2DD3D::_d3d->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
//}
}
void CancelSolidColour()
{
EndShaderMode();
EndBlendMode();
//GLfloat texcols[4];
//bmp->setBlitColor(1.0, 1.0, 1.0, 1.0);
//if (game.opengl)
//{
// texcols[0] = 1.0;
// texcols[1] = 1.0;
// texcols[2] = 1.0;
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texcols);
//}
//else
//{
// //Texture2DD3D::_d3d->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
////Texture2DD3D::_d3d->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
//}
}
//
//void DrawShadedRect(int x1, int y1, int x2, int y2, Rgba c1, Rgba c2, Rgba c3, Rgba c4)
//{
// if (game.opengl)
// {
// glDisable( GL_TEXTURE_2D) ;
// glDisable( GL_BLEND ) ;
// glShadeModel( GL_SMOOTH );
//
// glBegin( GL_TRIANGLE_STRIP);
//
// y1 = ScreenHeight() - y1;
// y2 = ScreenHeight() - y2;
//
// glColor4f(c3.r, c3.g, c3.b, c3.a);
// glVertex3f(x1, y2, 0);
//
// glColor4f(c1.r, c1.g, c1.b, c1.a);
// glVertex3f(x1, y1, 0);
//
// glColor4f(c4.r, c4.g, c4.b, c4.a);
// glVertex3f(x2, y2, 0);
//
// glColor4f(c2.r, c2.g, c2.b, c2.a);
// glVertex3f(x2, y1, 0);
//
// glEnd();
//
// glEnable( GL_TEXTURE_2D) ;
// }
// else
// {
// #if !defined __APPLE__
///*
// y1++;
// y2++;
// y2 = -y2;
// y1 = -y1;
// if ( Texture2DD3D::_directX->TestCooperativeLevel() != DD_OK) return ;
//
// Texture2DD3D::_d3d->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
// Texture2DD3D::_d3d->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);
// Texture2DD3D::_d3d->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
// Texture2DD3D::_d3d->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
//
// D3DCOLOR col1 = D3DRGBA( c1.r, c1.g, c1.b, c1.a );
// D3DCOLOR col2 = D3DRGBA( c2.r, c2.g, c2.b, c2.a );
// D3DCOLOR col3 = D3DRGBA( c3.r, c3.g, c3.b, c3.a );
// D3DCOLOR col4 = D3DRGBA( c4.r, c4.g, c4.b, c4.a );
//
// D3DLVERTEX v[4];
// v[0] = D3DLVERTEX(D3DVECTOR(x1,y2,0), col3, 0, 0, 0);
// v[1] = D3DLVERTEX(D3DVECTOR(x1,y1,0), col1, 0, 0, 0);
// v[2] = D3DLVERTEX(D3DVECTOR(x2,y2,0), col4, 0, 0, 0);
// v[3] = D3DLVERTEX(D3DVECTOR(x2,y1,0), col2, 0, 0, 0);
//
// Texture2DD3D::_d3d->SetTexture(0, NULL);
//
// Texture2DD3D::_d3d->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_LVERTEX, &v[0], 4, 0);
//*/
// #endif
// }
//}
void CheckGfxExists(int g, char *file, int line)
{
char txt[MAX_STRING];
if (g > gfx.size())
{
sprintf(txt, "Gfx: %d in %s at line %d", g, file, line);
MessageBox("Gfx number does not exist!", txt);
}
}
int slprintf(char *buffer, size_t count, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
#ifdef _WIN32
ret = _vsnprintf(buffer, count-1, fmt, ap);
#else
ret = vsnprintf(buffer, count-1, fmt, ap);
#endif
if (ret < 0)
buffer[count-1] = '\0';
va_end(ap);
return ret;
}