framework2
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
10using std::shared_ptr;
11using std::vector;
12using std::string;
13
14//style stuff - new in 006
15static ofVboMesh gradientMesh;
16
17void ofSetCurrentRenderer(shared_ptr<ofBaseRenderer> renderer,bool setDefaults){
18if(setDefaults){
19ofStyle style = ofGetCurrentRenderer()->getStyle();
20renderer->setupGraphicDefaults();
21renderer->setStyle(style);
22}
23ofGetCurrentRenderer() = renderer;
24}
25
26//----------------------------------------------------------
27// transformation matrix related functions
28
29//----------------------------------------------------------
30void ofPushView(){
31ofGetCurrentRenderer()->pushView();
32}
33
34//----------------------------------------------------------
35void ofPopView(){
36ofGetCurrentRenderer()->popView();
37}
38
39//----------------------------------------------------------
40void ofViewport(ofRectangle viewport){
41ofGetCurrentRenderer()->viewport(viewport.x, viewport.y, viewport.width, viewport.height);
42}
43
44//----------------------------------------------------------
45void ofViewport(float x, float y, float width, float height, bool invertY){
46ofGetCurrentRenderer()->viewport(x,y,width,height,invertY);
47}
48
49//----------------------------------------------------------
50ofRectangle ofGetCurrentViewport(){
51return ofGetCurrentRenderer()->getCurrentViewport();
52}
53
54//----------------------------------------------------------
55ofRectangle ofGetNativeViewport(){
56return ofGetCurrentRenderer()->getNativeViewport();
57}
58
59//----------------------------------------------------------
60int ofGetViewportWidth(){
61return ofGetCurrentRenderer()->getViewportWidth();
62}
63
64//----------------------------------------------------------
65int ofGetViewportHeight(){
66return ofGetCurrentRenderer()->getViewportHeight();
67}
68
69//----------------------------------------------------------
70int ofOrientationToDegrees(ofOrientation orientation){
71switch(orientation){
72case OF_ORIENTATION_DEFAULT:
73return 0;
74case OF_ORIENTATION_180:
75return 180;
76case OF_ORIENTATION_90_RIGHT:
77return 270;
78case OF_ORIENTATION_90_LEFT:
79return 90;
80default:
81return 0;
82}
83}
84
85//----------------------------------------------------------
86bool ofIsVFlipped(){
87return ofGetCurrentRenderer()->isVFlipped();
88}
89
90//----------------------------------------------------------
91void ofSetCoordHandedness(ofHandednessType handedness){
92ofGetCurrentRenderer()->setCoordHandedness(handedness);
93}
94
95//----------------------------------------------------------
96ofHandednessType ofGetCoordHandedness(){
97return ofGetCurrentRenderer()->getCoordHandedness();
98}
99
100//----------------------------------------------------------
101void ofSetupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){
102ofGetCurrentRenderer()->setupScreenPerspective(width,height, fov,nearDist,farDist);
103}
104
105//----------------------------------------------------------
106void ofSetupScreenOrtho(float width, float height, float nearDist, float farDist){
107ofGetCurrentRenderer()->setupScreenOrtho(width,height,nearDist,farDist);
108}
109
110//----------------------------------------------------------
111//Resets openGL parameters back to OF defaults
112void ofSetupGraphicDefaults(){
113ofGetCurrentRenderer()->setupGraphicDefaults();
114}
115
116//----------------------------------------------------------
117void ofSetupScreen(){
118ofGetCurrentRenderer()->setupScreen(); // assume defaults
119}
120
121
122
123//our openGL wrappers
124//----------------------------------------------------------
125void ofPushMatrix(){
126ofGetCurrentRenderer()->pushMatrix();
127}
128
129//----------------------------------------------------------
130void ofPopMatrix(){
131ofGetCurrentRenderer()->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*/
147glm::mat4 ofGetCurrentMatrix(ofMatrixMode matrixMode_){
148return ofGetCurrentRenderer()->getCurrentMatrix(matrixMode_);
149}
150
151//----------------------------------------------------------
152glm::mat4 ofGetCurrentOrientationMatrix(){
153return ofGetCurrentRenderer()->getCurrentOrientationMatrix();
154}
155
156//----------------------------------------------------------
157glm::mat4 ofGetCurrentNormalMatrix(){
158return ofGetCurrentRenderer()->getCurrentNormalMatrix();
159}
160
161//----------------------------------------------------------
162void ofTranslate(const glm::vec3& p){
163ofGetCurrentRenderer()->translate(p);
164}
165
166//----------------------------------------------------------
167void ofTranslate(const glm::vec2& p){
168ofGetCurrentRenderer()->translate(glm::vec3(p, 0.0));
169}
170
171//----------------------------------------------------------
172void ofTranslate(float x, float y, float z){
173ofGetCurrentRenderer()->translate(x, y, z);
174}
175
176//----------------------------------------------------------
177void ofScale(float xAmnt, float yAmnt, float zAmnt){
178ofGetCurrentRenderer()->scale(xAmnt, yAmnt, zAmnt);
179}
180
181void ofScale(float amount){
182ofScale(amount, amount, amount);
183}
184
185void ofScale(const glm::vec3 & p) {
186ofScale(p.x, p.y, p.z);
187}
188
189
190//same as ofRotateZ
191//----------------------------------------------------------
192void ofRotate(float degrees){
193ofGetCurrentRenderer()->rotateDeg(degrees);
194}
195
196//----------------------------------------------------------
197void ofRotate(float degrees, float vecX, float vecY, float vecZ){
198ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ);
199}
200
201//----------------------------------------------------------
202void ofRotateX(float degrees){
203ofGetCurrentRenderer()->rotateXDeg(degrees);
204}
205
206//----------------------------------------------------------
207void ofRotateY(float degrees){
208ofGetCurrentRenderer()->rotateYDeg(degrees);
209}
210
211//----------------------------------------------------------
212void ofRotateZ(float degrees){
213ofGetCurrentRenderer()->rotateZDeg(degrees);
214}
215
216//same as ofRotateZ
217//----------------------------------------------------------
218void ofRotateDeg(float degrees){
219ofGetCurrentRenderer()->rotateDeg(degrees);
220}
221
222//----------------------------------------------------------
223void ofRotateDeg(float degrees, float vecX, float vecY, float vecZ){
224ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ);
225}
226
227//----------------------------------------------------------
228void ofRotateXDeg(float degrees){
229ofGetCurrentRenderer()->rotateXDeg(degrees);
230}
231
232//----------------------------------------------------------
233void ofRotateYDeg(float degrees){
234ofGetCurrentRenderer()->rotateYDeg(degrees);
235}
236
237//----------------------------------------------------------
238void ofRotateZDeg(float degrees){
239ofGetCurrentRenderer()->rotateZDeg(degrees);
240}
241
242//same as ofRotateZ
243//----------------------------------------------------------
244void ofRotateRad(float radians){
245ofGetCurrentRenderer()->rotateRad(radians);
246}
247
248//----------------------------------------------------------
249void ofRotateRad(float radians, float vecX, float vecY, float vecZ){
250ofGetCurrentRenderer()->rotateRad(radians, vecX, vecY, vecZ);
251}
252
253//----------------------------------------------------------
254void ofRotateXRad(float radians){
255ofGetCurrentRenderer()->rotateXRad(radians);
256}
257
258//----------------------------------------------------------
259void ofRotateYRad(float radians){
260ofGetCurrentRenderer()->rotateYRad(radians);
261}
262
263//----------------------------------------------------------
264void ofRotateZRad(float radians){
265ofGetCurrentRenderer()->rotateZRad(radians);
266}
267
268//----------------------------------------------------------
269void ofLoadIdentityMatrix (void){
270ofGetCurrentRenderer()->loadIdentityMatrix();
271}
272
273//----------------------------------------------------------
274void ofLoadMatrix (const glm::mat4 & m){
275ofGetCurrentRenderer()->loadMatrix(m);
276}
277
278//----------------------------------------------------------
279void ofLoadMatrix (const float *m){
280ofGetCurrentRenderer()->loadMatrix(m);
281}
282
283//----------------------------------------------------------
284void ofMultMatrix (const glm::mat4 & m){
285ofGetCurrentRenderer()->multMatrix(m);
286}
287
288//----------------------------------------------------------
289void ofMultMatrix (const float *m){
290ofGetCurrentRenderer()->multMatrix(m);
291}
292
293//----------------------------------------------------------
294void ofSetMatrixMode(ofMatrixMode matrixMode){
295ofGetCurrentRenderer()->matrixMode(matrixMode);
296}
297
298void ofLoadViewMatrix(const glm::mat4 & m){
299ofGetCurrentRenderer()->loadViewMatrix(m);
300}
301
302void ofMultViewMatrix(const glm::mat4 & m){
303ofGetCurrentRenderer()->multViewMatrix(m);
304}
305
306glm::mat4 ofGetCurrentViewMatrix(){
307return ofGetCurrentRenderer()->getCurrentViewMatrix();
308}
309
310// end transformation matrix related functions
311//----------------------------------------------------------
312
313
314//----------------------------------------------------------
315// background functions
316
317//----------------------------------------------------------
318void ofClear(float r, float g, float b, float a){
319ofGetCurrentRenderer()->clear(r,g,b,a);
320}
321
322//----------------------------------------------------------
323void ofClear(float brightness, float a){
324ofGetCurrentRenderer()->clear(brightness, brightness, brightness, a);
325}
326
327//----------------------------------------------------------
328void ofClear(const ofColor & c){
329ofGetCurrentRenderer()->clear(c.r, c.g, c.b, c.a);
330}
331
332//----------------------------------------------------------
333void ofClearAlpha(){
334ofGetCurrentRenderer()->clearAlpha();
335}
336
337//----------------------------------------------------------
338void ofSetBackgroundAuto(bool bAuto){
339ofGetCurrentRenderer()->setBackgroundAuto(bAuto);
340}
341
342bool ofGetBackgroundAuto(){
343return ofGetCurrentRenderer()->getBackgroundAuto();
344}
345
346//----------------------------------------------------------
347bool ofbClearBg(){
348return ofGetBackgroundAuto();
349}
350
351//----------------------------------------------------------
352ofColor ofGetBackground(){
353return ofGetCurrentRenderer()->getBackgroundColor();
354}
355
356//----------------------------------------------------------
357ofColor ofGetBackgroundColor(){
358return ofGetCurrentRenderer()->getBackgroundColor();
359}
360
361//----------------------------------------------------------
362void ofBackground(int brightness, int alpha){
363ofBackground(brightness, brightness, brightness, alpha);
364}
365
366//----------------------------------------------------------
367void ofBackground(const ofColor & c){
368ofBackground ( c.r, c.g, c.b, c.a);
369}
370
371//----------------------------------------------------------
372void ofBackgroundHex(int hexColor, int alpha){
373ofBackground ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha);
374}
375
376//----------------------------------------------------------
377void ofBackground(int r, int g, int b, int a){
378ofGetCurrentRenderer()->background(r,g,b,a);
379}
380
381//----------------------------------------------------------
382void ofBackgroundGradient(const ofColor& start, const ofColor& end, ofGradientMode mode) {
383float w = ofGetViewportWidth(), h = ofGetViewportHeight();
384gradientMesh.clear();
385gradientMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
386#ifndef TARGET_EMSCRIPTEN
387#ifdef TARGET_OPENGLES
388if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW);
389#else
390gradientMesh.setUsage(GL_STREAM_DRAW);
391#endif
392#endif
393if(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!!
397glm::vec2 center(w / 2, h / 2);
398gradientMesh.addVertex(glm::vec3(center, 0.f));
399gradientMesh.addColor(start);
400float n = 32; // circular gradient resolution
401float angleBisector = glm::two_pi<float>() / (n * 2.0);
402float smallRadius = ofDist(0, 0, w / 2, h / 2);
403float bigRadius = smallRadius / cos(angleBisector);
404for(int i = 0; i <= n; i++) {
405float theta = i * glm::two_pi<float>() / n;
406gradientMesh.addVertex(glm::vec3(center + glm::vec2(sin(theta), cos(theta)) * bigRadius, 0));
407gradientMesh.addColor(end);
408}
409} else if(mode == OF_GRADIENT_LINEAR) {
410gradientMesh.addVertex({0.f, 0.f, 0.f});
411gradientMesh.addVertex({w, 0.f, 0.f});
412gradientMesh.addVertex({w, h, 0.f});
413gradientMesh.addVertex({0.f, h, 0.f});
414gradientMesh.addColor(start);
415gradientMesh.addColor(start);
416gradientMesh.addColor(end);
417gradientMesh.addColor(end);
418} else if(mode == OF_GRADIENT_BAR) {
419gradientMesh.addVertex({w / 2.f, h / 2.f, 0.f});
420gradientMesh.addVertex({0.f, h / 2.f, 0.f});
421gradientMesh.addVertex({0.f, 0.f, 0.f});
422gradientMesh.addVertex({w, 0.f, 0.f});
423gradientMesh.addVertex({w, h / 2.f, 0.f});
424gradientMesh.addVertex({w, h, 0.f});
425gradientMesh.addVertex({0.f, h, 0.f});
426gradientMesh.addVertex({0.f, h / 2, 0.f});
427gradientMesh.addColor(start);
428gradientMesh.addColor(start);
429gradientMesh.addColor(end);
430gradientMesh.addColor(end);
431gradientMesh.addColor(start);
432gradientMesh.addColor(end);
433gradientMesh.addColor(end);
434gradientMesh.addColor(start);
435}
436GLboolean depthMaskEnabled;
437glGetBooleanv(GL_DEPTH_WRITEMASK,&depthMaskEnabled);
438glDepthMask(GL_FALSE);
439gradientMesh.draw();
440if(depthMaskEnabled){
441glDepthMask(GL_TRUE);
442}
443}
444
445//----------------------------------------------------------
446void ofSetBackgroundColor(int brightness, int alpha){
447ofSetBackgroundColor(brightness, brightness, brightness, alpha);
448}
449
450//----------------------------------------------------------
451void ofSetBackgroundColorHex(int hexColor, int alpha){
452ofSetBackgroundColor ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha);
453}
454
455//----------------------------------------------------------
456void ofSetBackgroundColor(int r, int g, int b, int a){
457ofSetBackgroundColor (ofColor(r,g,b,a));
458}
459
460//----------------------------------------------------------
461void ofSetBackgroundColor(const ofColor & c){
462ofGetCurrentRenderer()->setBackgroundColor(c);
463}
464
465// end background functions
466//----------------------------------------------------------
467
468
469
470
471//---------------------------------------------------------------------------
472// drawing modes
473
474//----------------------------------------------------------
475void ofSetRectMode(ofRectMode mode){
476ofGetCurrentRenderer()->setRectMode(mode);
477}
478
479//----------------------------------------------------------
480ofRectMode ofGetRectMode(){
481return ofGetCurrentRenderer()->getRectMode();
482}
483
484//----------------------------------------------------------
485void ofNoFill(){
486ofGetCurrentRenderer()->setFillMode(OF_OUTLINE);
487}
488
489//----------------------------------------------------------
490void ofFill(){
491ofGetCurrentRenderer()->setFillMode(OF_FILLED);
492}
493
494// Returns OF_FILLED or OF_OUTLINE
495//----------------------------------------------------------
496ofFillFlag ofGetFill(){
497return ofGetCurrentRenderer()->getFillMode();
498}
499
500//----------------------------------------------------------
501void ofSetLineWidth(float lineWidth){
502ofGetCurrentRenderer()->setLineWidth(lineWidth);
503}
504
505//----------------------------------------------------------
506void ofSetDepthTest(bool depthTest){
507ofGetCurrentRenderer()->setDepthTest(depthTest);
508}
509
510//----------------------------------------------------------
511void ofEnableDepthTest(){
512ofSetDepthTest(true);
513}
514
515//----------------------------------------------------------
516void ofDisableDepthTest(){
517ofSetDepthTest(false);
518}
519
520//----------------------------------------
521void ofSetCurveResolution(int res){
522ofGetCurrentRenderer()->setCurveResolution(res);
523}
524
525//----------------------------------------------------------
526void ofSetCircleResolution(int res){
527ofGetCurrentRenderer()->setCircleResolution(res);
528}
529
530//----------------------------------------------------------
531void ofSetColor(const ofColor & color){
532ofSetColor(color.r,color.g,color.b,color.a);
533}
534
535//----------------------------------------------------------
536void ofSetColor(const ofColor & color, int _a){
537ofSetColor(color.r,color.g,color.b,_a);
538}
539
540//----------------------------------------------------------
541void ofSetColor(int r, int g, int b){
542ofSetColor(r,g,b,255);
543}
544
545
546//----------------------------------------------------------
547void ofSetColor(int r, int g, int b, int a){
548ofGetCurrentRenderer()->setColor(r,g,b,a);
549}
550
551//----------------------------------------------------------
552void ofSetColor(int gray){
553if( gray > 255 ){
554ofLogWarning("ofGraphics") << "ofSetColor(): gray value > 255, perhaps you want ofSetHexColor(int hexColor) instead?";
555}
556ofSetColor(gray, gray, gray);
557}
558
559//----------------------------------------------------------
560void ofSetHexColor(int hexColor){
561int r = (hexColor >> 16) & 0xff;
562int g = (hexColor >> 8) & 0xff;
563int b = (hexColor >> 0) & 0xff;
564ofSetColor(r,g,b);
565}
566
567//----------------------------------------------------------
568
569void ofEnableBlendMode(ofBlendMode blendMode){
570ofGetCurrentRenderer()->setBlendMode(blendMode);
571}
572
573//----------------------------------------------------------
574void ofEnablePointSprites(){
575if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){
576static_cast<ofBaseGLRenderer*>(ofGetCurrentRenderer().get())->enablePointSprites();
577}
578}
579
580//----------------------------------------------------------
581void ofDisablePointSprites(){
582if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){
583static_cast<ofBaseGLRenderer*>(ofGetCurrentRenderer().get())->disablePointSprites();
584}
585}
586
587//----------------------------------------------------------
588void ofDisableBlendMode(){
589ofEnableBlendMode(OF_BLENDMODE_DISABLED);
590}
591
592//----------------------------------------------------------
593void ofEnableAlphaBlending(){
594ofEnableBlendMode(OF_BLENDMODE_ALPHA);
595}
596
597//----------------------------------------------------------
598void ofDisableAlphaBlending(){
599ofDisableBlendMode();
600}
601
602//----------------------------------------------------------
603void ofEnableSmoothing(){
604// please see:
605// http://www.opengl.org/resources/faq/technical/rasterization.htm
606ofGetCurrentRenderer()->setLineSmoothing(true);
607}
608
609//----------------------------------------------------------
610void ofDisableSmoothing(){
611ofGetCurrentRenderer()->setLineSmoothing(false);
612}
613
614//----------------------------------------------------------
615void ofSetPolyMode(ofPolyWindingMode mode){
616ofGetCurrentRenderer()->setPolyMode(mode);
617}
618
619//----------------------------------------
620void ofEnableAntiAliasing(){
621ofGetCurrentRenderer()->enableAntiAliasing();
622}
623
624//----------------------------------------
625void ofDisableAntiAliasing(){
626ofGetCurrentRenderer()->disableAntiAliasing();
627}
628
629//----------------------------------------
630void ofSetDrawBitmapMode(ofDrawBitmapMode mode){
631ofGetCurrentRenderer()->setBitmapTextMode(mode);
632}
633
634//----------------------------------------------------------
635void ofSetStyle(ofStyle style){
636ofGetCurrentRenderer()->setStyle(style);
637}
638
639//----------------------------------------------------------
640ofStyle ofGetStyle(){
641return ofGetCurrentRenderer()->getStyle();
642}
643
644//----------------------------------------------------------
645void ofPushStyle(){
646ofGetCurrentRenderer()->pushStyle();
647}
648
649//----------------------------------------------------------
650void ofPopStyle(){
651ofGetCurrentRenderer()->popStyle();
652}
653
654
655
656// end drawing modes
657//---------------------------------------------------------------------------
658
659
660
661
662//----------------------------------------------------------
663// primitives
664
665//----------------------------------------------------------
666void ofDrawTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
667ofDrawTriangle(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z);
668}
669
670//----------------------------------------------------------
671void ofDrawTriangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){
672ofDrawTriangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
673}
674
675//----------------------------------------------------------
676void ofDrawTriangle(float x1,float y1,float x2,float y2,float x3, float y3){
677ofDrawTriangle(x1, y1, 0.0f, x2, y2, 0.0f, x3, y3, 0.0f);
678}
679
680//----------------------------------------------------------
681void ofDrawTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){
682ofGetCurrentRenderer()->drawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3);
683}
684
685//----------------------------------------------------------
686void ofDrawCircle(const glm::vec3 & p, float radius){
687ofDrawCircle(p.x, p.y, p.z, radius);
688}
689
690//----------------------------------------------------------
691void ofDrawCircle(const glm::vec2 & p, float radius){
692ofDrawCircle(p.x, p.y, 0.0, radius);
693}
694
695//----------------------------------------------------------
696void ofDrawCircle(float x, float y, float radius){
697ofDrawCircle(x,y,0,radius);
698}
699
700//----------------------------------------------------------
701void ofDrawCircle(float x, float y, float z, float radius){
702ofGetCurrentRenderer()->drawCircle(x,y,z,radius);
703}
704
705//----------------------------------------------------------
706void ofDrawEllipse(const glm::vec3 & p, float width, float height){
707ofDrawEllipse(p.x, p.y, p.z, width, height);
708}
709
710//----------------------------------------------------------
711void ofDrawEllipse(const glm::vec2 & p, float width, float height){
712ofDrawEllipse(p.x, p.y, width, height);
713}
714
715//----------------------------------------------------------
716void ofDrawEllipse(float x, float y, float width, float height){
717ofDrawEllipse(x,y,0,width,height);
718}
719
720//----------------------------------------------------------
721void ofDrawEllipse(float x, float y, float z, float width, float height){
722ofGetCurrentRenderer()->drawEllipse(x,y,z,width,height);
723}
724
725//----------------------------------------------------------
726void ofDrawLine(const glm::vec3 & p1, const glm::vec3 & p2){
727ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
728}
729
730//----------------------------------------------------------
731void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2){
732ofDrawLine(p1.x, p1.y, p2.x, p2.y);
733}
734
735//----------------------------------------------------------
736void ofDrawLine(float x1,float y1,float x2,float y2){
737ofDrawLine(x1, y1, 0.0f, x2, y2, 0.0f);
738}
739
740//----------------------------------------------------------
741void ofDrawLine(float x1,float y1,float z1,float x2,float y2,float z2){
742ofGetCurrentRenderer()->drawLine(x1,y1,z1,x2,y2,z2);
743}
744
745//----------------------------------------------------------
746void ofDrawRectangle(const ofRectangle & r){
747ofDrawRectangle(r.x,r.y,0.0f,r.width, r.height);
748}
749
750//----------------------------------------------------------
751void ofDrawRectangle(const glm::vec3 & p,float w,float h){
752ofDrawRectangle(p.x, p.y, p.z, w, h);
753}
754
755//----------------------------------------------------------
756void ofDrawRectangle(const glm::vec2 & p,float w,float h){
757ofDrawRectangle(p.x, p.y, w, h);
758}
759
760//----------------------------------------------------------
761void ofDrawRectangle(float x,float y,float w,float h){
762ofDrawRectangle(x, y, 0.0f, w, h);
763}
764
765//----------------------------------------------------------
766void ofDrawRectangle(float x,float y,float z,float w,float h){
767ofGetCurrentRenderer()->drawRectangle(x,y,z,w,h);
768}
769
770//----------------------------------------------------------
771void ofDrawRectRounded(const ofRectangle & b, float r){
772ofDrawRectRounded(b,r,r,r,r);
773}
774
775//----------------------------------------------------------
776void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float r){
777ofDrawRectRounded(p.x, p.y, p.z, w, h, r,r,r,r);
778}
779
780//----------------------------------------------------------
781void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r){
782ofDrawRectRounded(p.x, p.y, 0.0, w, h, r,r,r,r);
783}
784
785//----------------------------------------------------------
786void ofDrawRectRounded(float x, float y, float w, float h, float r){
787ofDrawRectRounded(x,y,0.0f,w,h,r,r,r,r);
788}
789
790//----------------------------------------------------------
791void ofDrawRectRounded(float x, float y, float z, float w, float h, float r){
792ofDrawRectRounded(x,y,z,w,h,r,r,r,r);
793}
794
795//----------------------------------------------------------
796void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius,
797float topRightRadius,
798float bottomRightRadius,
799float bottomLeftRadius){
800ofDrawRectRounded(p.x,p.y,p.z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
801}
802
803//----------------------------------------------------------
804void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float topLeftRadius,
805float topRightRadius,
806float bottomRightRadius,
807float bottomLeftRadius){
808ofDrawRectRounded(p.x,p.y,0.0,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
809}
810
811//----------------------------------------------------------
812void ofDrawRectRounded(const ofRectangle & b, float topLeftRadius,
813float topRightRadius,
814float bottomRightRadius,
815float bottomLeftRadius) {
816
817// if the parameter is an ofRectangle we don't do rectMode
818ofDrawRectRounded(b.x,b.y,0.0f,b.width,b.height,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
819}
820
821
822//----------------------------------------------------------
823void ofDrawRectRounded(float x, float y, float z, float w, float h, float topLeftRadius,
824float topRightRadius,
825float bottomRightRadius,
826float bottomLeftRadius) {
827// respect the current rectmode
828switch (ofGetRectMode()) {
829case OF_RECTMODE_CENTER:
830x -= w / 2.0f;
831y -= h / 2.0f;
832break;
833default:
834break;
835}
836ofGetCurrentRenderer()->getPath().clear();
837ofGetCurrentRenderer()->getPath().rectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
838ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
839
840}
841
842//----------------------------------------------------------
843void ofDrawCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
844ofGetCurrentRenderer()->getPath().clear();
845ofGetCurrentRenderer()->getPath().curveTo(x0,y0);
846ofGetCurrentRenderer()->getPath().curveTo(x1,y1);
847ofGetCurrentRenderer()->getPath().curveTo(x2,y2);
848ofGetCurrentRenderer()->getPath().curveTo(x3,y3);
849ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
850}
851
852//----------------------------------------------------------
853void 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){
854ofGetCurrentRenderer()->getPath().clear();
855ofGetCurrentRenderer()->getPath().curveTo(x0,y0,z0);
856ofGetCurrentRenderer()->getPath().curveTo(x1,y1,z1);
857ofGetCurrentRenderer()->getPath().curveTo(x2,y2,z2);
858ofGetCurrentRenderer()->getPath().curveTo(x3,y3,z3);
859ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
860}
861
862
863//----------------------------------------------------------
864void ofDrawBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
865ofGetCurrentRenderer()->getPath().clear();
866ofGetCurrentRenderer()->getPath().moveTo(x0,y0);
867ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3);
868ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
869}
870
871//----------------------------------------------------------
872void 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){
873ofGetCurrentRenderer()->getPath().clear();
874ofGetCurrentRenderer()->getPath().moveTo(x0,y0,z0);
875ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3);
876ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
877}
878
879//----------------------------------------------------------
880void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
881ofDrawTriangle(p1,p2,p3);
882}
883
884//----------------------------------------------------------
885void ofTriangle(float x1,float y1,float x2,float y2,float x3, float y3){
886ofDrawTriangle(x1, y1, x2, y2, x3, y3);
887}
888
889//----------------------------------------------------------
890void ofTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){
891ofDrawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3);
892}
893
894//----------------------------------------------------------
895void ofCircle(const glm::vec3 & p, float radius){
896ofDrawCircle(p, radius);
897}
898
899//----------------------------------------------------------
900void ofCircle(float x, float y, float radius){
901ofDrawCircle(x,y,radius);
902}
903
904//----------------------------------------------------------
905void ofCircle(float x, float y, float z, float radius){
906ofDrawCircle(x,y,z,radius);
907}
908
909//----------------------------------------------------------
910void ofEllipse(const glm::vec3 & p, float width, float height){
911ofDrawEllipse(p, width, height);
912}
913
914//----------------------------------------------------------
915void ofEllipse(float x, float y, float width, float height){
916ofDrawEllipse(x,y,width,height);
917}
918
919//----------------------------------------------------------
920void ofEllipse(float x, float y, float z, float width, float height){
921ofDrawEllipse(x,y,z,width,height);
922}
923
924//----------------------------------------------------------
925void ofLine(const glm::vec3 & p1, const glm::vec3 & p2){
926ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
927}
928
929//----------------------------------------------------------
930void ofLine(float x1,float y1,float x2,float y2){
931ofDrawLine(x1, y1, x2, y2);
932}
933
934//----------------------------------------------------------
935void ofLine(float x1,float y1,float z1,float x2,float y2,float z2){
936ofDrawLine(x1,y1,z1,x2,y2,z2);
937}
938
939//----------------------------------------------------------
940void ofRect(const ofRectangle & r){
941ofDrawRectangle(r.x,r.y,r.width, r.height);
942}
943
944//----------------------------------------------------------
945void ofRect(const glm::vec3 & p,float w,float h){
946ofDrawRectangle(p, w, h);
947}
948
949//----------------------------------------------------------
950void ofRect(float x,float y,float w,float h){
951ofDrawRectangle(x, y, w, h);
952}
953
954//----------------------------------------------------------
955void ofRect(float x,float y,float z,float w,float h){
956ofDrawRectangle(x,y,z,w,h);
957}
958
959//----------------------------------------------------------
960void ofRectRounded(const ofRectangle & b, float r){
961ofDrawRectRounded(b,r);
962}
963
964//----------------------------------------------------------
965void ofRectRounded(const glm::vec3 & p, float w, float h, float r){
966ofDrawRectRounded(p, w, h, r);
967}
968
969//----------------------------------------------------------
970void ofRectRounded(float x, float y, float w, float h, float r){
971ofDrawRectRounded(x, y, w, h, r);
972}
973
974//----------------------------------------------------------
975void ofRectRounded(float x, float y, float z, float w, float h, float r){
976ofDrawRectRounded(x,y,z,w,h,r,r,r,r);
977}
978
979//----------------------------------------------------------
980void ofRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius,
981float topRightRadius,
982float bottomRightRadius,
983float bottomLeftRadius){
984ofDrawRectRounded(p,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
985}
986
987//----------------------------------------------------------
988void ofRectRounded(const ofRectangle & b, float topLeftRadius,
989float topRightRadius,
990float bottomRightRadius,
991float bottomLeftRadius) {
992
993// if the parameter is an ofRectangle we don't do rectMode
994ofDrawRectRounded(b,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
995}
996
997
998//----------------------------------------------------------
999void ofRectRounded(float x, float y, float z, float w, float h, float topLeftRadius,
1000float topRightRadius,
1001float bottomRightRadius,
1002float bottomLeftRadius) {
1003
1004ofDrawRectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius);
1005
1006}
1007
1008//----------------------------------------------------------
1009void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
1010ofDrawCurve(x0, y0, x1, y1, x2, y2, x3, y3);
1011}
1012
1013//----------------------------------------------------------
1014void 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){
1015ofDrawCurve(x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3);
1016}
1017
1018
1019//----------------------------------------------------------
1020void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){
1021ofDrawBezier(x0,y0,x1,y1,x2,y2,x3,y3);
1022}
1023
1024//----------------------------------------------------------
1025void 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){
1026ofDrawBezier(x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3);
1027}
1028
1029//----------------------------------------------------------
1030void ofBeginShape(){
1031ofGetCurrentRenderer()->getPath().clear();
1032}
1033
1034//----------------------------------------------------------
1035void ofVertex(float x, float y){
1036ofGetCurrentRenderer()->getPath().lineTo(x,y);
1037}
1038
1039//----------------------------------------------------------
1040void ofVertex(float x, float y, float z){
1041ofGetCurrentRenderer()->getPath().lineTo(x,y,z);
1042}
1043
1044//---------------------------------------------------
1045void ofVertex(const glm::vec3 & p){
1046ofGetCurrentRenderer()->getPath().lineTo(p);
1047}
1048
1049//---------------------------------------------------
1050void ofVertex(const glm::vec2 & p){
1051ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0));
1052}
1053
1054//----------------------------------------------------------
1055void ofVertices( const vector <glm::vec3> & polyPoints ){
1056for( const auto & p: polyPoints ){
1057ofGetCurrentRenderer()->getPath().lineTo(p);
1058}
1059}
1060
1061//----------------------------------------------------------
1062void ofVertices( const vector <glm::vec2> & polyPoints ){
1063for( const auto & p: polyPoints ){
1064ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0));
1065}
1066}
1067
1068//----------------------------------------------------------
1069void ofVertices( const vector <ofVec3f> & polyPoints ){
1070for( const auto & p: polyPoints ){
1071ofGetCurrentRenderer()->getPath().lineTo(p);
1072}
1073}
1074
1075//----------------------------------------------------------
1076void ofVertices( const vector <ofVec2f> & polyPoints ){
1077for( const auto & p: polyPoints ){
1078ofGetCurrentRenderer()->getPath().lineTo(p);
1079}
1080}
1081
1082//---------------------------------------------------
1083void ofCurveVertex(float x, float y){
1084ofGetCurrentRenderer()->getPath().curveTo(x,y);
1085}
1086
1087//---------------------------------------------------
1088void ofCurveVertex(float x, float y, float z){
1089ofGetCurrentRenderer()->getPath().curveTo(x,y,z);
1090}
1091
1092//----------------------------------------------------------
1093void ofCurveVertices( const vector <glm::vec3> & curvePoints){
1094for( const auto & p: curvePoints ){
1095ofGetCurrentRenderer()->getPath().curveTo(p);
1096}
1097}
1098
1099//----------------------------------------------------------
1100void ofCurveVertices( const vector <glm::vec2> & curvePoints){
1101for( const auto & p: curvePoints ){
1102ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0));
1103}
1104}
1105
1106//----------------------------------------------------------
1107void ofCurveVertices( const vector <ofVec3f> & curvePoints){
1108for( const auto & p: curvePoints ){
1109ofGetCurrentRenderer()->getPath().curveTo(p);
1110}
1111}
1112
1113//----------------------------------------------------------
1114void ofCurveVertices( const vector <ofVec2f> & curvePoints){
1115for( const auto & p: curvePoints ){
1116ofGetCurrentRenderer()->getPath().curveTo(p);
1117}
1118}
1119
1120//---------------------------------------------------
1121void ofCurveVertex(const glm::vec3 & p){
1122ofGetCurrentRenderer()->getPath().curveTo(p);
1123}
1124
1125//---------------------------------------------------
1126void ofCurveVertex(const glm::vec2 & p){
1127ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0));
1128}
1129
1130//---------------------------------------------------
1131void ofBezierVertex(float x1, float y1, float x2, float y2, float x3, float y3){
1132ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3);
1133}
1134
1135//---------------------------------------------------
1136void ofBezierVertex(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){
1137ofGetCurrentRenderer()->getPath().bezierTo(p1, p2, p3);
1138}
1139
1140//---------------------------------------------------
1141void ofBezierVertex(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){
1142ofGetCurrentRenderer()->getPath().bezierTo(glm::vec3(p1, 0.0), glm::vec3(p2,0.0), glm::vec3(p3,0.0));
1143}
1144
1145//---------------------------------------------------
1146void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){
1147ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3);
1148}
1149
1150//----------------------------------------------------------
1151void ofNextContour(bool bClose){
1152if (bClose){
1153ofGetCurrentRenderer()->getPath().close();
1154}
1155ofGetCurrentRenderer()->getPath().newSubPath();
1156}
1157
1158
1159//----------------------------------------------------------
1160void ofEndShape(bool bClose){
1161
1162// (close -> add the first point to the end)
1163// -----------------------------------------------
1164
1165if (bClose){
1166ofGetCurrentRenderer()->getPath().close();
1167}
1168
1169ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw();
1170
1171}
1172
1173//--------------------------------------------------
1174// text
1175//--------------------------------------------------
1176template<>
1177void ofDrawBitmapString(const string & textString, float x, float y, float z){
1178ofGetCurrentRenderer()->drawString(textString,x,y,z);
1179}
1180
1181template<>
1182void ofDrawBitmapString(const std::string & textString, const glm::vec3 & p){
1183ofGetCurrentRenderer()->drawString(textString, p.x, p.y, p.z);
1184}
1185
1186template<>
1187void ofDrawBitmapString(const std::string & textString, const glm::vec2 & p){
1188ofGetCurrentRenderer()->drawString(textString, p.x, p.y, 0.f);
1189}
1190
1191//--------------------------------------------------
1192void ofDrawBitmapStringHighlight(string text, const glm::vec3& position, const ofColor& background, const ofColor& foreground) {
1193ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground);
1194}
1195
1196//--------------------------------------------------
1197void ofDrawBitmapStringHighlight(string text, const glm::vec2& position, const ofColor& background, const ofColor& foreground) {
1198ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground);
1199}
1200
1201//--------------------------------------------------
1202void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& background, const ofColor& foreground) {
1203vector<string> lines = ofSplitString(text, "\n");
1204int maxLineLength = 0;
1205for(int i = 0; i < (int)lines.size(); i++) {
1206// tabs are not rendered
1207const string & line(lines[i]);
1208int currentLineLength = 0;
1209for(int j = 0; j < (int)line.size(); j++) {
1210if (line[j] == '\t') {
1211currentLineLength += 8 - (currentLineLength % 8);
1212} else {
1213currentLineLength++;
1214}
1215}
1216maxLineLength = std::max(maxLineLength, currentLineLength);
1217}
1218
1219int padding = 4;
1220int fontSize = 8;
1221float leading = 1.7;
1222int height = lines.size() * fontSize * leading - 1;
1223int width = maxLineLength * fontSize;
1224
1225ofPushStyle();
1226glDepthMask(false);
1227ofSetColor(background);
1228ofFill();
1229ofPushMatrix();
1230
1231if(ofGetStyle().drawBitmapMode == OF_BITMAPMODE_MODEL) {
1232ofTranslate(x,y,0);
1233ofScale(1,-1,0);
1234ofTranslate(-(padding), + padding - fontSize - 2,0);
1235} else {
1236ofTranslate(x-(padding), y-(padding + fontSize + 2), 0);
1237
1238}
1239
1240ofDrawRectangle(0, 0, width + 2 * padding, height + 2 * padding);
1241ofPopMatrix();
1242ofSetColor(foreground);
1243ofNoFill();
1244ofDrawBitmapString(text, x, y);
1245glDepthMask(true);
1246ofPopStyle();
1247}
1248
1249
1250// end text
1251//--------------------------------------------------
1252