framework2

Форк
0
1251 строка · 39.8 Кб
1
#include "ofGraphics.h"
2
#include "ofRendererCollection.h"
3
#include "ofGLRenderer.h"
4

5

6
#ifndef TARGET_WIN32
7
    #define CALLBACK
8
#endif
9

10
using std::shared_ptr;
11
using std::vector;
12
using std::string;
13

14
//style stuff - new in 006
15
static ofVboMesh gradientMesh;
16

17
void ofSetCurrentRenderer(shared_ptr<ofBaseRenderer> renderer,bool setDefaults){
18
	if(setDefaults){
19
		ofStyle style = ofGetCurrentRenderer()->getStyle();
20
		renderer->setupGraphicDefaults();
21
		renderer->setStyle(style);
22
	}
23
	ofGetCurrentRenderer() = renderer;
24
}
25

26
//----------------------------------------------------------
27
// transformation matrix related functions
28

29
//----------------------------------------------------------
30
void ofPushView(){
31
	ofGetCurrentRenderer()->pushView();
32
}
33

34
//----------------------------------------------------------
35
void ofPopView(){
36
	ofGetCurrentRenderer()->popView();
37
}
38

39
//----------------------------------------------------------
40
void ofViewport(ofRectangle viewport){
41
	ofGetCurrentRenderer()->viewport(viewport.x, viewport.y, viewport.width, viewport.height);
42
}
43

44
//----------------------------------------------------------
45
void ofViewport(float x, float y, float width, float height, bool invertY){
46
	ofGetCurrentRenderer()->viewport(x,y,width,height,invertY);
47
}
48

49
//----------------------------------------------------------
50
ofRectangle ofGetCurrentViewport(){
51
	return ofGetCurrentRenderer()->getCurrentViewport();
52
}
53

54
//----------------------------------------------------------
55
ofRectangle ofGetNativeViewport(){
56
	return ofGetCurrentRenderer()->getNativeViewport();
57
}
58

59
//----------------------------------------------------------
60
int ofGetViewportWidth(){
61
	return ofGetCurrentRenderer()->getViewportWidth();
62
}
63

64
//----------------------------------------------------------
65
int ofGetViewportHeight(){
66
	return ofGetCurrentRenderer()->getViewportHeight();
67
}
68

69
//----------------------------------------------------------
70
int ofOrientationToDegrees(ofOrientation orientation){
71
	switch(orientation){
72
	case OF_ORIENTATION_DEFAULT:
73
		return 0;
74
	case OF_ORIENTATION_180:
75
		return 180;
76
	case OF_ORIENTATION_90_RIGHT:
77
		return 270;
78
	case OF_ORIENTATION_90_LEFT:
79
		return 90;
80
	default:
81
		return 0;
82
	}
83
}
84

85
//----------------------------------------------------------
86
bool ofIsVFlipped(){
87
	return ofGetCurrentRenderer()->isVFlipped();
88
}
89

90
//----------------------------------------------------------
91
void ofSetCoordHandedness(ofHandednessType handedness){
92
	ofGetCurrentRenderer()->setCoordHandedness(handedness);
93
}
94

95
//----------------------------------------------------------
96
ofHandednessType ofGetCoordHandedness(){
97
	return ofGetCurrentRenderer()->getCoordHandedness();
98
}
99

100
//----------------------------------------------------------
101
void ofSetupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){
102
	ofGetCurrentRenderer()->setupScreenPerspective(width,height, fov,nearDist,farDist);
103
}
104

105
//----------------------------------------------------------
106
void ofSetupScreenOrtho(float width, float height, float nearDist, float farDist){
107
	ofGetCurrentRenderer()->setupScreenOrtho(width,height,nearDist,farDist);
108
}
109

110
//----------------------------------------------------------
111
//Resets openGL parameters back to OF defaults
112
void ofSetupGraphicDefaults(){
113
	ofGetCurrentRenderer()->setupGraphicDefaults();
114
}
115

116
//----------------------------------------------------------
117
void ofSetupScreen(){
118
	ofGetCurrentRenderer()->setupScreen();	// assume defaults
119
}
120

121

122

123
//our openGL wrappers
124
//----------------------------------------------------------
125
void ofPushMatrix(){
126
	ofGetCurrentRenderer()->pushMatrix();
127
}
128

129
//----------------------------------------------------------
130
void ofPopMatrix(){
131
	ofGetCurrentRenderer()->popMatrix();
132
}
133

134
//----------------------------------------------------------
135
/** @brief	Queries the current OpenGL matrix state
136
 *  @detail Returns the specified matrix as held by the renderer's current matrix stack.
137
 *
138
 *			You can query one of the following:
139
 *
140
 *			[OF_MATRIX_MODELVIEW | OF_MATRIX_PROJECTION | OF_MATRIX_TEXTURE]
141
 *
142
 *			Each query will return the state of the matrix
143
 *			as it was uploaded to the shader currently bound.
144
 *
145
 *	@param	matrixMode_  Which matrix mode to query
146
 */
147
glm::mat4 ofGetCurrentMatrix(ofMatrixMode matrixMode_){
148
	return ofGetCurrentRenderer()->getCurrentMatrix(matrixMode_);
149
}
150

151
//----------------------------------------------------------
152
glm::mat4 ofGetCurrentOrientationMatrix(){
153
	return ofGetCurrentRenderer()->getCurrentOrientationMatrix();
154
}
155

156
//----------------------------------------------------------
157
glm::mat4 ofGetCurrentNormalMatrix(){
158
	return ofGetCurrentRenderer()->getCurrentNormalMatrix();
159
}
160

161
//----------------------------------------------------------
162
void ofTranslate(const glm::vec3& p){
163
	ofGetCurrentRenderer()->translate(p);
164
}
165

166
//----------------------------------------------------------
167
void ofTranslate(const glm::vec2& p){
168
	ofGetCurrentRenderer()->translate(glm::vec3(p, 0.0));
169
}
170

171
//----------------------------------------------------------
172
void ofTranslate(float x, float y, float z){
173
	ofGetCurrentRenderer()->translate(x, y, z);
174
}
175

176
//----------------------------------------------------------
177
void ofScale(float xAmnt, float yAmnt, float zAmnt){
178
	ofGetCurrentRenderer()->scale(xAmnt, yAmnt, zAmnt);
179
}
180

181
void ofScale(float amount){
182
	ofScale(amount, amount, amount);
183
}
184

185
void ofScale(const glm::vec3 & p) {
186
	ofScale(p.x, p.y, p.z); 
187
}
188

189

190
//same as ofRotateZ
191
//----------------------------------------------------------
192
void ofRotate(float degrees){
193
	ofGetCurrentRenderer()->rotateDeg(degrees);
194
}
195

196
//----------------------------------------------------------
197
void ofRotate(float degrees, float vecX, float vecY, float vecZ){
198
	ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ);
199
}
200

201
//----------------------------------------------------------
202
void ofRotateX(float degrees){
203
	ofGetCurrentRenderer()->rotateXDeg(degrees);
204
}
205

206
//----------------------------------------------------------
207
void ofRotateY(float degrees){
208
	ofGetCurrentRenderer()->rotateYDeg(degrees);
209
}
210

211
//----------------------------------------------------------
212
void ofRotateZ(float degrees){
213
	ofGetCurrentRenderer()->rotateZDeg(degrees);
214
}
215

216
//same as ofRotateZ
217
//----------------------------------------------------------
218
void ofRotateDeg(float degrees){
219
	ofGetCurrentRenderer()->rotateDeg(degrees);
220
}
221

222
//----------------------------------------------------------
223
void ofRotateDeg(float degrees, float vecX, float vecY, float vecZ){
224
	ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ);
225
}
226

227
//----------------------------------------------------------
228
void ofRotateXDeg(float degrees){
229
	ofGetCurrentRenderer()->rotateXDeg(degrees);
230
}
231

232
//----------------------------------------------------------
233
void ofRotateYDeg(float degrees){
234
	ofGetCurrentRenderer()->rotateYDeg(degrees);
235
}
236

237
//----------------------------------------------------------
238
void ofRotateZDeg(float degrees){
239
	ofGetCurrentRenderer()->rotateZDeg(degrees);
240
}
241

242
//same as ofRotateZ
243
//----------------------------------------------------------
244
void ofRotateRad(float radians){
245
	ofGetCurrentRenderer()->rotateRad(radians);
246
}
247

248
//----------------------------------------------------------
249
void ofRotateRad(float radians, float vecX, float vecY, float vecZ){
250
	ofGetCurrentRenderer()->rotateRad(radians, vecX, vecY, vecZ);
251
}
252

253
//----------------------------------------------------------
254
void ofRotateXRad(float radians){
255
	ofGetCurrentRenderer()->rotateXRad(radians);
256
}
257

258
//----------------------------------------------------------
259
void ofRotateYRad(float radians){
260
	ofGetCurrentRenderer()->rotateYRad(radians);
261
}
262

263
//----------------------------------------------------------
264
void ofRotateZRad(float radians){
265
	ofGetCurrentRenderer()->rotateZRad(radians);
266
}
267

268
//----------------------------------------------------------
269
void ofLoadIdentityMatrix (void){
270
	ofGetCurrentRenderer()->loadIdentityMatrix();
271
}
272

273
//----------------------------------------------------------
274
void ofLoadMatrix (const glm::mat4 & m){
275
	ofGetCurrentRenderer()->loadMatrix(m);
276
}
277

278
//----------------------------------------------------------
279
void ofLoadMatrix (const float *m){
280
	ofGetCurrentRenderer()->loadMatrix(m);
281
}
282

283
//----------------------------------------------------------
284
void ofMultMatrix (const glm::mat4 & m){
285
	ofGetCurrentRenderer()->multMatrix(m);
286
}
287

288
//----------------------------------------------------------
289
void ofMultMatrix (const float *m){
290
	ofGetCurrentRenderer()->multMatrix(m);
291
}
292

293
//----------------------------------------------------------
294
void ofSetMatrixMode(ofMatrixMode matrixMode){
295
	ofGetCurrentRenderer()->matrixMode(matrixMode);
296
}
297

298
void ofLoadViewMatrix(const glm::mat4 & m){
299
	ofGetCurrentRenderer()->loadViewMatrix(m);
300
}
301

302
void ofMultViewMatrix(const glm::mat4 & m){
303
	ofGetCurrentRenderer()->multViewMatrix(m);
304
}
305

306
glm::mat4 ofGetCurrentViewMatrix(){
307
	return ofGetCurrentRenderer()->getCurrentViewMatrix();
308
}
309

310
// end transformation matrix related functions
311
//----------------------------------------------------------
312

313

314
//----------------------------------------------------------
315
// background functions
316

317
//----------------------------------------------------------
318
void ofClear(float r, float g, float b, float a){
319
	ofGetCurrentRenderer()->clear(r,g,b,a);
320
}
321

322
//----------------------------------------------------------
323
void ofClear(float brightness, float a){
324
	ofGetCurrentRenderer()->clear(brightness, brightness, brightness, a);
325
}
326

327
//----------------------------------------------------------
328
void ofClear(const ofColor & c){
329
	ofGetCurrentRenderer()->clear(c.r, c.g, c.b, c.a);
330
}
331

332
//----------------------------------------------------------
333
void ofClearAlpha(){
334
	ofGetCurrentRenderer()->clearAlpha();
335
}	
336

337
//----------------------------------------------------------
338
void ofSetBackgroundAuto(bool bAuto){
339
	ofGetCurrentRenderer()->setBackgroundAuto(bAuto);
340
}
341

342
bool ofGetBackgroundAuto(){
343
	return ofGetCurrentRenderer()->getBackgroundAuto();
344
}
345

346
//----------------------------------------------------------
347
bool ofbClearBg(){
348
	return ofGetBackgroundAuto();
349
}
350

351
//----------------------------------------------------------
352
ofColor ofGetBackground(){
353
	return ofGetCurrentRenderer()->getBackgroundColor();
354
}
355

356
//----------------------------------------------------------
357
ofColor ofGetBackgroundColor(){
358
	return ofGetCurrentRenderer()->getBackgroundColor();
359
}
360

361
//----------------------------------------------------------
362
void ofBackground(int brightness, int alpha){
363
	ofBackground(brightness, brightness, brightness, alpha);
364
}
365

366
//----------------------------------------------------------
367
void ofBackground(const ofColor & c){
368
	ofBackground ( c.r, c.g, c.b, c.a);
369
}
370

371
//----------------------------------------------------------
372
void ofBackgroundHex(int hexColor, int alpha){
373
	ofBackground ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha);
374
}
375

376
//----------------------------------------------------------
377
void ofBackground(int r, int g, int b, int a){
378
	ofGetCurrentRenderer()->background(r,g,b,a);
379
}
380

381
//----------------------------------------------------------
382
void ofBackgroundGradient(const ofColor& start, const ofColor& end, ofGradientMode mode) {
383
	float w = ofGetViewportWidth(), h = ofGetViewportHeight();
384
	gradientMesh.clear();
385
	gradientMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
386
#ifndef TARGET_EMSCRIPTEN
387
	#ifdef TARGET_OPENGLES
388
		if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW);
389
	#else
390
		gradientMesh.setUsage(GL_STREAM_DRAW);
391
	#endif
392
#endif
393
	if(mode == OF_GRADIENT_CIRCULAR) {
394
		// this could be optimized by building a single mesh once, then copying
395
		// it and just adding the colors whenever the function is called.
396
		///TODO: revert to glm::vec2!!
397
		glm::vec2 center(w / 2, h / 2);
398
		gradientMesh.addVertex(glm::vec3(center, 0.f));
399
		gradientMesh.addColor(start);
400
		float n = 32; // circular gradient resolution
401
		float angleBisector = glm::two_pi<float>() / (n * 2.0);
402
		float smallRadius = ofDist(0, 0, w / 2, h / 2);
403
		float bigRadius = smallRadius / cos(angleBisector);
404
		for(int i = 0; i <= n; i++) {
405
			float theta = i * glm::two_pi<float>() / n;
406
			gradientMesh.addVertex(glm::vec3(center + glm::vec2(sin(theta), cos(theta)) * bigRadius, 0));
407
			gradientMesh.addColor(end);
408
		}
409
	} else if(mode == OF_GRADIENT_LINEAR) {
410
		gradientMesh.addVertex({0.f, 0.f, 0.f});
411
		gradientMesh.addVertex({w, 0.f, 0.f});
412
		gradientMesh.addVertex({w, h, 0.f});
413
		gradientMesh.addVertex({0.f, h, 0.f});
414
		gradientMesh.addColor(start);
415
		gradientMesh.addColor(start);
416
		gradientMesh.addColor(end);
417
		gradientMesh.addColor(end);
418
	} else if(mode == OF_GRADIENT_BAR) {
419
		gradientMesh.addVertex({w / 2.f, h / 2.f, 0.f});
420
		gradientMesh.addVertex({0.f, h / 2.f, 0.f});
421
		gradientMesh.addVertex({0.f, 0.f, 0.f});
422
		gradientMesh.addVertex({w, 0.f, 0.f});
423
		gradientMesh.addVertex({w, h / 2.f, 0.f});
424
		gradientMesh.addVertex({w, h, 0.f});
425
		gradientMesh.addVertex({0.f, h, 0.f});
426
		gradientMesh.addVertex({0.f, h / 2, 0.f});
427
		gradientMesh.addColor(start);
428
		gradientMesh.addColor(start);
429
		gradientMesh.addColor(end);
430
		gradientMesh.addColor(end);
431
		gradientMesh.addColor(start);
432
		gradientMesh.addColor(end);
433
		gradientMesh.addColor(end);
434
		gradientMesh.addColor(start);
435
	}
436
	GLboolean depthMaskEnabled;
437
	glGetBooleanv(GL_DEPTH_WRITEMASK,&depthMaskEnabled);
438
	glDepthMask(GL_FALSE);
439
	gradientMesh.draw();
440
	if(depthMaskEnabled){
441
		glDepthMask(GL_TRUE);
442
	}
443
}
444

445
//----------------------------------------------------------
446
void ofSetBackgroundColor(int brightness, int alpha){
447
	ofSetBackgroundColor(brightness, brightness, brightness, alpha);
448
}
449

450
//----------------------------------------------------------
451
void ofSetBackgroundColorHex(int hexColor, int alpha){
452
	ofSetBackgroundColor ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha);
453
}
454

455
//----------------------------------------------------------
456
void ofSetBackgroundColor(int r, int g, int b, int a){
457
	ofSetBackgroundColor (ofColor(r,g,b,a));
458
}
459

460
//----------------------------------------------------------
461
void ofSetBackgroundColor(const ofColor & c){
462
	ofGetCurrentRenderer()->setBackgroundColor(c);
463
}
464

465
// end background functions
466
//----------------------------------------------------------
467

468

469

470

471
//---------------------------------------------------------------------------
472
// drawing modes
473

474
//----------------------------------------------------------
475
void  ofSetRectMode(ofRectMode mode){
476
	ofGetCurrentRenderer()->setRectMode(mode);
477
}
478

479
//----------------------------------------------------------
480
ofRectMode ofGetRectMode(){
481
    return ofGetCurrentRenderer()->getRectMode();
482
}
483

484
//----------------------------------------------------------
485
void ofNoFill(){
486
	ofGetCurrentRenderer()->setFillMode(OF_OUTLINE);
487
}
488

489
//----------------------------------------------------------
490
void ofFill(){
491
	ofGetCurrentRenderer()->setFillMode(OF_FILLED);
492
}
493

494
// Returns OF_FILLED or OF_OUTLINE
495
//----------------------------------------------------------
496
ofFillFlag ofGetFill(){
497
    return ofGetCurrentRenderer()->getFillMode();
498
}
499

500
//----------------------------------------------------------
501
void ofSetLineWidth(float lineWidth){
502
	ofGetCurrentRenderer()->setLineWidth(lineWidth);
503
}
504

505
//----------------------------------------------------------
506
void ofSetDepthTest(bool depthTest){
507
	ofGetCurrentRenderer()->setDepthTest(depthTest);
508
}
509

510
//----------------------------------------------------------
511
void ofEnableDepthTest(){
512
	ofSetDepthTest(true);
513
}
514

515
//----------------------------------------------------------
516
void ofDisableDepthTest(){
517
	ofSetDepthTest(false);
518
}
519

520
//----------------------------------------
521
void ofSetCurveResolution(int res){
522
	ofGetCurrentRenderer()->setCurveResolution(res);
523
}
524

525
//----------------------------------------------------------
526
void ofSetCircleResolution(int res){
527
	ofGetCurrentRenderer()->setCircleResolution(res);
528
}
529

530
//----------------------------------------------------------
531
void ofSetColor(const ofColor & color){
532
	ofSetColor(color.r,color.g,color.b,color.a);
533
}
534

535
//----------------------------------------------------------
536
void ofSetColor(const ofColor & color, int _a){
537
	ofSetColor(color.r,color.g,color.b,_a);
538
}
539

540
//----------------------------------------------------------
541
void ofSetColor(int r, int g, int b){
542
	ofSetColor(r,g,b,255);
543
}
544

545

546
//----------------------------------------------------------
547
void ofSetColor(int r, int g, int b, int a){
548
	ofGetCurrentRenderer()->setColor(r,g,b,a);
549
}
550

551
//----------------------------------------------------------
552
void ofSetColor(int gray){
553
	if( gray > 255 ){
554
		ofLogWarning("ofGraphics") << "ofSetColor(): gray value > 255, perhaps you want ofSetHexColor(int hexColor) instead?";
555
	}
556
	ofSetColor(gray, gray, gray);
557
}
558

559
//----------------------------------------------------------
560
void ofSetHexColor(int hexColor){
561
	int r = (hexColor >> 16) & 0xff;
562
	int g = (hexColor >> 8) & 0xff;
563
	int b = (hexColor >> 0) & 0xff;
564
	ofSetColor(r,g,b);
565
}
566

567
//----------------------------------------------------------
568

569
void ofEnableBlendMode(ofBlendMode blendMode){
570
	ofGetCurrentRenderer()->setBlendMode(blendMode);
571
}
572

573
//----------------------------------------------------------
574
void ofEnablePointSprites(){
575
	if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){
576
		static_cast<ofBaseGLRenderer*>(ofGetCurrentRenderer().get())->enablePointSprites();
577
	}
578
}
579

580
//----------------------------------------------------------
581
void ofDisablePointSprites(){
582
	if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){
583
		static_cast<ofBaseGLRenderer*>(ofGetCurrentRenderer().get())->disablePointSprites();
584
	}
585
}
586

587
//----------------------------------------------------------
588
void ofDisableBlendMode(){
589
    ofEnableBlendMode(OF_BLENDMODE_DISABLED);
590
}
591

592
//----------------------------------------------------------
593
void ofEnableAlphaBlending(){
594
	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
595
}
596

597
//----------------------------------------------------------
598
void ofDisableAlphaBlending(){
599
    ofDisableBlendMode();
600
}
601

602
//----------------------------------------------------------
603
void ofEnableSmoothing(){
604
	// please see:
605
	// http://www.opengl.org/resources/faq/technical/rasterization.htm
606
	ofGetCurrentRenderer()->setLineSmoothing(true);
607
}
608

609
//----------------------------------------------------------
610
void ofDisableSmoothing(){
611
	ofGetCurrentRenderer()->setLineSmoothing(false);
612
}
613

614
//----------------------------------------------------------
615
void ofSetPolyMode(ofPolyWindingMode mode){
616
	ofGetCurrentRenderer()->setPolyMode(mode);
617
}
618

619
//----------------------------------------
620
void ofEnableAntiAliasing(){
621
	ofGetCurrentRenderer()->enableAntiAliasing();
622
}
623

624
//----------------------------------------
625
void ofDisableAntiAliasing(){
626
	ofGetCurrentRenderer()->disableAntiAliasing();
627
}
628

629
//----------------------------------------
630
void ofSetDrawBitmapMode(ofDrawBitmapMode mode){
631
	ofGetCurrentRenderer()->setBitmapTextMode(mode);
632
}
633

634
//----------------------------------------------------------
635
void ofSetStyle(ofStyle style){
636
	ofGetCurrentRenderer()->setStyle(style);
637
}
638

639
//----------------------------------------------------------
640
ofStyle ofGetStyle(){
641
	return ofGetCurrentRenderer()->getStyle();
642
}
643

644
//----------------------------------------------------------
645
void ofPushStyle(){
646
	ofGetCurrentRenderer()->pushStyle();
647
}
648

649
//----------------------------------------------------------
650
void ofPopStyle(){
651
	ofGetCurrentRenderer()->popStyle();
652
}
653

654

655

656
// end drawing modes
657
//---------------------------------------------------------------------------
658

659

660

661

662
//----------------------------------------------------------
663
// primitives
664

665
//----------------------------------------------------------
666
void ofDrawTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
667
	ofDrawTriangle(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z);
668
}
669

670
//----------------------------------------------------------
671
void ofDrawTriangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){
672
	ofDrawTriangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
673
}
674

675
//----------------------------------------------------------
676
void ofDrawTriangle(float x1,float y1,float x2,float y2,float x3, float y3){
677
	ofDrawTriangle(x1, y1, 0.0f, x2, y2, 0.0f, x3, y3, 0.0f);
678
}
679

680
//----------------------------------------------------------
681
void ofDrawTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){
682
	ofGetCurrentRenderer()->drawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3);
683
}
684

685
//----------------------------------------------------------
686
void ofDrawCircle(const glm::vec3 & p, float radius){
687
	ofDrawCircle(p.x, p.y, p.z, radius);
688
}
689

690
//----------------------------------------------------------
691
void ofDrawCircle(const glm::vec2 & p, float radius){
692
	ofDrawCircle(p.x, p.y, 0.0, radius);
693
}
694

695
//----------------------------------------------------------
696
void ofDrawCircle(float x, float y, float radius){
697
	ofDrawCircle(x,y,0,radius);
698
}
699

700
//----------------------------------------------------------
701
void ofDrawCircle(float x, float y, float z, float radius){
702
	ofGetCurrentRenderer()->drawCircle(x,y,z,radius);
703
}
704

705
//----------------------------------------------------------
706
void ofDrawEllipse(const glm::vec3 & p, float width, float height){
707
	ofDrawEllipse(p.x, p.y, p.z, width, height);
708
}
709

710
//----------------------------------------------------------
711
void ofDrawEllipse(const glm::vec2 & p, float width, float height){
712
	ofDrawEllipse(p.x, p.y, width, height);
713
}
714

715
//----------------------------------------------------------
716
void ofDrawEllipse(float x, float y, float width, float height){
717
	ofDrawEllipse(x,y,0,width,height);
718
}
719

720
//----------------------------------------------------------
721
void ofDrawEllipse(float x, float y, float z, float width, float height){
722
	ofGetCurrentRenderer()->drawEllipse(x,y,z,width,height);
723
}
724

725
//----------------------------------------------------------
726
void ofDrawLine(const glm::vec3 & p1, const glm::vec3 & p2){
727
	ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
728
}
729

730
//----------------------------------------------------------
731
void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2){
732
	ofDrawLine(p1.x, p1.y, p2.x, p2.y);
733
}
734

735
//----------------------------------------------------------
736
void ofDrawLine(float x1,float y1,float x2,float y2){
737
	ofDrawLine(x1, y1, 0.0f, x2, y2, 0.0f);
738
}
739

740
//----------------------------------------------------------
741
void ofDrawLine(float x1,float y1,float z1,float x2,float y2,float z2){
742
	ofGetCurrentRenderer()->drawLine(x1,y1,z1,x2,y2,z2);
743
}
744

745
//----------------------------------------------------------
746
void ofDrawRectangle(const ofRectangle & r){
747
	ofDrawRectangle(r.x,r.y,0.0f,r.width, r.height);
748
}
749

750
//----------------------------------------------------------
751
void ofDrawRectangle(const glm::vec3 & p,float w,float h){
752
	ofDrawRectangle(p.x, p.y, p.z, w, h);
753
}
754

755
//----------------------------------------------------------
756
void ofDrawRectangle(const glm::vec2 & p,float w,float h){
757
	ofDrawRectangle(p.x, p.y, w, h);
758
}
759

760
//----------------------------------------------------------
761
void ofDrawRectangle(float x,float y,float w,float h){
762
	ofDrawRectangle(x, y, 0.0f, w, h);
763
}
764

765
//----------------------------------------------------------
766
void ofDrawRectangle(float x,float y,float z,float w,float h){
767
	ofGetCurrentRenderer()->drawRectangle(x,y,z,w,h);
768
}
769

770
//----------------------------------------------------------
771
void ofDrawRectRounded(const ofRectangle & b, float r){
772
	ofDrawRectRounded(b,r,r,r,r);
773
}
774

775
//----------------------------------------------------------
776
void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float r){
777
	ofDrawRectRounded(p.x, p.y, p.z, w, h, r,r,r,r);
778
}
779

780
//----------------------------------------------------------
781
void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r){
782
	ofDrawRectRounded(p.x, p.y, 0.0, w, h, r,r,r,r);
783
}
784

785
//----------------------------------------------------------
786
void ofDrawRectRounded(float x, float y, float w, float h, float r){
787
	ofDrawRectRounded(x,y,0.0f,w,h,r,r,r,r);
788
}
789

790
//----------------------------------------------------------
791
void ofDrawRectRounded(float x, float y, float z, float w, float h, float r){
792
	ofDrawRectRounded(x,y,z,w,h,r,r,r,r);
793
}
794

795
//----------------------------------------------------------
796
void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius,
797
                                                        float topRightRadius,
798
                                                        float bottomRightRadius,
799
                                                        float bottomLeftRadius){
800
	ofDrawRectRounded(p.x,p.y,p.z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
801
}
802

803
//----------------------------------------------------------
804
void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float topLeftRadius,
805
														float topRightRadius,
806
														float bottomRightRadius,
807
														float bottomLeftRadius){
808
	ofDrawRectRounded(p.x,p.y,0.0,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
809
}
810

811
//----------------------------------------------------------
812
void ofDrawRectRounded(const ofRectangle & b, float topLeftRadius,
813
                                          float topRightRadius,
814
                                          float bottomRightRadius,
815
                                          float bottomLeftRadius) {
816

817
	// if the parameter is an ofRectangle we don't do rectMode
818
	ofDrawRectRounded(b.x,b.y,0.0f,b.width,b.height,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
819
}
820

821

822
//----------------------------------------------------------
823
void ofDrawRectRounded(float x, float y, float z, float w, float h, float topLeftRadius,
824
                                                                float topRightRadius,
825
                                                                float bottomRightRadius,
826
                                                                float bottomLeftRadius) {
827
	// respect the current rectmode
828
	switch (ofGetRectMode()) {
829
		case OF_RECTMODE_CENTER:
830
			x -= w / 2.0f;
831
			y -= h / 2.0f;
832
			break;
833
		default:
834
			break;
835
	}
836
	ofGetCurrentRenderer()->getPath().clear();
837
	ofGetCurrentRenderer()->getPath().rectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
838
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
839

840
}
841

842
//----------------------------------------------------------
843
void ofDrawCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
844
	ofGetCurrentRenderer()->getPath().clear();
845
	ofGetCurrentRenderer()->getPath().curveTo(x0,y0);
846
	ofGetCurrentRenderer()->getPath().curveTo(x1,y1);
847
	ofGetCurrentRenderer()->getPath().curveTo(x2,y2);
848
	ofGetCurrentRenderer()->getPath().curveTo(x3,y3);
849
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
850
}
851

852
//----------------------------------------------------------
853
void ofDrawCurve(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
854
	ofGetCurrentRenderer()->getPath().clear();
855
	ofGetCurrentRenderer()->getPath().curveTo(x0,y0,z0);
856
	ofGetCurrentRenderer()->getPath().curveTo(x1,y1,z1);
857
	ofGetCurrentRenderer()->getPath().curveTo(x2,y2,z2);
858
	ofGetCurrentRenderer()->getPath().curveTo(x3,y3,z3);
859
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
860
}
861

862

863
//----------------------------------------------------------
864
void ofDrawBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
865
	ofGetCurrentRenderer()->getPath().clear();
866
	ofGetCurrentRenderer()->getPath().moveTo(x0,y0);
867
	ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3);
868
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
869
}
870

871
//----------------------------------------------------------
872
void ofDrawBezier(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
873
	ofGetCurrentRenderer()->getPath().clear();
874
	ofGetCurrentRenderer()->getPath().moveTo(x0,y0,z0);
875
	ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3);
876
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
877
}
878

879
//----------------------------------------------------------
880
void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
881
	ofDrawTriangle(p1,p2,p3);
882
}
883

884
//----------------------------------------------------------
885
void ofTriangle(float x1,float y1,float x2,float y2,float x3, float y3){
886
	ofDrawTriangle(x1, y1, x2, y2, x3, y3);
887
}
888

889
//----------------------------------------------------------
890
void ofTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){
891
	ofDrawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3);
892
}
893

894
//----------------------------------------------------------
895
void ofCircle(const glm::vec3 & p, float radius){
896
	ofDrawCircle(p, radius);
897
}
898

899
//----------------------------------------------------------
900
void ofCircle(float x, float y, float radius){
901
	ofDrawCircle(x,y,radius);
902
}
903

904
//----------------------------------------------------------
905
void ofCircle(float x, float y, float z, float radius){
906
	ofDrawCircle(x,y,z,radius);
907
}
908

909
//----------------------------------------------------------
910
void ofEllipse(const glm::vec3 & p, float width, float height){
911
	ofDrawEllipse(p, width, height);
912
}
913

914
//----------------------------------------------------------
915
void ofEllipse(float x, float y, float width, float height){
916
	ofDrawEllipse(x,y,width,height);
917
}
918

919
//----------------------------------------------------------
920
void ofEllipse(float x, float y, float z, float width, float height){
921
	ofDrawEllipse(x,y,z,width,height);
922
}
923

924
//----------------------------------------------------------
925
void ofLine(const glm::vec3 & p1, const glm::vec3 & p2){
926
	ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
927
}
928

929
//----------------------------------------------------------
930
void ofLine(float x1,float y1,float x2,float y2){
931
	ofDrawLine(x1, y1, x2, y2);
932
}
933

934
//----------------------------------------------------------
935
void ofLine(float x1,float y1,float z1,float x2,float y2,float z2){
936
	ofDrawLine(x1,y1,z1,x2,y2,z2);
937
}
938

939
//----------------------------------------------------------
940
void ofRect(const ofRectangle & r){
941
	ofDrawRectangle(r.x,r.y,r.width, r.height);
942
}
943

944
//----------------------------------------------------------
945
void ofRect(const glm::vec3 & p,float w,float h){
946
	ofDrawRectangle(p, w, h);
947
}
948

949
//----------------------------------------------------------
950
void ofRect(float x,float y,float w,float h){
951
	ofDrawRectangle(x, y, w, h);
952
}
953

954
//----------------------------------------------------------
955
void ofRect(float x,float y,float z,float w,float h){
956
	ofDrawRectangle(x,y,z,w,h);
957
}
958

959
//----------------------------------------------------------
960
void ofRectRounded(const ofRectangle & b, float r){
961
	ofDrawRectRounded(b,r);
962
}
963

964
//----------------------------------------------------------
965
void ofRectRounded(const glm::vec3 & p, float w, float h, float r){
966
	ofDrawRectRounded(p, w, h, r);
967
}
968

969
//----------------------------------------------------------
970
void ofRectRounded(float x, float y, float w, float h, float r){
971
	ofDrawRectRounded(x, y, w, h, r);
972
}
973

974
//----------------------------------------------------------
975
void ofRectRounded(float x, float y, float z, float w, float h, float r){
976
	ofDrawRectRounded(x,y,z,w,h,r,r,r,r);
977
}
978

979
//----------------------------------------------------------
980
void ofRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius,
981
                                                        float topRightRadius,
982
                                                        float bottomRightRadius,
983
                                                        float bottomLeftRadius){
984
	ofDrawRectRounded(p,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
985
}
986

987
//----------------------------------------------------------
988
void ofRectRounded(const ofRectangle & b, float topLeftRadius,
989
                                          float topRightRadius,
990
                                          float bottomRightRadius,
991
                                          float bottomLeftRadius) {
992

993
	// if the parameter is an ofRectangle we don't do rectMode
994
	ofDrawRectRounded(b,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
995
}
996

997

998
//----------------------------------------------------------
999
void ofRectRounded(float x, float y, float z, float w, float h, float topLeftRadius,
1000
                                                                float topRightRadius,
1001
                                                                float bottomRightRadius,
1002
                                                                float bottomLeftRadius) {
1003

1004
	ofDrawRectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
1005

1006
}
1007

1008
//----------------------------------------------------------
1009
void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
1010
    ofDrawCurve(x0, y0, x1, y1, x2, y2, x3, y3);
1011
}
1012

1013
//----------------------------------------------------------
1014
void ofCurve(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
1015
	ofDrawCurve(x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3);
1016
}
1017

1018

1019
//----------------------------------------------------------
1020
void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
1021
    ofDrawBezier(x0,y0,x1,y1,x2,y2,x3,y3);
1022
}
1023

1024
//----------------------------------------------------------
1025
void ofBezier(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
1026
    ofDrawBezier(x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3);
1027
}
1028

1029
//----------------------------------------------------------
1030
void ofBeginShape(){
1031
	ofGetCurrentRenderer()->getPath().clear();
1032
}
1033

1034
//----------------------------------------------------------
1035
void ofVertex(float x, float y){
1036
	ofGetCurrentRenderer()->getPath().lineTo(x,y);
1037
}
1038

1039
//----------------------------------------------------------
1040
void ofVertex(float x, float y, float z){
1041
	ofGetCurrentRenderer()->getPath().lineTo(x,y,z);
1042
}
1043

1044
//---------------------------------------------------
1045
void ofVertex(const glm::vec3 & p){
1046
	ofGetCurrentRenderer()->getPath().lineTo(p);
1047
}
1048

1049
//---------------------------------------------------
1050
void ofVertex(const glm::vec2 & p){
1051
	ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0));
1052
}
1053

1054
//----------------------------------------------------------
1055
void ofVertices( const vector <glm::vec3> & polyPoints ){
1056
	for( const auto & p: polyPoints ){
1057
		ofGetCurrentRenderer()->getPath().lineTo(p);
1058
	}
1059
}
1060

1061
//----------------------------------------------------------
1062
void ofVertices( const vector <glm::vec2> & polyPoints ){
1063
	for( const auto & p: polyPoints ){
1064
		ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0));
1065
	}
1066
}
1067

1068
//----------------------------------------------------------
1069
void ofVertices( const vector <ofVec3f> & polyPoints ){
1070
	for( const auto & p: polyPoints ){
1071
		ofGetCurrentRenderer()->getPath().lineTo(p);
1072
	}
1073
}
1074

1075
//----------------------------------------------------------
1076
void ofVertices( const vector <ofVec2f> & polyPoints ){
1077
	for( const auto & p: polyPoints ){
1078
		ofGetCurrentRenderer()->getPath().lineTo(p);
1079
	}
1080
}
1081

1082
//---------------------------------------------------
1083
void ofCurveVertex(float x, float y){
1084
	ofGetCurrentRenderer()->getPath().curveTo(x,y);
1085
}
1086

1087
//---------------------------------------------------
1088
void ofCurveVertex(float x, float y, float z){
1089
	ofGetCurrentRenderer()->getPath().curveTo(x,y,z);
1090
}
1091

1092
//----------------------------------------------------------
1093
void ofCurveVertices( const vector <glm::vec3> & curvePoints){
1094
	for( const auto & p: curvePoints ){
1095
		ofGetCurrentRenderer()->getPath().curveTo(p);
1096
	}
1097
}
1098

1099
//----------------------------------------------------------
1100
void ofCurveVertices( const vector <glm::vec2> & curvePoints){
1101
	for( const auto & p: curvePoints ){
1102
		ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0));
1103
	}
1104
}
1105

1106
//----------------------------------------------------------
1107
void ofCurveVertices( const vector <ofVec3f> & curvePoints){
1108
	for( const auto & p: curvePoints ){
1109
		ofGetCurrentRenderer()->getPath().curveTo(p);
1110
	}
1111
}
1112

1113
//----------------------------------------------------------
1114
void ofCurveVertices( const vector <ofVec2f> & curvePoints){
1115
	for( const auto & p: curvePoints ){
1116
		ofGetCurrentRenderer()->getPath().curveTo(p);
1117
	}
1118
}
1119

1120
//---------------------------------------------------
1121
void ofCurveVertex(const glm::vec3 & p){
1122
	ofGetCurrentRenderer()->getPath().curveTo(p);
1123
}
1124

1125
//---------------------------------------------------
1126
void ofCurveVertex(const glm::vec2 & p){
1127
	ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0));
1128
}
1129

1130
//---------------------------------------------------
1131
void ofBezierVertex(float x1, float y1, float x2, float y2, float x3, float y3){
1132
	ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3);
1133
}
1134

1135
//---------------------------------------------------
1136
void ofBezierVertex(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
1137
	ofGetCurrentRenderer()->getPath().bezierTo(p1, p2, p3);
1138
}
1139

1140
//---------------------------------------------------
1141
void ofBezierVertex(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){
1142
	ofGetCurrentRenderer()->getPath().bezierTo(glm::vec3(p1, 0.0), glm::vec3(p2,0.0), glm::vec3(p3,0.0));
1143
}
1144

1145
//---------------------------------------------------
1146
void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
1147
	ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3);
1148
}
1149

1150
//----------------------------------------------------------
1151
void ofNextContour(bool bClose){
1152
	if (bClose){
1153
		ofGetCurrentRenderer()->getPath().close();
1154
	}
1155
	ofGetCurrentRenderer()->getPath().newSubPath();
1156
}
1157

1158

1159
//----------------------------------------------------------
1160
void ofEndShape(bool bClose){
1161

1162
	// (close -> add the first point to the end)
1163
	// -----------------------------------------------
1164

1165
	if (bClose){
1166
		ofGetCurrentRenderer()->getPath().close();
1167
	}
1168

1169
    ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
1170

1171
}
1172

1173
//--------------------------------------------------
1174
// text
1175
//--------------------------------------------------
1176
template<>
1177
void ofDrawBitmapString(const string & textString, float x, float y, float z){
1178
	ofGetCurrentRenderer()->drawString(textString,x,y,z);
1179
}
1180

1181
template<>
1182
void ofDrawBitmapString(const std::string & textString, const glm::vec3 & p){
1183
	ofGetCurrentRenderer()->drawString(textString, p.x, p.y, p.z);
1184
}
1185

1186
template<>
1187
void ofDrawBitmapString(const std::string & textString, const glm::vec2 & p){
1188
	ofGetCurrentRenderer()->drawString(textString, p.x, p.y, 0.f);
1189
}
1190

1191
//--------------------------------------------------
1192
void ofDrawBitmapStringHighlight(string text, const glm::vec3& position, const ofColor& background, const ofColor& foreground) {
1193
	ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground);
1194
}
1195

1196
//--------------------------------------------------
1197
void ofDrawBitmapStringHighlight(string text, const glm::vec2& position, const ofColor& background, const ofColor& foreground) {
1198
	ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground);
1199
}
1200

1201
//--------------------------------------------------
1202
void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& background, const ofColor& foreground) {
1203
	vector<string> lines = ofSplitString(text, "\n");
1204
	int maxLineLength = 0;
1205
	for(int i = 0; i < (int)lines.size(); i++) {
1206
		// tabs are not rendered
1207
		const string & line(lines[i]);
1208
		int currentLineLength = 0;
1209
		for(int j = 0; j < (int)line.size(); j++) {
1210
			if (line[j] == '\t') {
1211
				currentLineLength += 8 - (currentLineLength % 8);
1212
			} else {
1213
				currentLineLength++;
1214
			}
1215
		}
1216
		maxLineLength = std::max(maxLineLength, currentLineLength);
1217
	}
1218
	
1219
	int padding = 4;
1220
	int fontSize = 8;
1221
	float leading = 1.7;
1222
	int height = lines.size() * fontSize * leading - 1;
1223
	int width = maxLineLength * fontSize;
1224
	
1225
	ofPushStyle();
1226
	glDepthMask(false);
1227
	ofSetColor(background);
1228
	ofFill();
1229
	ofPushMatrix();
1230
	
1231
	if(ofGetStyle().drawBitmapMode == OF_BITMAPMODE_MODEL) {
1232
		ofTranslate(x,y,0);
1233
		ofScale(1,-1,0);
1234
		ofTranslate(-(padding), + padding - fontSize - 2,0);
1235
	} else {
1236
		ofTranslate(x-(padding), y-(padding + fontSize + 2), 0);
1237
		
1238
	}
1239
	
1240
	ofDrawRectangle(0, 0, width + 2 * padding, height + 2 * padding);
1241
	ofPopMatrix();
1242
	ofSetColor(foreground);
1243
	ofNoFill();
1244
	ofDrawBitmapString(text, x, y);
1245
	glDepthMask(true);
1246
	ofPopStyle();
1247
}
1248

1249

1250
// end text
1251
//--------------------------------------------------
1252

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.