diff --git a/libs/openFrameworks/app/ofAppNoWindow.cpp b/libs/openFrameworks/app/ofAppNoWindow.cpp index 33fc8caceaa..9e650c858f1 100644 --- a/libs/openFrameworks/app/ofAppNoWindow.cpp +++ b/libs/openFrameworks/app/ofAppNoWindow.cpp @@ -1,277 +1,262 @@ +#include "of3dGraphics.h" #include "ofAppNoWindow.h" #include "ofGraphics.h" #include "ofPath.h" -#include "of3dGraphics.h" #include - #if defined TARGET_OSX || defined TARGET_LINUX -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include struct termios orig_termios; struct sigaction act_open; -void reset_terminal_mode() -{ - tcsetattr(0, TCSANOW, &orig_termios); +void reset_terminal_mode() { + tcsetattr(0, TCSANOW, &orig_termios); } +void set_conio_terminal_mode() { + struct termios new_termios; -void set_conio_terminal_mode() -{ - struct termios new_termios; + /* take two copies - one for now, one for later */ + tcgetattr(0, &orig_termios); + memcpy(&new_termios, &orig_termios, sizeof(new_termios)); - /* take two copies - one for now, one for later */ - tcgetattr(0, &orig_termios); - memcpy(&new_termios, &orig_termios, sizeof(new_termios)); - - /* register cleanup handler, and set the new terminal mode */ - atexit(reset_terminal_mode); + /* register cleanup handler, and set the new terminal mode */ + atexit(reset_terminal_mode); // setup new_termios for raw keyboard input - cfmakeraw(&new_termios); + cfmakeraw(&new_termios); // handle "\n" properly new_termios.c_oflag |= OPOST; //new_termios.c_oflag |= ONLCR; // set the new_termios - tcsetattr(0, TCSANOW, &new_termios); + tcsetattr(0, TCSANOW, &new_termios); } -int kbhit() -{ +int kbhit() { return 0; -// struct timeval tv = { 0L, 0L }; -// fd_set fds; -// FD_SET(0, &fds); -// return select(1, &fds, nullptr, nullptr, &tv); + // struct timeval tv = { 0L, 0L }; + // fd_set fds; + // FD_SET(0, &fds); + // return select(1, &fds, nullptr, nullptr, &tv); } -int getch() -{ - int r; - unsigned char c; - if ((r = read(0, &c, sizeof(c))) < 0) { - return r; - } else { - return c; - } +int getch() { + int r; + unsigned char c; + if ((r = read(0, &c, sizeof(c))) < 0) { + return r; + } else { + return c; + } } #endif -class ofNoopRenderer: public ofBaseRenderer{ +class ofNoopRenderer : public ofBaseRenderer { public: - ofNoopRenderer():graphics3d(this){} + ofNoopRenderer() + : graphics3d(this) { } + private: static const std::string TYPE; - const std::string & getType(){return TYPE;} - - void startRender(){} - void finishRender(){} - void update(){} - - void draw(const ofPolyline & poly) const{} - void draw(const ofPath & shape) const{} - void draw(const of3dPrimitive&, ofPolyRenderMode) const{} - void draw(const ofNode&) const{} - void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const{} - void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{} - void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{} - void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{} - void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{} + const std::string & getType() { return TYPE; } + + void startRender() { } + void finishRender() { } + void update() { } + + void draw(const ofPolyline & poly) const { } + void draw(const ofPath & shape) const { } + void draw(const of3dPrimitive &, ofPolyRenderMode) const { } + void draw(const ofNode &) const { } + void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const { } + void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { } + void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { } + void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { } + void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const { } //-------------------------------------------- // transformations - void pushView(){}; - void popView(){}; + void pushView() {}; + void popView() {}; // setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) - void viewport(ofRectangle viewport){}; - void viewport(float x = 0, float y = 0, float width = 0, float height = 0, bool invertY = true){}; - void setupScreenPerspective(float width = 0, float height = 0, float fov = 60, float nearDist = 0, float farDist = 0){} - void setupScreenOrtho(float width = 0, float height = 0, float nearDist = -1, float farDist = 1){}; - ofRectangle getCurrentViewport() const{return ofRectangle();}; - ofRectangle getNativeViewport() const{return ofRectangle();}; - int getViewportWidth() const{return 0;}; - int getViewportHeight() const{return 0;}; - - void setCoordHandedness(ofHandednessType handedness){}; - ofHandednessType getCoordHandedness() const{return OF_LEFT_HANDED;}; + void viewport(ofRectangle viewport) {}; + void viewport(float x = 0, float y = 0, float width = 0, float height = 0, bool invertY = true) {}; + void setupScreenPerspective(float width = 0, float height = 0, float fov = 60, float nearDist = 0, float farDist = 0) { } + void setupScreenOrtho(float width = 0, float height = 0, float nearDist = -1, float farDist = 1) {}; + ofRectangle getCurrentViewport() const { return ofRectangle(); }; + ofRectangle getNativeViewport() const { return ofRectangle(); }; + int getViewportWidth() const { return 0; }; + int getViewportHeight() const { return 0; }; + + void setCoordHandedness(ofHandednessType handedness) {}; + ofHandednessType getCoordHandedness() const { return OF_LEFT_HANDED; }; //our openGL wrappers - void pushMatrix(){}; - void popMatrix(){}; - void translate(float x, float y, float z = 0){}; - void translate(const glm::vec3 & p){}; - void scale(float xAmnt, float yAmnt, float zAmnt = 1){}; - void rotateRad(float radians, float vecX, float vecY, float vecZ){}; - void rotateXRad(float radians){}; - void rotateYRad(float radians){}; - void rotateZRad(float radians){}; - void rotateRad(float radians){}; + void pushMatrix() {}; + void popMatrix() {}; + void translate(float x, float y, float z = 0) {}; + void translate(const glm::vec3 & p) {}; + void scale(float xAmnt, float yAmnt, float zAmnt = 1) {}; + void rotateRad(float radians, float vecX, float vecY, float vecZ) {}; + void rotateXRad(float radians) {}; + void rotateYRad(float radians) {}; + void rotateZRad(float radians) {}; + void rotateRad(float radians) {}; // screen coordinate things / default gl values - void setupGraphicDefaults(){}; - void setupScreen(){}; - - void setOrientation(ofOrientation, bool){} - bool isVFlipped() const{return true;} - glm::mat4 getCurrentMatrix(ofMatrixMode) const{return glm::mat4(1.0);}; - glm::mat4 getCurrentOrientationMatrix() const{return glm::mat4(1.0);} - void matrixMode(ofMatrixMode){} - void loadIdentityMatrix(){} - void loadMatrix(const glm::mat4&){} - void loadMatrix(const float*){} - void multMatrix(const glm::mat4&){} - void multMatrix(const float*){} - void loadViewMatrix(const glm::mat4&){} - void multViewMatrix(const glm::mat4&){} - glm::mat4 getCurrentViewMatrix() const{return glm::mat4(1.0);} - glm::mat4 getCurrentNormalMatrix() const{return glm::mat4(1.0);} - void enableAntiAliasing(){} - void disableAntiAliasing(){} - + void setupGraphicDefaults() {}; + void setupScreen() {}; + + void setOrientation(ofOrientation, bool) { } + bool isVFlipped() const { return true; } + glm::mat4 getCurrentMatrix(ofMatrixMode) const { return glm::mat4(1.0); }; + glm::mat4 getCurrentOrientationMatrix() const { return glm::mat4(1.0); } + void matrixMode(ofMatrixMode) { } + void loadIdentityMatrix() { } + void loadMatrix(const glm::mat4 &) { } + void loadMatrix(const float *) { } + void multMatrix(const glm::mat4 &) { } + void multMatrix(const float *) { } + void loadViewMatrix(const glm::mat4 &) { } + void multViewMatrix(const glm::mat4 &) { } + glm::mat4 getCurrentViewMatrix() const { return glm::mat4(1.0); } + glm::mat4 getCurrentNormalMatrix() const { return glm::mat4(1.0); } + void enableAntiAliasing() { } + void disableAntiAliasing() { } // drawing modes - void setRectMode(ofRectMode mode){} - ofRectMode getRectMode(){return OF_RECTMODE_CORNER;} - void setFillMode(ofFillFlag fill){} - ofFillFlag getFillMode(){return OF_FILLED;} - void setLineWidth(float lineWidth){} - void setBlendMode(ofBlendMode blendMode){} - void setLineSmoothing(bool smooth){} - void setCircleResolution(int res){}; - void enablePointSprites(){}; - void disablePointSprites(){}; - void setDepthTest(bool){}; + void setRectMode(ofRectMode mode) { } + ofRectMode getRectMode() { return OF_RECTMODE_CORNER; } + void setFillMode(ofFillFlag fill) { } + ofFillFlag getFillMode() { return OF_FILLED; } + void setLineWidth(float lineWidth) { } + void setBlendMode(ofBlendMode blendMode) { } + void setLineSmoothing(bool smooth) { } + void setCircleResolution(int res) {}; + void enablePointSprites() {}; + void disablePointSprites() {}; + void setDepthTest(bool) {}; // color options - void setColor(float r, float g, float b){}; // 0-1 - void setColor(float r, float g, float b, float a){}; // 0-1 - void setColor(const ofFloatColor & color){}; - void setColor(const ofFloatColor & color, float _a){}; - void setColor(float gray){}; // new set a color as grayscale with one argument - void setHexColor( int hexColor ){}; // hex, like web 0xFF0033; + void setColor(float r, float g, float b) {}; // 0-1 + void setColor(float r, float g, float b, float a) {}; // 0-1 + void setColor(const ofFloatColor & color) {}; + void setColor(const ofFloatColor & color, float _a) {}; + void setColor(float gray) {}; // new set a color as grayscale with one argument + void setHexColor(int hexColor) {}; // hex, like web 0xFF0033; // bg color - ofFloatColor getBackgroundColor(){return ofFloatColor(200.f/255.f);} - void setBackgroundColor(const ofFloatColor & color){} - bool getBackgroundAuto(){ + ofFloatColor getBackgroundColor() { return ofFloatColor(200.f / 255.f); } + void setBackgroundColor(const ofFloatColor & color) { } + bool getBackgroundAuto() { return true; } - void background(const ofFloatColor & c){}; - void background(float brightness){}; - void background(int hexColor, int _a=255){}; - void background(float r, float g, float b, float a=1.f){}; + void background(const ofFloatColor & c) {}; + void background(float brightness) {}; + void background(int hexColor, int _a = 255) {}; + void background(float r, float g, float b, float a = 1.f) {}; - void setBackgroundAuto(bool bManual){}; // default is true + void setBackgroundAuto(bool bManual) {}; // default is true - void clear(){}; - void clear(float r, float g, float b, float a=0){}; - void clear(float brightness, float a=0){}; - void clearAlpha(){}; + void clear() {}; + void clear(float r, float g, float b, float a = 0) {}; + void clear(float brightness, float a = 0) {}; + void clearAlpha() {}; // drawing - void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{} - void drawRectangle(float x, float y, float z, float w, float h) const{} - void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{} - void drawCircle(float x, float y, float z, float radius) const{} - void drawSphere(float x, float y, float z, float radius) const{} - void drawEllipse(float x, float y, float z, float width, float height) const{} - void drawString(std::string text, float x, float y, float z) const{} - void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const{} - - void setBitmapTextMode(ofDrawBitmapMode mode){} - ofStyle getStyle() const{ return ofStyle(); } - void pushStyle(){} - void popStyle(){} - void setStyle(const ofStyle & style){} - void setCurveResolution(int res){} - void setPolyMode(ofPolyWindingMode){} - - void bind(const ofCamera & camera, const ofRectangle & viewport){}; - void unbind(const ofCamera & camera){}; - ofPath & getPath(){ return path; } - const of3dGraphics & get3dGraphics() const{ + void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const { } + void drawRectangle(float x, float y, float z, float w, float h) const { } + void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const { } + void drawCircle(float x, float y, float z, float radius) const { } + void drawSphere(float x, float y, float z, float radius) const { } + void drawEllipse(float x, float y, float z, float width, float height) const { } + void drawString(std::string text, float x, float y, float z) const { } + void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const { } + + void setBitmapTextMode(ofBitmapMode mode) { } + ofStyle getStyle() const { return ofStyle(); } + void pushStyle() { } + void popStyle() { } + void setStyle(const ofStyle & style) { } + void setCurveResolution(int res) { } + void setPolyMode(ofPolyWindingMode) { } + + void bind(const ofCamera & camera, const ofRectangle & viewport) {}; + void unbind(const ofCamera & camera) {}; + ofPath & getPath() { return path; } + const of3dGraphics & get3dGraphics() const { return graphics3d; } - of3dGraphics & get3dGraphics(){ + of3dGraphics & get3dGraphics() { return graphics3d; } of3dGraphics graphics3d; ofPath path; }; - -const std::string ofNoopRenderer::TYPE="NOOP"; +const std::string ofNoopRenderer::TYPE = "NOOP"; //---------------------------------------------------------- ofAppNoWindow::ofAppNoWindow() -:coreEvents(new ofCoreEvents) -,currentRenderer(new ofNoopRenderer){ + : coreEvents(new ofCoreEvents) + , currentRenderer(new ofNoopRenderer) { ofAppPtr = nullptr; width = 0; height = 0; } - //---------------------------------------------------------- -void ofAppNoWindow::setup(const ofWindowSettings & settings){ +void ofAppNoWindow::setup(const ofWindowSettings & settings) { width = settings.getWidth(); height = settings.getHeight(); } //---------------------------------------------------------- -void ofAppNoWindow::update(){ +void ofAppNoWindow::update() { - /// listen for escape - #ifdef TARGET_WIN32 - if (GetAsyncKeyState(VK_ESCAPE)) - events().notifyKeyPressed(OF_KEY_ESC); - #endif +/// listen for escape +#ifdef TARGET_WIN32 + if (GetAsyncKeyState(VK_ESCAPE)) + events().notifyKeyPressed(OF_KEY_ESC); +#endif - #if defined TARGET_OSX || defined TARGET_LINUX - while ( kbhit() ) - { +#if defined TARGET_OSX || defined TARGET_LINUX + while (kbhit()) { int key = getch(); - if ( key == 27 ) - { + if (key == 27) { events().notifyKeyPressed(OF_KEY_ESC); - } - else if ( key == /* ctrl-c */ 3 ) - { + } else if (key == /* ctrl-c */ 3) { ofLogNotice("ofAppNoWindow") << "Ctrl-C pressed" << std::endl; break; - } - else - { + } else { events().notifyKeyPressed(key); } } - #endif - +#endif events().notifyUpdate(); } //---------------------------------------------------------- -void ofAppNoWindow::draw(){ +void ofAppNoWindow::draw() { events().notifyDraw(); } //------------------------------------------------------------ -void ofAppNoWindow::exitApp(){ +void ofAppNoWindow::exitApp() { ofLogVerbose("ofAppNoWindow") << "terminating headless (no window) app!"; - #if defined TARGET_OSX || defined TARGET_LINUX - // this doesn't exist on windows and gives linking errors, so commented out. + // this doesn't exist on windows and gives linking errors, so commented out. reset_terminal_mode(); #endif @@ -279,38 +264,35 @@ void ofAppNoWindow::exitApp(){ } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getWindowPosition(){ - return {0.f, 0.f}; +glm::vec2 ofAppNoWindow::getWindowPosition() { + return { 0.f, 0.f }; } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getWindowSize(){ - return {width, height}; +glm::vec2 ofAppNoWindow::getWindowSize() { + return { width, height }; } //---------------------------------------------------------- -glm::vec2 ofAppNoWindow::getScreenSize(){ - return {width, height}; +glm::vec2 ofAppNoWindow::getScreenSize() { + return { width, height }; } - //---------------------------------------------------------- -int ofAppNoWindow::getWidth(){ +int ofAppNoWindow::getWidth() { return width; } //---------------------------------------------------------- -int ofAppNoWindow::getHeight(){ +int ofAppNoWindow::getHeight() { return height; } - //---------------------------------------------------------- -ofCoreEvents & ofAppNoWindow::events(){ +ofCoreEvents & ofAppNoWindow::events() { return *coreEvents; } -std::shared_ptr & ofAppNoWindow::renderer(){ +std::shared_ptr & ofAppNoWindow::renderer() { return currentRenderer; } - diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp index 89bec4f4b7b..b497662ced4 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp @@ -1,49 +1,46 @@ -#include "ofGLProgrammableRenderer.h" -#include "ofMesh.h" -#include "ofPath.h" +#include "of3dPrimitives.h" #include "ofBitmapFont.h" +#include "ofCamera.h" +#include "ofFbo.h" +#include "ofGLProgrammableRenderer.h" #include "ofGLUtils.h" #include "ofImage.h" -#include "ofFbo.h" -#include "ofVboMesh.h" -#include "of3dPrimitives.h" #include "ofLight.h" #include "ofMaterialBaseTypes.h" -#include "ofCamera.h" -#include "ofTrueTypeFont.h" +#include "ofMesh.h" #include "ofNode.h" +#include "ofPath.h" +#include "ofTrueTypeFont.h" +#include "ofVboMesh.h" #include "ofVideoBaseTypes.h" -using std::vector; using std::string; using std::swap; +using std::vector; -static const string MODEL_MATRIX_UNIFORM="modelMatrix"; -static const string VIEW_MATRIX_UNIFORM="viewMatrix"; -static const string MODELVIEW_MATRIX_UNIFORM="modelViewMatrix"; -static const string PROJECTION_MATRIX_UNIFORM="projectionMatrix"; -static const string MODELVIEW_PROJECTION_MATRIX_UNIFORM="modelViewProjectionMatrix"; -static const string TEXTURE_MATRIX_UNIFORM="textureMatrix"; -static const string COLOR_UNIFORM="globalColor"; - -static const string USE_TEXTURE_UNIFORM="usingTexture"; -static const string USE_COLORS_UNIFORM="usingColors"; -static const string BITMAP_STRING_UNIFORM="bitmapText"; +static const string MODEL_MATRIX_UNIFORM = "modelMatrix"; +static const string VIEW_MATRIX_UNIFORM = "viewMatrix"; +static const string MODELVIEW_MATRIX_UNIFORM = "modelViewMatrix"; +static const string PROJECTION_MATRIX_UNIFORM = "projectionMatrix"; +static const string MODELVIEW_PROJECTION_MATRIX_UNIFORM = "modelViewProjectionMatrix"; +static const string TEXTURE_MATRIX_UNIFORM = "textureMatrix"; +static const string COLOR_UNIFORM = "globalColor"; +static const string USE_TEXTURE_UNIFORM = "usingTexture"; +static const string USE_COLORS_UNIFORM = "usingColors"; +static const string BITMAP_STRING_UNIFORM = "bitmapText"; -const string ofGLProgrammableRenderer::TYPE="ProgrammableGL"; +const string ofGLProgrammableRenderer::TYPE = "ProgrammableGL"; static bool programmableRendererCreated = false; -bool ofIsGLProgrammableRenderer(){ +bool ofIsGLProgrammableRenderer() { return programmableRendererCreated; } - //---------------------------------------------------------- ofGLProgrammableRenderer::ofGLProgrammableRenderer(const ofAppBaseWindow * _window) -:matrixStack(_window) -,graphics3d(this) -{ + : matrixStack(_window) + , graphics3d(this) { programmableRendererCreated = true; bBackgroundAuto = true; @@ -53,10 +50,10 @@ ofGLProgrammableRenderer::ofGLProgrammableRenderer(const ofAppBaseWindow * _wind rectMesh.getVertices().resize(4); bitmapStringEnabled = false; - verticesEnabled = true; - colorsEnabled = false; - texCoordsEnabled = false; - normalsEnabled = false; + verticesEnabled = true; + colorsEnabled = false; + texCoordsEnabled = false; + normalsEnabled = false; settingDefaultShader = false; usingVideoShader = false; usingCustomShader = false; @@ -70,7 +67,7 @@ ofGLProgrammableRenderer::ofGLProgrammableRenderer(const ofAppBaseWindow * _wind currentTextureTarget = OF_NO_TEXTURE; currentMaterial = nullptr; alphaMaskTextureTarget = OF_NO_TEXTURE; - + currentShadow = nullptr; bIsShadowDepthPass = false; @@ -81,8 +78,8 @@ ofGLProgrammableRenderer::ofGLProgrammableRenderer(const ofAppBaseWindow * _wind currentFramebufferId = 0; defaultFramebufferId = 0; path.setMode(ofPath::POLYLINES); - path.setUseShapeColor(false); - currentEyePos = {0.f,0.f,0.f}; + path.setUseShapeColor(false); + currentEyePos = { 0.f, 0.f, 0.f }; } //---------------------------------------------------------- @@ -92,16 +89,16 @@ void ofGLProgrammableRenderer::startRender() { matrixStack.setRenderSurface(*window); beginDefaultShader(); viewport(); - // to do non auto clear on PC for now - we do something like "single" buffering -- - // it's not that pretty but it work for the most part + // to do non auto clear on PC for now - we do something like "single" buffering -- + // it's not that pretty but it work for the most part - #ifdef TARGET_WIN32 - if (getBackgroundAuto() == false){ - glDrawBuffer (GL_FRONT); - } - #endif +#ifdef TARGET_WIN32 + if (getBackgroundAuto() == false) { + glDrawBuffer(GL_FRONT); + } +#endif - if ( getBackgroundAuto() ){// || ofGetFrameNum() < 3){ + if (getBackgroundAuto()) { // || ofGetFrameNum() < 3){ background(currentStyle.bgColor); } } @@ -110,58 +107,56 @@ void ofGLProgrammableRenderer::startRender() { void ofGLProgrammableRenderer::finishRender() { if (!uniqueShader) { glUseProgram(0); - if(!usingCustomShader) currentShader = nullptr; + if (!usingCustomShader) currentShader = nullptr; } matrixStack.clearStacks(); framebufferIdStack.clear(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const{ +void ofGLProgrammableRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const { if (vertexData.getVertices().empty()) return; - - - // tig: note that for GL3+ we use glPolygonMode to draw wireframes or filled meshes, and not the primitive mode. - // the reason is not purely aesthetic, but more conformant with the behaviour of ofGLRenderer. Whereas - // gles2.0 doesn't allow for a polygonmode. - // Also gles2 still supports vertex array syntax for uploading data to attributes and it seems to be faster than - // vbo's for meshes that are updated frequently so let's use that instead - - //if (bSmoothHinted) startSmoothing(); + + // tig: note that for GL3+ we use glPolygonMode to draw wireframes or filled meshes, and not the primitive mode. + // the reason is not purely aesthetic, but more conformant with the behaviour of ofGLRenderer. Whereas + // gles2.0 doesn't allow for a polygonmode. + // Also gles2 still supports vertex array syntax for uploading data to attributes and it seems to be faster than + // vbo's for meshes that are updated frequently so let's use that instead + + //if (bSmoothHinted) startSmoothing(); #if defined(TARGET_OPENGLES) && !defined(TARGET_EMSCRIPTEN) glEnableVertexAttribArray(ofShader::POSITION_ATTRIBUTE); glVertexAttribPointer(ofShader::POSITION_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, sizeof(typename ofMesh::VertexType), vertexData.getVerticesPointer()); - - useNormals &= (vertexData.getNumNormals()>0); - if(useNormals){ + + useNormals &= (vertexData.getNumNormals() > 0); + if (useNormals) { glEnableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE); glVertexAttribPointer(ofShader::NORMAL_ATTRIBUTE, 3, GL_FLOAT, GL_TRUE, sizeof(typename ofMesh::NormalType), vertexData.getNormalsPointer()); - }else{ + } else { glDisableVertexAttribArray(ofShader::NORMAL_ATTRIBUTE); } - - useColors &= (vertexData.getNumColors()>0); - if(useColors){ + + useColors &= (vertexData.getNumColors() > 0); + if (useColors) { glEnableVertexAttribArray(ofShader::COLOR_ATTRIBUTE); - glVertexAttribPointer(ofShader::COLOR_ATTRIBUTE, 4,GL_FLOAT, GL_FALSE, sizeof(ofFloatColor), vertexData.getColorsPointer()); - }else{ + glVertexAttribPointer(ofShader::COLOR_ATTRIBUTE, 4, GL_FLOAT, GL_FALSE, sizeof(ofFloatColor), vertexData.getColorsPointer()); + } else { glDisableVertexAttribArray(ofShader::COLOR_ATTRIBUTE); } - useTextures &= (vertexData.getNumTexCoords()>0); - if(useTextures){ + useTextures &= (vertexData.getNumTexCoords() > 0); + if (useTextures) { glEnableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE); - glVertexAttribPointer(ofShader::TEXCOORD_ATTRIBUTE,2, GL_FLOAT, GL_FALSE, sizeof(typename ofMesh::TexCoordType), vertexData.getTexCoordsPointer()); - }else{ + glVertexAttribPointer(ofShader::TEXCOORD_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, sizeof(typename ofMesh::TexCoordType), vertexData.getTexCoordsPointer()); + } else { glDisableVertexAttribArray(ofShader::TEXCOORD_ATTRIBUTE); } - - const_cast(this)->setAttributes(true,useColors,useTextures,useNormals); + const_cast(this)->setAttributes(true, useColors, useTextures, useNormals); GLenum drawMode; - switch(renderType){ + switch (renderType) { case OF_MESH_POINTS: drawMode = GL_POINTS; break; @@ -176,22 +171,21 @@ void ofGLProgrammableRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode break; } - if(vertexData.getNumIndices()){ - glDrawElements(drawMode, vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer()); - }else{ + if (vertexData.getNumIndices()) { + glDrawElements(drawMode, vertexData.getNumIndices(), GL_UNSIGNED_SHORT, vertexData.getIndexPointer()); + } else { glDrawArrays(drawMode, 0, vertexData.getNumVertices()); } #else - -#ifndef TARGET_OPENGLES + #ifndef TARGET_OPENGLES meshVbo.setMesh(vertexData, GL_STREAM_DRAW, useColors, useTextures, useNormals); glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); GLenum drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); -#else + #else meshVbo.setMesh(vertexData, GL_STATIC_DRAW, useColors, useTextures, useNormals); GLenum drawMode; - switch(renderType){ + switch (renderType) { case OF_MESH_POINTS: drawMode = GL_POINTS; break; @@ -205,50 +199,50 @@ void ofGLProgrammableRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); break; } -#endif - if(meshVbo.getUsingIndices()) { - drawElements(meshVbo,drawMode, meshVbo.getNumIndices()); + #endif + if (meshVbo.getUsingIndices()) { + drawElements(meshVbo, drawMode, meshVbo.getNumIndices()); } else { draw(meshVbo, drawMode, 0, vertexData.getNumVertices()); } - + // tig: note further that we could glGet() and store the current polygon mode, but don't, since that would // infer a massive performance hit. instead, we revert the glPolygonMode to mirror the current ofFill state // after we're finished drawing, following the principle of least surprise. // ideally the glPolygonMode (or the polygon draw mode) should be part of ofStyle so that we can keep track // of its state on the client side... -#ifndef TARGET_OPENGLES - glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); -#endif - + #ifndef TARGET_OPENGLES + glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); + #endif + #endif - + //if (bSmoothHinted) endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const{ - drawInstanced(mesh,renderType,1); +void ofGLProgrammableRenderer::draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const { + drawInstanced(mesh, renderType, 1); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const{ - if(mesh.getNumVertices()==0) return; +void ofGLProgrammableRenderer::drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const { + if (mesh.getNumVertices() == 0) return; GLuint mode = ofGetGLPrimitiveMode(mesh.getMode()); #ifndef TARGET_OPENGLES glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); - if(mesh.getNumIndices() && renderType!=OF_MESH_POINTS){ + if (mesh.getNumIndices() && renderType != OF_MESH_POINTS) { if (primCount <= 1) { - drawElements(mesh.getVbo(),mode,mesh.getNumIndices()); + drawElements(mesh.getVbo(), mode, mesh.getNumIndices()); } else { - drawElementsInstanced(mesh.getVbo(),mode,mesh.getNumIndices(),primCount); + drawElementsInstanced(mesh.getVbo(), mode, mesh.getNumIndices(), primCount); } - }else{ + } else { if (primCount <= 1) { - draw(mesh.getVbo(),mode,0,mesh.getNumVertices()); + draw(mesh.getVbo(), mode, 0, mesh.getNumVertices()); } else { - drawInstanced(mesh.getVbo(),mode,0,mesh.getNumVertices(),primCount); + drawInstanced(mesh.getVbo(), mode, 0, mesh.getNumVertices(), primCount); } } @@ -258,68 +252,68 @@ void ofGLProgrammableRenderer::drawInstanced(const ofVboMesh & mesh, ofPolyRende // ideally the glPolygonMode (or the polygon draw mode) should be part of ofStyle so that we can keep track // of its state on the client side... - glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); + glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); #else - if(renderType == OF_MESH_POINTS){ - draw(mesh.getVbo(),GL_POINTS,0,mesh.getNumVertices()); - }else if(renderType == OF_MESH_WIREFRAME){ - if(mesh.getNumIndices()){ - drawElements(mesh.getVbo(),GL_LINES,mesh.getNumIndices()); - }else{ - draw(mesh.getVbo(),GL_LINES,0,mesh.getNumVertices()); + if (renderType == OF_MESH_POINTS) { + draw(mesh.getVbo(), GL_POINTS, 0, mesh.getNumVertices()); + } else if (renderType == OF_MESH_WIREFRAME) { + if (mesh.getNumIndices()) { + drawElements(mesh.getVbo(), GL_LINES, mesh.getNumIndices()); + } else { + draw(mesh.getVbo(), GL_LINES, 0, mesh.getNumVertices()); } - }else{ - if(mesh.getNumIndices()){ - drawElements(mesh.getVbo(),mode,mesh.getNumIndices()); - }else{ - draw(mesh.getVbo(),mode,0,mesh.getNumVertices()); + } else { + if (mesh.getNumIndices()) { + drawElements(mesh.getVbo(), mode, mesh.getNumIndices()); + } else { + draw(mesh.getVbo(), mode, 0, mesh.getNumVertices()); } } #endif } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw( const of3dPrimitive& model, ofPolyRenderMode renderType) const { - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); - if(model.isUsingVbo()){ - draw(static_cast(model.getMesh()),renderType); - }else{ - draw(model.getMesh(),renderType); +void ofGLProgrammableRenderer::draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const { + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); + if (model.isUsingVbo()) { + draw(static_cast(model.getMesh()), renderType); + } else { + draw(model.getMesh(), renderType); } - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofNode& node) const{ - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); +void ofGLProgrammableRenderer::draw(const ofNode & node) const { + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); node.customDraw(this); - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofPolyline & poly) const{ - if(poly.getVertices().empty()) return; +void ofGLProgrammableRenderer::draw(const ofPolyline & poly) const { + if (poly.getVertices().empty()) return; - // use smoothness, if requested: - //if (bSmoothHinted) startSmoothing(); + // use smoothness, if requested: + //if (bSmoothHinted) startSmoothing(); -#if defined( TARGET_OPENGLES ) && !defined(TARGET_EMSCRIPTEN) +#if defined(TARGET_OPENGLES) && !defined(TARGET_EMSCRIPTEN) glEnableVertexAttribArray(ofShader::POSITION_ATTRIBUTE); glVertexAttribPointer(ofShader::POSITION_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, sizeof(typename ofPolyline::VertexType), &poly[0]); - const_cast(this)->setAttributes(true,false,false,false); + const_cast(this)->setAttributes(true, false, false, false); - GLenum drawMode = poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP; + GLenum drawMode = poly.isClosed() ? GL_LINE_LOOP : GL_LINE_STRIP; glDrawArrays(drawMode, 0, poly.size()); #else meshVbo.setVertexData(&poly.getVertices()[0], poly.size(), GL_DYNAMIC_DRAW); - meshVbo.draw(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size()); + meshVbo.draw(poly.isClosed() ? GL_LINE_LOOP : GL_LINE_STRIP, 0, poly.size()); #endif // use smoothness, if requested: @@ -327,44 +321,44 @@ void ofGLProgrammableRenderer::draw(const ofPolyline & poly) const{ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofPath & shape) const{ +void ofGLProgrammableRenderer::draw(const ofPath & shape) const { ofFloatColor prevColor; - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { prevColor = currentStyle.color; } - ofGLProgrammableRenderer * mut_this = const_cast(this); - if(shape.isFilled()){ + ofGLProgrammableRenderer * mut_this = const_cast(this); + if (shape.isFilled()) { const ofMesh & mesh = shape.getTessellation(); - if(shape.getUseShapeColor()){ - mut_this->setColor( shape.getFillColor(),shape.getFillColor().a); + if (shape.getUseShapeColor()) { + mut_this->setColor(shape.getFillColor(), shape.getFillColor().a); } - draw(mesh,OF_MESH_FILL); + draw(mesh, OF_MESH_FILL); } - if(shape.hasOutline()){ + if (shape.hasOutline()) { float lineWidth = currentStyle.lineWidth; - if(shape.getUseShapeColor()){ - mut_this->setColor( shape.getStrokeColor(), shape.getStrokeColor().a); + if (shape.getUseShapeColor()) { + mut_this->setColor(shape.getStrokeColor(), shape.getStrokeColor().a); } - mut_this->setLineWidth( shape.getStrokeWidth() ); + mut_this->setLineWidth(shape.getStrokeWidth()); const vector & outlines = shape.getOutline(); - for(int i=0; i<(int)outlines.size(); i++) + for (int i = 0; i < (int)outlines.size(); i++) draw(outlines[i]); mut_this->setLineWidth(lineWidth); } - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { mut_this->setColor(prevColor); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const_cast(this)->setAttributes(true,false,true,false); - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLProgrammableRenderer::draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const_cast(this)->setAttributes(true, false, true, false); + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLProgrammableRenderer") << "draw(): texture is not allocated"; } @@ -372,14 +366,14 @@ void ofGLProgrammableRenderer::draw(const ofImage & image, float x, float y, flo } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const_cast(this)->setAttributes(true,false,true,false); - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLProgrammableRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const_cast(this)->setAttributes(true, false, true, false); + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLProgrammableRenderer") << "draw(): texture is not allocated"; } @@ -387,14 +381,14 @@ void ofGLProgrammableRenderer::draw(const ofFloatImage & image, float x, float y } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const_cast(this)->setAttributes(true,false,true,false); - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLProgrammableRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const_cast(this)->setAttributes(true, false, true, false); + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLProgrammableRenderer") << "draw(): texture is not allocated"; } @@ -402,56 +396,56 @@ void ofGLProgrammableRenderer::draw(const ofShortImage & image, float x, float y } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofTexture & tex, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - const_cast(this)->setAttributes(true,false,true,false); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLProgrammableRenderer::draw(const ofTexture & tex, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + const_cast(this)->setAttributes(true, false, true, false); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLProgrammableRenderer") << "draw(): texture is not allocated"; } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{ - if(!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()){ +void ofGLProgrammableRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const { + if (!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()) { return; } - const_cast(this)->bind(video); - draw(video.getTexture().getMeshForSubsection(x,y,0,w,h,0,0,video.getWidth(),video.getHeight(),isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(video); + const_cast(this)->bind(video); + draw(video.getTexture().getMeshForSubsection(x, y, 0, w, h, 0, 0, video.getWidth(), video.getHeight(), isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(video); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const{ - if(vbo.getUsingVerts()) { +void ofGLProgrammableRenderer::draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const { + if (vbo.getUsingVerts()) { vbo.bind(); - const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); + const_cast(this)->setAttributes(vbo.getUsingVerts(), vbo.getUsingColors(), vbo.getUsingTexCoords(), vbo.getUsingNormals()); glDrawArrays(drawMode, first, total); vbo.unbind(); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements) const{ - if(vbo.getUsingVerts()) { +void ofGLProgrammableRenderer::drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements) const { + if (vbo.getUsingVerts()) { vbo.bind(); - const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); + const_cast(this)->setAttributes(vbo.getUsingVerts(), vbo.getUsingColors(), vbo.getUsingTexCoords(), vbo.getUsingNormals()); #ifdef TARGET_OPENGLES - glDrawElements(drawMode, amt, GL_UNSIGNED_SHORT, (void*)(sizeof(ofIndexType) * offsetelements)); + glDrawElements(drawMode, amt, GL_UNSIGNED_SHORT, (void *)(sizeof(ofIndexType) * offsetelements)); #else - glDrawElements(drawMode, amt, GL_UNSIGNED_INT, (void*)(sizeof(ofIndexType) * offsetelements)); + glDrawElements(drawMode, amt, GL_UNSIGNED_INT, (void *)(sizeof(ofIndexType) * offsetelements)); #endif vbo.unbind(); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const{ - if(vbo.getUsingVerts()) { +void ofGLProgrammableRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const { + if (vbo.getUsingVerts()) { vbo.bind(); - const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); + const_cast(this)->setAttributes(vbo.getUsingVerts(), vbo.getUsingColors(), vbo.getUsingTexCoords(), vbo.getUsingNormals()); #ifdef TARGET_OPENGLES // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 // unfortunately there is currently no easy way within oF to query the current OpenGL version. @@ -466,57 +460,57 @@ void ofGLProgrammableRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const{ - if(vbo.getUsingVerts()) { +void ofGLProgrammableRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const { + if (vbo.getUsingVerts()) { vbo.bind(); - const_cast(this)->setAttributes(vbo.getUsingVerts(),vbo.getUsingColors(),vbo.getUsingTexCoords(),vbo.getUsingNormals()); + const_cast(this)->setAttributes(vbo.getUsingVerts(), vbo.getUsingColors(), vbo.getUsingTexCoords(), vbo.getUsingNormals()); #ifdef TARGET_OPENGLES - // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 - // unfortunately there is currently no easy way within oF to query the current OpenGL version. - // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml - ofLogWarning("ofVbo") << "drawElementsInstanced(): hardware instancing is not supported on OpenGL ES < 3.0"; - // glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_SHORT, nullptr, primCount); + // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 + // unfortunately there is currently no easy way within oF to query the current OpenGL version. + // https://www.khronos.org/opengles/sdk/docs/man3/xhtml/glDrawElementsInstanced.xml + ofLogWarning("ofVbo") << "drawElementsInstanced(): hardware instancing is not supported on OpenGL ES < 3.0"; + // glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_SHORT, nullptr, primCount); #else - glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_INT, nullptr, primCount); + glDrawElementsInstanced(drawMode, amt, GL_UNSIGNED_INT, nullptr, primCount); #endif vbo.unbind(); } } //---------------------------------------------------------- -ofPath & ofGLProgrammableRenderer::getPath(){ +ofPath & ofGLProgrammableRenderer::getPath() { return path; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofBaseVideoDraws & video){ - if(!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()){ +void ofGLProgrammableRenderer::bind(const ofBaseVideoDraws & video) { + if (!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()) { return; } const ofShader * shader = nullptr; - if(!usingCustomShader){ + if (!usingCustomShader) { shader = getVideoShader(video); - if(shader){ + if (shader) { bind(*shader); - setVideoShaderUniforms(video,*shader); + setVideoShaderUniforms(video, *shader); usingVideoShader = true; } } - if(!usingVideoShader){ - bind(video.getTexture(),0); + if (!usingVideoShader) { + bind(video.getTexture(), 0); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofBaseVideoDraws & video){ - if(!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()){ +void ofGLProgrammableRenderer::unbind(const ofBaseVideoDraws & video) { + if (!video.isInitialized() || !video.isUsingTexture() || video.getTexturePlanes().empty()) { return; } - if(usingVideoShader){ + if (usingVideoShader) { unbind(*currentShader); - }else{ - unbind(video.getTexture(),0); + } else { + unbind(video.getTexture(), 0); } usingVideoShader = false; } @@ -534,39 +528,39 @@ void ofGLProgrammableRenderer::popView() { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::viewport(ofRectangle viewport_){ - viewport(viewport_.x,viewport_.y,viewport_.width,viewport_.height,isVFlipped()); +void ofGLProgrammableRenderer::viewport(ofRectangle viewport_) { + viewport(viewport_.x, viewport_.y, viewport_.width, viewport_.height, isVFlipped()); } //---------------------------------------------------------- void ofGLProgrammableRenderer::viewport(float x, float y, float width, float height, bool vflip) { - matrixStack.viewport(x,y,width,height,vflip); + matrixStack.viewport(x, y, width, height, vflip); ofRectangle nativeViewport = matrixStack.getNativeViewport(); - glViewport(nativeViewport.x,nativeViewport.y,nativeViewport.width,nativeViewport.height); + glViewport(nativeViewport.x, nativeViewport.y, nativeViewport.width, nativeViewport.height); } //---------------------------------------------------------- -ofRectangle ofGLProgrammableRenderer::getCurrentViewport() const{ +ofRectangle ofGLProgrammableRenderer::getCurrentViewport() const { return matrixStack.getCurrentViewport(); } //---------------------------------------------------------- -ofRectangle ofGLProgrammableRenderer::getNativeViewport() const{ - return matrixStack.getNativeViewport(); +ofRectangle ofGLProgrammableRenderer::getNativeViewport() const { + return matrixStack.getNativeViewport(); } //---------------------------------------------------------- -int ofGLProgrammableRenderer::getViewportWidth() const{ +int ofGLProgrammableRenderer::getViewportWidth() const { return getCurrentViewport().width; } //---------------------------------------------------------- -int ofGLProgrammableRenderer::getViewportHeight() const{ +int ofGLProgrammableRenderer::getViewportHeight() const { return getCurrentViewport().height; } //---------------------------------------------------------- -bool ofGLProgrammableRenderer::isVFlipped() const{ +bool ofGLProgrammableRenderer::isVFlipped() const { return matrixStack.isVFlipped(); } @@ -576,26 +570,25 @@ void ofGLProgrammableRenderer::setCoordHandedness(ofHandednessType handedness) { } //---------------------------------------------------------- -ofHandednessType ofGLProgrammableRenderer::getCoordHandedness() const{ +ofHandednessType ofGLProgrammableRenderer::getCoordHandedness() const { return matrixStack.getHandedness(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setOrientation(ofOrientation orientation, bool vFlip){ - matrixStack.setOrientation(orientation,vFlip); +void ofGLProgrammableRenderer::setOrientation(ofOrientation orientation, bool vFlip) { + matrixStack.setOrientation(orientation, vFlip); uploadMatrices(); - } //---------------------------------------------------------- void ofGLProgrammableRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { float viewW, viewH; - if(width<0 || height<0){ + if (width < 0 || height < 0) { ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; - }else{ + } else { viewW = width; viewH = height; } @@ -605,33 +598,31 @@ void ofGLProgrammableRenderer::setupScreenPerspective(float width, float height, float halfFov = glm::pi() * fov / 360.0f; float theTan = tanf(halfFov); float dist = eyeY / theTan; - float aspect = (float) viewW / viewH; - - if(nearDist == 0) nearDist = dist / 10.0f; - if(farDist == 0) farDist = dist * 10.0f; + float aspect = (float)viewW / viewH; + if (nearDist == 0) nearDist = dist / 10.0f; + if (farDist == 0) farDist = dist * 10.0f; matrixMode(OF_MATRIX_PROJECTION); auto persp = glm::perspective(ofDegToRad(fov), aspect, nearDist, farDist); - loadMatrix( persp ); + loadMatrix(persp); matrixMode(OF_MATRIX_MODELVIEW); - auto lookAt = glm::lookAt( glm::vec3{eyeX, eyeY, dist}, glm::vec3{eyeX, eyeY, 0.f}, glm::vec3{0.f, 1.f, 0.f} ); + auto lookAt = glm::lookAt(glm::vec3 { eyeX, eyeY, dist }, glm::vec3 { eyeX, eyeY, 0.f }, glm::vec3 { 0.f, 1.f, 0.f }); loadViewMatrix(lookAt); - - currentEyePos = glm::vec3{eyeX, eyeY, dist}; - + + currentEyePos = glm::vec3 { eyeX, eyeY, dist }; } //---------------------------------------------------------- void ofGLProgrammableRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist) { float viewW, viewH; - if(width<0 || height<0){ + if (width < 0 || height < 0) { ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; - }else{ + } else { viewW = width; viewH = height; } @@ -643,154 +634,154 @@ void ofGLProgrammableRenderer::setupScreenOrtho(float width, float height, float matrixMode(OF_MATRIX_MODELVIEW); loadViewMatrix(glm::mat4(1.0)); - - currentEyePos = glm::vec3{viewW/2.0f, viewH/2.0f, nearDist }; + + currentEyePos = glm::vec3 { viewW / 2.0f, viewH / 2.0f, nearDist }; } //---------------------------------------------------------- //Resets openGL parameters back to OF defaults -void ofGLProgrammableRenderer::setupGraphicDefaults(){ +void ofGLProgrammableRenderer::setupGraphicDefaults() { setStyle(ofStyle()); path.setMode(ofPath::POLYLINES); path.setUseShapeColor(false); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setupScreen(){ +void ofGLProgrammableRenderer::setupScreen() { beginDefaultShader(); - setupScreenPerspective(); // assume defaults + setupScreenPerspective(); // assume defaults } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setCircleResolution(int res){ - if((int)circlePolyline.size()!=res+1){ +void ofGLProgrammableRenderer::setCircleResolution(int res) { + if ((int)circlePolyline.size() != res + 1) { circlePolyline.clear(); - circlePolyline.arc(0,0,0,1,1,0,360,res); + circlePolyline.arc(0, 0, 0, 1, 1, 0, 360, res); circleMesh.getVertices() = circlePolyline.getVertices(); path.setCircleResolution(res); } - currentStyle.circleResolution = res; + currentStyle.circleResolution = res; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setPolyMode(ofPolyWindingMode mode){ +void ofGLProgrammableRenderer::setPolyMode(ofPolyWindingMode mode) { currentStyle.polyMode = mode; path.setPolyWindingMode(mode); } //our openGL wrappers //---------------------------------------------------------- -void ofGLProgrammableRenderer::pushMatrix(){ +void ofGLProgrammableRenderer::pushMatrix() { matrixStack.pushMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::popMatrix(){ +void ofGLProgrammableRenderer::popMatrix() { matrixStack.popMatrix(); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::translate(const glm::vec3& p){ +void ofGLProgrammableRenderer::translate(const glm::vec3 & p) { translate(p.x, p.y, p.z); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::translate(float x, float y, float z){ - matrixStack.translate(x,y,z); +void ofGLProgrammableRenderer::translate(float x, float y, float z) { + matrixStack.translate(x, y, z); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::scale(float xAmnt, float yAmnt, float zAmnt){ +void ofGLProgrammableRenderer::scale(float xAmnt, float yAmnt, float zAmnt) { matrixStack.scale(xAmnt, yAmnt, zAmnt); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ){ +void ofGLProgrammableRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ) { matrixStack.rotateRad(radians, vecX, vecY, vecZ); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::rotateXRad(float radians){ +void ofGLProgrammableRenderer::rotateXRad(float radians) { rotateRad(radians, 1, 0, 0); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::rotateYRad(float radians){ +void ofGLProgrammableRenderer::rotateYRad(float radians) { rotateRad(radians, 0, 1, 0); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::rotateZRad(float radians){ +void ofGLProgrammableRenderer::rotateZRad(float radians) { rotateRad(radians, 0, 0, 1); } //same as ofRotateZ //---------------------------------------------------------- -void ofGLProgrammableRenderer::rotateRad(float radians){ +void ofGLProgrammableRenderer::rotateRad(float radians) { rotateZRad(radians); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::matrixMode(ofMatrixMode mode){ +void ofGLProgrammableRenderer::matrixMode(ofMatrixMode mode) { matrixStack.matrixMode(mode); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::loadIdentityMatrix (void){ +void ofGLProgrammableRenderer::loadIdentityMatrix(void) { matrixStack.loadIdentityMatrix(); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::loadMatrix (const glm::mat4 & m){ +void ofGLProgrammableRenderer::loadMatrix(const glm::mat4 & m) { matrixStack.loadMatrix(m); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::loadMatrix (const float *m){ +void ofGLProgrammableRenderer::loadMatrix(const float * m) { loadMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::multMatrix (const glm::mat4 & m){ +void ofGLProgrammableRenderer::multMatrix(const glm::mat4 & m) { matrixStack.multMatrix(m); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::multMatrix (const float *m){ +void ofGLProgrammableRenderer::multMatrix(const float * m) { multMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::loadViewMatrix(const glm::mat4 & m){ +void ofGLProgrammableRenderer::loadViewMatrix(const glm::mat4 & m) { matrixStack.loadViewMatrix(m); uploadCurrentMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::multViewMatrix(const glm::mat4 & m){ +void ofGLProgrammableRenderer::multViewMatrix(const glm::mat4 & m) { matrixStack.multViewMatrix(m); uploadCurrentMatrix(); } //---------------------------------------------------------- -glm::mat4 ofGLProgrammableRenderer::getCurrentViewMatrix() const{ +glm::mat4 ofGLProgrammableRenderer::getCurrentViewMatrix() const { return matrixStack.getViewMatrix(); } //---------------------------------------------------------- -glm::mat4 ofGLProgrammableRenderer::getCurrentNormalMatrix() const{ +glm::mat4 ofGLProgrammableRenderer::getCurrentNormalMatrix() const { return glm::transpose(glm::inverse(getCurrentMatrix(OF_MATRIX_MODELVIEW))); } //---------------------------------------------------------- -glm::mat4 ofGLProgrammableRenderer::getCurrentModelMatrix() const{ +glm::mat4 ofGLProgrammableRenderer::getCurrentModelMatrix() const { return matrixStack.getModelMatrix(); } @@ -800,17 +791,17 @@ glm::vec3 ofGLProgrammableRenderer::getCurrentEyePosition() const { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::uploadCurrentMatrix(){ - if(!currentShader) return; +void ofGLProgrammableRenderer::uploadCurrentMatrix() { + if (!currentShader) return; // uploads the current matrix to the current shader. - switch(matrixStack.getCurrentMatrixMode()){ + switch (matrixStack.getCurrentMatrixMode()) { case OF_MATRIX_MODELVIEW: currentShader->setUniformMatrix4f(MODEL_MATRIX_UNIFORM, matrixStack.getModelMatrix()); currentShader->setUniformMatrix4f(VIEW_MATRIX_UNIFORM, matrixStack.getViewMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_MATRIX_UNIFORM, matrixStack.getModelViewMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); - if(currentMaterial){ - currentMaterial->uploadMatrices(*currentShader,*this); + if (currentMaterial) { + currentMaterial->uploadMatrices(*currentShader, *this); } break; case OF_MATRIX_PROJECTION: @@ -821,25 +812,24 @@ void ofGLProgrammableRenderer::uploadCurrentMatrix(){ currentShader->setUniformMatrix4f(TEXTURE_MATRIX_UNIFORM, matrixStack.getTextureMatrix()); break; } - } //---------------------------------------------------------- glm::mat4 ofGLProgrammableRenderer::getCurrentMatrix(ofMatrixMode matrixMode_) const { switch (matrixMode_) { - case OF_MATRIX_MODELVIEW: - return matrixStack.getModelViewMatrix(); - break; - case OF_MATRIX_PROJECTION: - return matrixStack.getProjectionMatrix(); - break; - case OF_MATRIX_TEXTURE: - return matrixStack.getTextureMatrix(); - break; - default: - ofLogWarning() << "Invalid getCurrentMatrix query"; - return glm::mat4(1.0); - break; + case OF_MATRIX_MODELVIEW: + return matrixStack.getModelViewMatrix(); + break; + case OF_MATRIX_PROJECTION: + return matrixStack.getProjectionMatrix(); + break; + case OF_MATRIX_TEXTURE: + return matrixStack.getTextureMatrix(); + break; + default: + ofLogWarning() << "Invalid getCurrentMatrix query"; + return glm::mat4(1.0); + break; } } @@ -848,51 +838,51 @@ glm::mat4 ofGLProgrammableRenderer::getCurrentOrientationMatrix() const { return matrixStack.getOrientationMatrix(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setColor(const ofFloatColor & color){ - setColor(color.r,color.g,color.b,color.a); +void ofGLProgrammableRenderer::setColor(const ofFloatColor & color) { + setColor(color.r, color.g, color.b, color.a); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setColor(const ofFloatColor & color, float _a){ - setColor(color.r,color.g,color.b,_a); +void ofGLProgrammableRenderer::setColor(const ofFloatColor & color, float _a) { + setColor(color.r, color.g, color.b, _a); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b){ +void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b) { setColor(_r, _g, _b, 1.f); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b, float _a){ - ofFloatColor newColor(_r,_g,_b,_a); - if(newColor!=currentStyle.color){ - currentStyle.color = newColor; - if(currentShader){ - currentShader->setUniform4f(COLOR_UNIFORM,_r,_g,_b,_a); +void ofGLProgrammableRenderer::setColor(float _r, float _g, float _b, float _a) { + ofFloatColor newColor(_r, _g, _b, _a); + if (newColor != currentStyle.color) { + currentStyle.color = newColor; + if (currentShader) { + currentShader->setUniform4f(COLOR_UNIFORM, _r, _g, _b, _a); } } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setColor(float gray){ +void ofGLProgrammableRenderer::setColor(float gray) { setColor(gray, gray, gray); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setHexColor(int hexColor){ +void ofGLProgrammableRenderer::setHexColor(int hexColor) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - setColor((float)r/255.f,(float)g/255.f,(float)b/255.f); + setColor((float)r / 255.f, (float)g / 255.f, (float)b / 255.f); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setBitmapTextMode(ofDrawBitmapMode mode){ - currentStyle.drawBitmapMode = mode; +void ofGLProgrammableRenderer::setBitmapTextMode(ofBitmapMode mode) { + currentStyle.bitmapMode = mode; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::clear(){ +void ofGLProgrammableRenderer::clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -916,30 +906,30 @@ void ofGLProgrammableRenderer::clearAlpha() { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setBackgroundAuto(bool bAuto){ +void ofGLProgrammableRenderer::setBackgroundAuto(bool bAuto) { bBackgroundAuto = bAuto; } //---------------------------------------------------------- -bool ofGLProgrammableRenderer::getBackgroundAuto(){ +bool ofGLProgrammableRenderer::getBackgroundAuto() { return bBackgroundAuto; } //---------------------------------------------------------- -ofFloatColor ofGLProgrammableRenderer::getBackgroundColor(){ +ofFloatColor ofGLProgrammableRenderer::getBackgroundColor() { return currentStyle.bgColor; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setBackgroundColor(const ofFloatColor & c){ +void ofGLProgrammableRenderer::setBackgroundColor(const ofFloatColor & c) { currentStyle.bgColor = c; glClearColor(currentStyle.bgColor[0], currentStyle.bgColor[1], currentStyle.bgColor[2], currentStyle.bgColor[3]); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::background(const ofFloatColor & c){ +void ofGLProgrammableRenderer::background(const ofFloatColor & c) { setBackgroundColor(c); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } //---------------------------------------------------------- @@ -948,60 +938,60 @@ void ofGLProgrammableRenderer::background(float brightness) { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::background(int hexColor, int _a){ +void ofGLProgrammableRenderer::background(int hexColor, int _a) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - background( (float)r/255.f, (float)g/255.f, (float)b/255.f, _a/255.f ); -// background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a); + background((float)r / 255.f, (float)g / 255.f, (float)b / 255.f, _a / 255.f); + // background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::background(float r, float g, float b, float a){ - background(ofFloatColor(r,g,b,a)); +void ofGLProgrammableRenderer::background(float r, float g, float b, float a) { + background(ofFloatColor(r, g, b, a)); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setFillMode(ofFillFlag fill){ - currentStyle.bFill = (fill==OF_FILLED); - if(currentStyle.bFill){ +void ofGLProgrammableRenderer::setFillMode(ofFillFlag fill) { + currentStyle.bFill = (fill == OF_FILLED); + if (currentStyle.bFill) { path.setFilled(true); path.setStrokeWidth(0); - #ifndef TARGET_OPENGLES - // GLES does not support glPolygonMode - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - #endif - }else{ +#ifndef TARGET_OPENGLES + // GLES does not support glPolygonMode + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif + } else { path.setFilled(false); path.setStrokeWidth(currentStyle.lineWidth); - #ifndef TARGET_OPENGLES - // GLES does not support glPolygonMode - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - #endif +#ifndef TARGET_OPENGLES + // GLES does not support glPolygonMode + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); +#endif } } //---------------------------------------------------------- -ofFillFlag ofGLProgrammableRenderer::getFillMode(){ - if(currentStyle.bFill){ +ofFillFlag ofGLProgrammableRenderer::getFillMode() { + if (currentStyle.bFill) { return OF_FILLED; - }else{ + } else { return OF_OUTLINE; } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setRectMode(ofRectMode mode){ +void ofGLProgrammableRenderer::setRectMode(ofRectMode mode) { currentStyle.rectMode = mode; } //---------------------------------------------------------- -ofRectMode ofGLProgrammableRenderer::getRectMode(){ +ofRectMode ofGLProgrammableRenderer::getRectMode() { return currentStyle.rectMode; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setLineWidth(float lineWidth){ +void ofGLProgrammableRenderer::setLineWidth(float lineWidth) { // tig: glLinewidth is 'kind of' deprecated. // http://www.opengl.org/registry/doc/glspec32.core.20090803.pdf // p.330: "LineWidth values greater than 1.0 will generate an @@ -1009,7 +999,7 @@ void ofGLProgrammableRenderer::setLineWidth(float lineWidth){ // use geometry shaders to draw lines of varying thickness... currentStyle.lineWidth = lineWidth; - if(!currentStyle.bFill){ + if (!currentStyle.bFill) { path.setStrokeWidth(lineWidth); } //glLineWidth(lineWidth); @@ -1017,7 +1007,7 @@ void ofGLProgrammableRenderer::setLineWidth(float lineWidth){ //---------------------------------------------------------- void ofGLProgrammableRenderer::setDepthTest(bool depthTest) { - if(depthTest) { + if (depthTest) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); @@ -1025,68 +1015,68 @@ void ofGLProgrammableRenderer::setDepthTest(bool depthTest) { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setLineSmoothing(bool smooth){ +void ofGLProgrammableRenderer::setLineSmoothing(bool smooth) { currentStyle.smoothing = smooth; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::startSmoothing(){ - // TODO :: needs ES2 code. +void ofGLProgrammableRenderer::startSmoothing() { + // TODO :: needs ES2 code. } //---------------------------------------------------------- -void ofGLProgrammableRenderer::endSmoothing(){ - // TODO :: needs ES2 code. +void ofGLProgrammableRenderer::endSmoothing() { + // TODO :: needs ES2 code. } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setBlendMode(ofBlendMode blendMode){ - switch (blendMode){ - case OF_BLENDMODE_DISABLED: - glDisable(GL_BLEND); - break; +void ofGLProgrammableRenderer::setBlendMode(ofBlendMode blendMode) { + switch (blendMode) { + case OF_BLENDMODE_DISABLED: + glDisable(GL_BLEND); + break; - case OF_BLENDMODE_ALPHA: - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; + case OF_BLENDMODE_ALPHA: + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; - case OF_BLENDMODE_ADD: - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; + case OF_BLENDMODE_ADD: + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; - case OF_BLENDMODE_MULTIPLY: - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA /* GL_ZERO or GL_ONE_MINUS_SRC_ALPHA */); - break; + case OF_BLENDMODE_MULTIPLY: + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA /* GL_ZERO or GL_ONE_MINUS_SRC_ALPHA */); + break; - case OF_BLENDMODE_SCREEN: - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); - break; + case OF_BLENDMODE_SCREEN: + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); + break; - case OF_BLENDMODE_SUBTRACT: - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; + case OF_BLENDMODE_SUBTRACT: + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; - default: - break; + default: + break; } currentStyle.blendingMode = blendMode; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::enablePointSprites(){ +void ofGLProgrammableRenderer::enablePointSprites() { #ifdef TARGET_OPENGLES #ifndef TARGET_PROGRAMMABLE_GL - glEnable(GL_POINT_SPRITE_OES); + glEnable(GL_POINT_SPRITE_OES); #endif #else glEnable(GL_PROGRAM_POINT_SIZE); @@ -1094,68 +1084,67 @@ void ofGLProgrammableRenderer::enablePointSprites(){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disablePointSprites(){ +void ofGLProgrammableRenderer::disablePointSprites() { #ifdef TARGET_OPENGLES #ifndef TARGET_PROGRAMMABLE_GL - glEnable(GL_POINT_SPRITE_OES); + glEnable(GL_POINT_SPRITE_OES); #endif #else glDisable(GL_PROGRAM_POINT_SIZE); #endif } - //---------------------------------------------------------- -void ofGLProgrammableRenderer::enableAntiAliasing(){ +void ofGLProgrammableRenderer::enableAntiAliasing() { #if !defined(TARGET_PROGRAMMABLE_GL) || !defined(TARGET_OPENGLES) glEnable(GL_MULTISAMPLE); #endif } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disableAntiAliasing(){ +void ofGLProgrammableRenderer::disableAntiAliasing() { #if !defined(TARGET_PROGRAMMABLE_GL) || !defined(TARGET_OPENGLES) glDisable(GL_MULTISAMPLE); #endif } //---------------------------------------------------------- -const ofShader & ofGLProgrammableRenderer::getCurrentShader() const{ +const ofShader & ofGLProgrammableRenderer::getCurrentShader() const { return *currentShader; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setAlphaBitmapText(bool bitmapText){ +void ofGLProgrammableRenderer::setAlphaBitmapText(bool bitmapText) { bool wasBitmapStringEnabled = bitmapStringEnabled; bitmapStringEnabled = bitmapText; - if(wasBitmapStringEnabled!=bitmapText){ - if(currentShader) currentShader->setUniform1f(BITMAP_STRING_UNIFORM,bitmapText); + if (wasBitmapStringEnabled != bitmapText) { + if (currentShader) currentShader->setUniform1f(BITMAP_STRING_UNIFORM, bitmapText); } } -ofStyle ofGLProgrammableRenderer::getStyle() const{ +ofStyle ofGLProgrammableRenderer::getStyle() const { return currentStyle; } -void ofGLProgrammableRenderer::pushStyle(){ +void ofGLProgrammableRenderer::pushStyle() { styleHistory.push_back(currentStyle); //if we are over the max number of styles we have set, then delete the oldest styles. - if( styleHistory.size() > OF_MAX_STYLE_HISTORY ){ + if (styleHistory.size() > OF_MAX_STYLE_HISTORY) { styleHistory.pop_front(); //should we warn here? ofLogWarning("ofGraphics") << "ofPushStyle(): maximum number of style pushes << " << OF_MAX_STYLE_HISTORY << " reached, did you forget to pop somewhere?"; } } -void ofGLProgrammableRenderer::popStyle(){ - if( styleHistory.size() ){ +void ofGLProgrammableRenderer::popStyle() { + if (styleHistory.size()) { setStyle(styleHistory.back()); styleHistory.pop_back(); } } -void ofGLProgrammableRenderer::setStyle(const ofStyle & style){ +void ofGLProgrammableRenderer::setStyle(const ofStyle & style) { //color setColor((int)style.color.r, (int)style.color.g, (int)style.color.b, (int)style.color.a); @@ -1180,9 +1169,9 @@ void ofGLProgrammableRenderer::setStyle(const ofStyle & style){ setPolyMode(style.polyMode); //fill - if(style.bFill ){ + if (style.bFill) { setFillMode(OF_FILLED); - }else{ + } else { setFillMode(OF_OUTLINE); } @@ -1199,152 +1188,152 @@ void ofGLProgrammableRenderer::setStyle(const ofStyle & style){ currentStyle = style; } -void ofGLProgrammableRenderer::setCurveResolution(int resolution){ +void ofGLProgrammableRenderer::setCurveResolution(int resolution) { currentStyle.curveResolution = resolution; path.setCurveResolution(resolution); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setAttributes(bool vertices, bool color, bool tex, bool normals){ +void ofGLProgrammableRenderer::setAttributes(bool vertices, bool color, bool tex, bool normals) { bool wasColorsEnabled = colorsEnabled; - bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); + bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); texCoordsEnabled = tex; colorsEnabled = color; normalsEnabled = normals; - if(!uniqueShader || currentMaterial){ + if (!uniqueShader || currentMaterial) { beginDefaultShader(); } - bool usingTexture = tex & (currentTextureTarget!=OF_NO_TEXTURE); - if(wasUsingTexture!=usingTexture){ - if(currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM,usingTexture); + bool usingTexture = tex & (currentTextureTarget != OF_NO_TEXTURE); + if (wasUsingTexture != usingTexture) { + if (currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM, usingTexture); } - if(wasColorsEnabled!=color){ - if(currentShader) currentShader->setUniform1f(USE_COLORS_UNIFORM,color); + if (wasColorsEnabled != color) { + if (currentShader) currentShader->setUniform1f(USE_COLORS_UNIFORM, color); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::enableTextureTarget(const ofTexture & tex, int textureLocation){ - bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); +void ofGLProgrammableRenderer::enableTextureTarget(const ofTexture & tex, int textureLocation) { + bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); currentTextureTarget = tex.texData.textureTarget; - if(!uniqueShader || currentMaterial){ + if (!uniqueShader || currentMaterial) { beginDefaultShader(); } - bool usingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); - if(wasUsingTexture!=usingTexture){ - if(currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM,usingTexture); + bool usingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); + if (wasUsingTexture != usingTexture) { + if (currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM, usingTexture); } - if((currentTextureTarget!=OF_NO_TEXTURE) && currentShader){ - currentShader->setUniformTexture("src_tex_unit"+ofToString(textureLocation),tex,textureLocation); + if ((currentTextureTarget != OF_NO_TEXTURE) && currentShader) { + currentShader->setUniformTexture("src_tex_unit" + ofToString(textureLocation), tex, textureLocation); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disableTextureTarget(int textureTarget, int textureLocation){ - bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); +void ofGLProgrammableRenderer::disableTextureTarget(int textureTarget, int textureLocation) { + bool wasUsingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); currentTextureTarget = OF_NO_TEXTURE; - if(!uniqueShader || currentMaterial){ + if (!uniqueShader || currentMaterial) { beginDefaultShader(); } - bool usingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); - if(wasUsingTexture!=usingTexture){ - if(currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM,usingTexture); + bool usingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); + if (wasUsingTexture != usingTexture) { + if (currentShader) currentShader->setUniform1f(USE_TEXTURE_UNIFORM, usingTexture); } - glActiveTexture(GL_TEXTURE0+textureLocation); + glActiveTexture(GL_TEXTURE0 + textureLocation); glBindTexture(textureTarget, 0); glActiveTexture(GL_TEXTURE0); } //---------------------------------------------------------- -GLenum ofGLProgrammableRenderer::getCurrentTextureTarget(){ +GLenum ofGLProgrammableRenderer::getCurrentTextureTarget() { return currentTextureTarget; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setAlphaMaskTex(const ofTexture & tex){ +void ofGLProgrammableRenderer::setAlphaMaskTex(const ofTexture & tex) { alphaMaskTextureTarget = tex.getTextureData().textureTarget; - if(alphaMaskTextureTarget==GL_TEXTURE_2D){ + if (alphaMaskTextureTarget == GL_TEXTURE_2D) { alphaMask2DShader.begin(); - }else{ + } else { alphaMaskRectShader.begin(); } enableTextureTarget(tex, 1); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disableAlphaMask(){ - disableTextureTarget(alphaMaskTextureTarget,1); - if(alphaMaskTextureTarget==GL_TEXTURE_2D){ +void ofGLProgrammableRenderer::disableAlphaMask() { + disableTextureTarget(alphaMaskTextureTarget, 1); + if (alphaMaskTextureTarget == GL_TEXTURE_2D) { alphaMask2DShader.end(); - }else{ + } else { alphaMaskRectShader.end(); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofShader & shader){ - if(currentShader && *currentShader==shader){ +void ofGLProgrammableRenderer::bind(const ofShader & shader) { + if (currentShader && *currentShader == shader) { return; - } - - if(bIsShadowDepthPass) { + } + + if (bIsShadowDepthPass) { // if we are not the shadow shader, lets unbind it - if(!settingDefaultShader && currentShadow && currentShader ) { + if (!settingDefaultShader && currentShadow && currentShader) { // lets assume it's bound? - if(!bCustomShadowShader) { + if (!bCustomShadowShader) { glUseProgram(0); } // we are assuming that since it's a custom depth shader, it all will be taken care of ... - bCustomShadowShader=true; + bCustomShadowShader = true; } } - + glUseProgram(shader.getProgram()); currentShader = &shader; uploadMatrices(); setDefaultUniforms(); - if(!settingDefaultShader){ + if (!settingDefaultShader) { usingCustomShader = true; } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofShader & shader){ +void ofGLProgrammableRenderer::unbind(const ofShader & shader) { glUseProgram(0); usingCustomShader = false; - bCustomShadowShader=false; + bCustomShadowShader = false; beginDefaultShader(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::begin(const ofFbo & fbo, ofFboMode mode){ +void ofGLProgrammableRenderer::begin(const ofFbo & fbo, ofFboMode mode) { pushView(); - pushStyle(); - if(mode & OF_FBOMODE_MATRIXFLIP){ - matrixStack.setRenderSurface(fbo); - }else{ - matrixStack.setRenderSurfaceNoMatrixFlip(fbo); - } + pushStyle(); + if (mode & OF_FBOMODE_MATRIXFLIP) { + matrixStack.setRenderSurface(fbo); + } else { + matrixStack.setRenderSurfaceNoMatrixFlip(fbo); + } viewport(); - if(mode & OF_FBOMODE_PERSPECTIVE){ + if (mode & OF_FBOMODE_PERSPECTIVE) { setupScreenPerspective(); - }else{ + } else { uploadMatrices(); } bind(fbo); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::end(const ofFbo & fbo){ +void ofGLProgrammableRenderer::end(const ofFbo & fbo) { unbind(fbo); matrixStack.setRenderSurface(*window); uploadMatrices(); @@ -1353,16 +1342,16 @@ void ofGLProgrammableRenderer::end(const ofFbo & fbo){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofFbo & fbo){ - if (currentFramebufferId == fbo.getId()){ - ofLogWarning() << "Framebuffer with id: " << fbo.getId() << " cannot be bound onto itself. \n" << - "Most probably you forgot to end() the current framebuffer before calling begin() again or you forgot to allocate() before calling begin()."; +void ofGLProgrammableRenderer::bind(const ofFbo & fbo) { + if (currentFramebufferId == fbo.getId()) { + ofLogWarning() << "Framebuffer with id: " << fbo.getId() << " cannot be bound onto itself. \n" + << "Most probably you forgot to end() the current framebuffer before calling begin() again or you forgot to allocate() before calling begin()."; return; } // this method could just as well have been placed in ofBaseGLRenderer // and shared over both programmable and fixed function renderer. // I'm keeping it here, so that if we want to do more fancyful - // named framebuffers with GL 4.5+, we can have + // named framebuffers with GL 4.5+, we can have // different implementations. framebufferIdStack.push_back(currentFramebufferId); currentFramebufferId = fbo.getId(); @@ -1371,10 +1360,10 @@ void ofGLProgrammableRenderer::bind(const ofFbo & fbo){ #ifndef TARGET_OPENGLES //---------------------------------------------------------- -void ofGLProgrammableRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fboDst, int attachmentPoint){ - if (currentFramebufferId == fboSrc.getId()){ - ofLogWarning() << "Framebuffer with id: " << fboSrc.getId() << " cannot be bound onto itself. \n" << - "Most probably you forgot to end() the current framebuffer before calling getTexture()."; +void ofGLProgrammableRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fboDst, int attachmentPoint) { + if (currentFramebufferId == fboSrc.getId()) { + ofLogWarning() << "Framebuffer with id: " << fboSrc.getId() << " cannot be bound onto itself. \n" + << "Most probably you forgot to end() the current framebuffer before calling getTexture()."; return; } // this method could just as well have been placed in ofBaseGLRenderer @@ -1392,11 +1381,11 @@ void ofGLProgrammableRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fbo #endif //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofFbo & fbo){ - if(framebufferIdStack.empty()){ +void ofGLProgrammableRenderer::unbind(const ofFbo & fbo) { + if (framebufferIdStack.empty()) { ofLogError() << "unbalanced fbo bind/unbind binding default framebuffer"; currentFramebufferId = defaultFramebufferId; - }else{ + } else { currentFramebufferId = framebufferIdStack.back(); framebufferIdStack.pop_back(); } @@ -1405,20 +1394,20 @@ void ofGLProgrammableRenderer::unbind(const ofFbo & fbo){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofBaseMaterial & material){ - if( bIsShadowDepthPass ) { -// currentMaterial = nullptr; +void ofGLProgrammableRenderer::bind(const ofBaseMaterial & material) { + if (bIsShadowDepthPass) { + // currentMaterial = nullptr; // we are the shadow depth pass right now, we don't need // textures or lighting, etc. return; } currentMaterial = &material; - // FIXME: this invalidates the previous shader to avoid that - // when binding 2 materials one after another, the second won't - // get the right parameters. + // FIXME: this invalidates the previous shader to avoid that + // when binding 2 materials one after another, the second won't + // get the right parameters. currentMaterial->bind(*this); - currentShader = nullptr; - beginDefaultShader(); + currentShader = nullptr; + beginDefaultShader(); } //---------------------------------------------------------- @@ -1431,16 +1420,16 @@ void ofGLProgrammableRenderer::bind(const ofShadow & shadow) { //---------------------------------------------------------- void ofGLProgrammableRenderer::bind(const ofShadow & shadow, GLenum aCubeFace) { shadowCubeFace = aCubeFace; - bind( shadow ); + bind(shadow); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofBaseMaterial &){ - if(currentMaterial) { +void ofGLProgrammableRenderer::unbind(const ofBaseMaterial &) { + if (currentMaterial) { currentMaterial->unbind(*this); } - currentMaterial = nullptr; - if( bIsShadowDepthPass ) { + currentMaterial = nullptr; + if (bIsShadowDepthPass) { // we are the shadow depth pass right now, we don't need // textures or lighting, etc. return; @@ -1462,45 +1451,41 @@ void ofGLProgrammableRenderer::unbind(const ofShadow & shadow, GLenum aCubeFace) } //---------------------------------------------------------- -void ofGLProgrammableRenderer::enableLighting(){ - +void ofGLProgrammableRenderer::enableLighting() { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disableLighting(){ +void ofGLProgrammableRenderer::disableLighting() { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::enableLight(int){ - +void ofGLProgrammableRenderer::enableLight(int) { } //---------------------------------------------------------- -void ofGLProgrammableRenderer::disableLight(int){ - +void ofGLProgrammableRenderer::disableLight(int) { } //---------------------------------------------------------- -bool ofGLProgrammableRenderer::getLightingEnabled(){ - return true; +bool ofGLProgrammableRenderer::getLightingEnabled() { + return true; } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofTexture & texture, int location){ +void ofGLProgrammableRenderer::bind(const ofTexture & texture, int location) { //we could check if it has been allocated - but we don't do that in draw() - if(texture.getAlphaMask()){ + if (texture.getAlphaMask()) { setAlphaMaskTex(*texture.getAlphaMask()); } - enableTextureTarget(texture,location); - + enableTextureTarget(texture, location); - if(ofGetUsingNormalizedTexCoords()) { + if (ofGetUsingNormalizedTexCoords()) { matrixMode(OF_MATRIX_TEXTURE); pushMatrix(); glm::mat4 m = glm::mat4(1.0); #ifndef TARGET_OPENGLES - if(texture.texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) + if (texture.texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) m = glm::scale(m, glm::vec3(texture.texData.width, texture.texData.height, 1.0f)); else #endif @@ -1509,22 +1494,22 @@ void ofGLProgrammableRenderer::bind(const ofTexture & texture, int location){ loadMatrix(m); matrixMode(OF_MATRIX_MODELVIEW); } - if(texture.isUsingTextureMatrix()){ + if (texture.isUsingTextureMatrix()) { matrixMode(OF_MATRIX_TEXTURE); - if(!ofGetUsingNormalizedTexCoords()) pushMatrix(); + if (!ofGetUsingNormalizedTexCoords()) pushMatrix(); multMatrix(texture.getTextureMatrix()); matrixMode(OF_MATRIX_MODELVIEW); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofTexture & texture, int location){ - disableTextureTarget(texture.texData.textureTarget,location); - if(texture.getAlphaMask()){ +void ofGLProgrammableRenderer::unbind(const ofTexture & texture, int location) { + disableTextureTarget(texture.texData.textureTarget, location); + if (texture.getAlphaMask()) { disableAlphaMask(); } - if(texture.isUsingTextureMatrix() || ofGetUsingNormalizedTexCoords()) { + if (texture.isUsingTextureMatrix() || ofGetUsingNormalizedTexCoords()) { matrixMode(OF_MATRIX_TEXTURE); popMatrix(); matrixMode(OF_MATRIX_MODELVIEW); @@ -1532,10 +1517,10 @@ void ofGLProgrammableRenderer::unbind(const ofTexture & texture, int location){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::bind(const ofCamera & camera, const ofRectangle & _viewport){ +void ofGLProgrammableRenderer::bind(const ofCamera & camera, const ofRectangle & _viewport) { pushView(); viewport(_viewport); - setOrientation(matrixStack.getOrientation(),camera.isVFlipped()); + setOrientation(matrixStack.getOrientation(), camera.isVFlipped()); matrixMode(OF_MATRIX_PROJECTION); loadMatrix(camera.getProjectionMatrix(_viewport)); matrixMode(OF_MATRIX_MODELVIEW); @@ -1544,40 +1529,39 @@ void ofGLProgrammableRenderer::bind(const ofCamera & camera, const ofRectangle & } //---------------------------------------------------------- -void ofGLProgrammableRenderer::unbind(const ofCamera & camera){ +void ofGLProgrammableRenderer::unbind(const ofCamera & camera) { popView(); } - //---------------------------------------------------------- -void ofGLProgrammableRenderer::uploadMatrices(){ - if(!currentShader) return; +void ofGLProgrammableRenderer::uploadMatrices() { + if (!currentShader) return; currentShader->setUniformMatrix4f(MODEL_MATRIX_UNIFORM, matrixStack.getModelMatrix()); currentShader->setUniformMatrix4f(VIEW_MATRIX_UNIFORM, matrixStack.getViewMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_MATRIX_UNIFORM, matrixStack.getModelViewMatrix()); currentShader->setUniformMatrix4f(PROJECTION_MATRIX_UNIFORM, matrixStack.getProjectionMatrix()); currentShader->setUniformMatrix4f(TEXTURE_MATRIX_UNIFORM, matrixStack.getTextureMatrix()); currentShader->setUniformMatrix4f(MODELVIEW_PROJECTION_MATRIX_UNIFORM, matrixStack.getModelViewProjectionMatrix()); - if(currentMaterial){ - currentMaterial->uploadMatrices(*currentShader,*this); + if (currentMaterial) { + currentMaterial->uploadMatrices(*currentShader, *this); } } //---------------------------------------------------------- -void ofGLProgrammableRenderer::setDefaultUniforms(){ - if(!currentShader) return; - currentShader->setUniform4f(COLOR_UNIFORM, currentStyle.color.r,currentStyle.color.g,currentStyle.color.b,currentStyle.color.a); - bool usingTexture = texCoordsEnabled & (currentTextureTarget!=OF_NO_TEXTURE); - currentShader->setUniform1f(USE_TEXTURE_UNIFORM,usingTexture); - currentShader->setUniform1f(USE_COLORS_UNIFORM,colorsEnabled); - if(currentMaterial){ - currentMaterial->updateMaterial(*currentShader,*this); - currentMaterial->updateLights(*currentShader,*this); - currentMaterial->updateShadows(*currentShader,*this); +void ofGLProgrammableRenderer::setDefaultUniforms() { + if (!currentShader) return; + currentShader->setUniform4f(COLOR_UNIFORM, currentStyle.color.r, currentStyle.color.g, currentStyle.color.b, currentStyle.color.a); + bool usingTexture = texCoordsEnabled & (currentTextureTarget != OF_NO_TEXTURE); + currentShader->setUniform1f(USE_TEXTURE_UNIFORM, usingTexture); + currentShader->setUniform1f(USE_COLORS_UNIFORM, colorsEnabled); + if (currentMaterial) { + currentMaterial->updateMaterial(*currentShader, *this); + currentMaterial->updateLights(*currentShader, *this); + currentMaterial->updateShadows(*currentShader, *this); currentMaterial->updateEnvironmentMaps(*currentShader, *this); } - if(currentShadow) { - if( currentShadow->isMultiCubeFacePass() ) { + if (currentShadow) { + if (currentShadow->isMultiCubeFacePass()) { currentShadow->updateDepth(*currentShader, shadowCubeFace, *this); } else { currentShadow->updateDepth(*currentShader, *this); @@ -1586,75 +1570,75 @@ void ofGLProgrammableRenderer::setDefaultUniforms(){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::beginDefaultShader(){ - if(usingCustomShader && !currentMaterial && !currentShadow) return; - if( currentShadow && bCustomShadowShader ) return; +void ofGLProgrammableRenderer::beginDefaultShader() { + if (usingCustomShader && !currentMaterial && !currentShadow) return; + if (currentShadow && bCustomShadowShader) return; const ofShader * nextShader = nullptr; - if(!uniqueShader || currentMaterial || currentShadow ){ - if(currentShadow) { + if (!uniqueShader || currentMaterial || currentShadow) { + if (currentShadow) { nextShader = ¤tShadow->getDepthShader(*this); - } else if(currentMaterial){ -// std::cout << "ofGLProgrammableRenderer::beginDefaultShader: " << currentTextureTarget << " | " << ofGetFrameNum() << std::endl; - nextShader = ¤tMaterial->getShader(currentTextureTarget,colorsEnabled,*this); + } else if (currentMaterial) { + // std::cout << "ofGLProgrammableRenderer::beginDefaultShader: " << currentTextureTarget << " | " << ofGetFrameNum() << std::endl; + nextShader = ¤tMaterial->getShader(currentTextureTarget, colorsEnabled, *this); - }else if(bitmapStringEnabled){ + } else if (bitmapStringEnabled) { nextShader = &bitmapStringShader; - }else if(colorsEnabled && texCoordsEnabled){ - switch(currentTextureTarget){ - #ifndef TARGET_OPENGLES + } else if (colorsEnabled && texCoordsEnabled) { + switch (currentTextureTarget) { +#ifndef TARGET_OPENGLES case GL_TEXTURE_RECTANGLE_ARB: nextShader = &defaultTexRectColor; break; - #endif +#endif case GL_TEXTURE_2D: nextShader = &defaultTex2DColor; break; case OF_NO_TEXTURE: nextShader = &defaultNoTexColor; break; - #ifdef TARGET_ANDROID +#ifdef TARGET_ANDROID case GL_TEXTURE_EXTERNAL_OES: nextShader = &defaultOESTexColor; break; - #endif +#endif } - }else if(colorsEnabled){ + } else if (colorsEnabled) { nextShader = &defaultNoTexColor; - }else if(texCoordsEnabled){ - switch(currentTextureTarget){ - #ifndef TARGET_OPENGLES + } else if (texCoordsEnabled) { + switch (currentTextureTarget) { +#ifndef TARGET_OPENGLES case GL_TEXTURE_RECTANGLE_ARB: nextShader = &defaultTexRectNoColor; break; - #endif +#endif case GL_TEXTURE_2D: nextShader = &defaultTex2DNoColor; break; case OF_NO_TEXTURE: nextShader = &defaultNoTexNoColor; break; - #ifdef TARGET_ANDROID +#ifdef TARGET_ANDROID case GL_TEXTURE_EXTERNAL_OES: nextShader = &defaultOESTexNoColor; break; - #endif +#endif } - }else{ + } else { nextShader = &defaultNoTexNoColor; } - }else{ + } else { nextShader = &defaultUniqueShader; } - if(nextShader){ - if(!currentShader || *currentShader!=*nextShader){ + if (nextShader) { + if (!currentShader || *currentShader != *nextShader) { settingDefaultShader = true; bind(*nextShader); settingDefaultShader = false; @@ -1663,103 +1647,103 @@ void ofGLProgrammableRenderer::beginDefaultShader(){ } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); - lineMesh.getVertices()[0] = {x1,y1,z1}; - lineMesh.getVertices()[1] = {x2,y2,z2}; - +void ofGLProgrammableRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); + lineMesh.getVertices()[0] = { x1, y1, z1 }; + lineMesh.getVertices()[1] = { x2, y2, z2 }; + // use smoothness, if requested: if (currentStyle.smoothing) mutThis->startSmoothing(); - - draw(lineMesh,OF_MESH_FILL,false,false,false); - + + draw(lineMesh, OF_MESH_FILL, false, false, false); + // use smoothness, if requested: if (currentStyle.smoothing) mutThis->endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawRectangle(float x, float y, float z, float w, float h) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); - if (currentStyle.rectMode == OF_RECTMODE_CORNER){ - rectMesh.getVertices()[0] = {x,y,z}; - rectMesh.getVertices()[1] = {x+w, y, z}; - rectMesh.getVertices()[2] = {x+w, y+h, z}; - rectMesh.getVertices()[3] = {x, y+h, z}; - }else{ - rectMesh.getVertices()[0] = {x-w/2.0f, y-h/2.0f, z}; - rectMesh.getVertices()[1] = {x+w/2.0f, y-h/2.0f, z}; - rectMesh.getVertices()[2] = {x+w/2.0f, y+h/2.0f, z}; - rectMesh.getVertices()[3] = {x-w/2.0f, y+h/2.0f, z}; +void ofGLProgrammableRenderer::drawRectangle(float x, float y, float z, float w, float h) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); + if (currentStyle.rectMode == OF_RECTMODE_CORNER) { + rectMesh.getVertices()[0] = { x, y, z }; + rectMesh.getVertices()[1] = { x + w, y, z }; + rectMesh.getVertices()[2] = { x + w, y + h, z }; + rectMesh.getVertices()[3] = { x, y + h, z }; + } else { + rectMesh.getVertices()[0] = { x - w / 2.0f, y - h / 2.0f, z }; + rectMesh.getVertices()[1] = { x + w / 2.0f, y - h / 2.0f, z }; + rectMesh.getVertices()[2] = { x + w / 2.0f, y + h / 2.0f, z }; + rectMesh.getVertices()[3] = { x - w / 2.0f, y + h / 2.0f, z }; } - + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->startSmoothing(); rectMesh.setMode(currentStyle.bFill ? OF_PRIMITIVE_TRIANGLE_FAN : OF_PRIMITIVE_LINE_LOOP); - draw(rectMesh,OF_MESH_FILL,false,false,false); - + draw(rectMesh, OF_MESH_FILL, false, false, false); + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); - triangleMesh.getVertices()[0] = {x1,y1,z1}; - triangleMesh.getVertices()[1] = {x2,y2,z2}; - triangleMesh.getVertices()[2] = {x3,y3,z3}; - +void ofGLProgrammableRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); + triangleMesh.getVertices()[0] = { x1, y1, z1 }; + triangleMesh.getVertices()[1] = { x2, y2, z2 }; + triangleMesh.getVertices()[2] = { x3, y3, z3 }; + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->startSmoothing(); triangleMesh.setMode(currentStyle.bFill ? OF_PRIMITIVE_TRIANGLE_STRIP : OF_PRIMITIVE_LINE_LOOP); - draw(triangleMesh,OF_MESH_FILL,false,false,false); - + draw(triangleMesh, OF_MESH_FILL, false, false, false); + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawCircle(float x, float y, float z, float radius) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); +void ofGLProgrammableRenderer::drawCircle(float x, float y, float z, float radius) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); const auto & circleCache = circlePolyline.getVertices(); - for(int i=0;i<(int)circleCache.size();i++){ - circleMesh.getVertices()[i] = {radius*circleCache[i].x+x,radius*circleCache[i].y+y,z}; + for (int i = 0; i < (int)circleCache.size(); i++) { + circleMesh.getVertices()[i] = { radius * circleCache[i].x + x, radius * circleCache[i].y + y, z }; } - + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->startSmoothing(); circleMesh.setMode(currentStyle.bFill ? OF_PRIMITIVE_TRIANGLE_FAN : OF_PRIMITIVE_LINE_STRIP); - draw(circleMesh,OF_MESH_FILL,false,false,false); - + draw(circleMesh, OF_MESH_FILL, false, false, false); + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawEllipse(float x, float y, float z, float width, float height) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); - float radiusX = width*0.5; - float radiusY = height*0.5; +void ofGLProgrammableRenderer::drawEllipse(float x, float y, float z, float width, float height) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); + float radiusX = width * 0.5; + float radiusY = height * 0.5; const auto & circleCache = circlePolyline.getVertices(); - for(int i=0;i<(int)circleCache.size();i++){ - circleMesh.getVertices()[i] = {radiusX*circlePolyline[i].x+x,radiusY*circlePolyline[i].y+y,z}; + for (int i = 0; i < (int)circleCache.size(); i++) { + circleMesh.getVertices()[i] = { radiusX * circlePolyline[i].x + x, radiusY * circlePolyline[i].y + y, z }; } - + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->startSmoothing(); circleMesh.setMode(currentStyle.bFill ? OF_PRIMITIVE_TRIANGLE_FAN : OF_PRIMITIVE_LINE_STRIP); - draw(circleMesh,OF_MESH_FILL,false,false,false); - + draw(circleMesh, OF_MESH_FILL, false, false, false); + // use smoothness, if requested: if (currentStyle.smoothing && !currentStyle.bFill) mutThis->endSmoothing(); } //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawString(string textString, float x, float y, float z) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); +void ofGLProgrammableRenderer::drawString(string textString, float x, float y, float z) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); float sx = 0; float sy = 0; @@ -1775,106 +1759,103 @@ void ofGLProgrammableRenderer::drawString(string textString, float x, float y, f ofRectangle rViewport; glm::mat4 modelView = glm::mat4(1.0); - switch (currentStyle.drawBitmapMode) { + switch (currentStyle.bitmapMode) { - case OF_BITMAPMODE_SIMPLE: + case OF_BITMAPMODE_SIMPLE: - sx += x; - sy += y; - break; + sx += x; + sy += y; + break; - case OF_BITMAPMODE_SCREEN: + case OF_BITMAPMODE_SCREEN: - hasViewport = true; - mutThis->pushView(); + hasViewport = true; + mutThis->pushView(); - rViewport = matrixStack.getFullSurfaceViewport(); - mutThis->viewport(rViewport); + rViewport = matrixStack.getFullSurfaceViewport(); + mutThis->viewport(rViewport); - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->loadIdentityMatrix(); - mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->loadIdentityMatrix(); + mutThis->matrixMode(OF_MATRIX_MODELVIEW); - modelView = glm::translate(modelView, glm::vec3(-1,-1,0)); - modelView = glm::scale(modelView, glm::vec3(2/rViewport.width, 2/rViewport.height, 1)); - modelView = glm::translate(modelView, glm::vec3(x,y, 0)); - mutThis->loadMatrix(modelView); - break; + modelView = glm::translate(modelView, glm::vec3(-1, -1, 0)); + modelView = glm::scale(modelView, glm::vec3(2 / rViewport.width, 2 / rViewport.height, 1)); + modelView = glm::translate(modelView, glm::vec3(x, y, 0)); + mutThis->loadMatrix(modelView); + break; - case OF_BITMAPMODE_VIEWPORT: + case OF_BITMAPMODE_VIEWPORT: - rViewport = getCurrentViewport(); + rViewport = getCurrentViewport(); - hasProjection = true; - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + hasProjection = true; + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); - modelView = glm::translate(modelView, glm::vec3(-1,-1,0)); - modelView = glm::scale(modelView, glm::vec3(2/rViewport.width, 2/rViewport.height, 1)); - modelView = glm::translate(modelView, glm::vec3(x,y, 0)); - mutThis->loadMatrix(modelView); - break; + modelView = glm::translate(modelView, glm::vec3(-1, -1, 0)); + modelView = glm::scale(modelView, glm::vec3(2 / rViewport.width, 2 / rViewport.height, 1)); + modelView = glm::translate(modelView, glm::vec3(x, y, 0)); + mutThis->loadMatrix(modelView); + break; - case OF_BITMAPMODE_MODEL: + case OF_BITMAPMODE_MODEL: - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); - - mutThis->translate(x, y, z); - break; - - case OF_BITMAPMODE_MODEL_BILLBOARD: - { - //our aim here is to draw to screen - //at the viewport position related - //to the world position x,y,z - - // tig: we want to get the signed normalised screen coordinates (-1,+1) of our point (x,y,z) - // that's projection * modelview * point in GLSL multiplication order - // then doing the good old (v + 1.0) / 2. to get unsigned normalized screen (0,1) coordinates. - // we then multiply x by width and y by height to get window coordinates. - - rViewport = getCurrentViewport(); - - glm::mat4 mat = matrixStack.getProjectionMatrixNoOrientation() * matrixStack.getModelViewMatrix(); - glm::vec4 dScreen4 = mat * glm::vec4(x,y,z,1.0); - glm::vec3 dScreen = glm::vec3(dScreen4) / dScreen4.w; - dScreen += glm::vec3(1.0) ; - dScreen *= 0.5; - - dScreen.x += rViewport.x; - dScreen.x *= rViewport.width; - - dScreen.y += rViewport.y; - dScreen.y *= rViewport.height; - - if (dScreen.z >= 1) return; - - - hasProjection = true; - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); + mutThis->translate(x, y, z); + break; - modelView = glm::translate(modelView, glm::vec3(-1,-1,0)); - modelView = glm::scale(modelView, glm::vec3(2/rViewport.width, 2/rViewport.height, 1)); - modelView = glm::translate(modelView, glm::vec3(dScreen.x, dScreen.y, 0)); - mutThis->loadMatrix(modelView); - } - break; + case OF_BITMAPMODE_MODEL_BILLBOARD: { + //our aim here is to draw to screen + //at the viewport position related + //to the world position x,y,z + + // tig: we want to get the signed normalised screen coordinates (-1,+1) of our point (x,y,z) + // that's projection * modelview * point in GLSL multiplication order + // then doing the good old (v + 1.0) / 2. to get unsigned normalized screen (0,1) coordinates. + // we then multiply x by width and y by height to get window coordinates. + + rViewport = getCurrentViewport(); + + glm::mat4 mat = matrixStack.getProjectionMatrixNoOrientation() * matrixStack.getModelViewMatrix(); + glm::vec4 dScreen4 = mat * glm::vec4(x, y, z, 1.0); + glm::vec3 dScreen = glm::vec3(dScreen4) / dScreen4.w; + dScreen += glm::vec3(1.0); + dScreen *= 0.5; + + dScreen.x += rViewport.x; + dScreen.x *= rViewport.width; + + dScreen.y += rViewport.y; + dScreen.y *= rViewport.height; + + if (dScreen.z >= 1) return; + + hasProjection = true; + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); + + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); + + modelView = glm::translate(modelView, glm::vec3(-1, -1, 0)); + modelView = glm::scale(modelView, glm::vec3(2 / rViewport.width, 2 / rViewport.height, 1)); + modelView = glm::translate(modelView, glm::vec3(dScreen.x, dScreen.y, 0)); + mutThis->loadMatrix(modelView); + } break; - default: - break; + default: + break; } // /////////////////////////// @@ -1886,22 +1867,20 @@ void ofGLProgrammableRenderer::drawString(string textString, float x, float y, f // (c) enable texture once before we start drawing each char (no point turning it on and off constantly) //We do this because its way faster mutThis->setAlphaBitmapText(true); - ofMesh charMesh = bitmapFont.getMesh(textString, sx, sy, currentStyle.drawBitmapMode, isVFlipped()); - mutThis->bind(bitmapFont.getTexture(),0); - draw(charMesh,OF_MESH_FILL,false,true,false); - mutThis->unbind(bitmapFont.getTexture(),0); + ofMesh charMesh = bitmapFont.getMesh(textString, sx, sy, currentStyle.bitmapMode, isVFlipped()); + mutThis->bind(bitmapFont.getTexture(), 0); + draw(charMesh, OF_MESH_FILL, false, true, false); + mutThis->unbind(bitmapFont.getTexture(), 0); mutThis->setAlphaBitmapText(false); - - if (hasViewport){ + if (hasViewport) { mutThis->popView(); - }else{ - if (hasModelView){ + } else { + if (hasModelView) { mutThis->popMatrix(); } - if (hasProjection) - { + if (hasProjection) { mutThis->matrixMode(OF_MATRIX_PROJECTION); mutThis->popMatrix(); mutThis->matrixMode(OF_MATRIX_MODELVIEW); @@ -1909,59 +1888,53 @@ void ofGLProgrammableRenderer::drawString(string textString, float x, float y, f } } - //---------------------------------------------------------- -void ofGLProgrammableRenderer::drawString(const ofTrueTypeFont & font, string text, float x, float y) const{ - ofGLProgrammableRenderer * mutThis = const_cast(this); +void ofGLProgrammableRenderer::drawString(const ofTrueTypeFont & font, string text, float x, float y) const { + ofGLProgrammableRenderer * mutThis = const_cast(this); ofBlendMode blendMode = currentStyle.blendingMode; mutThis->setBlendMode(OF_BLENDMODE_ALPHA); - mutThis->bind(font.getFontTexture(),0); - draw(font.getStringMesh(text,x,y,isVFlipped()),OF_MESH_FILL); - mutThis->unbind(font.getFontTexture(),0); + mutThis->bind(font.getFontTexture(), 0); + draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL); + mutThis->unbind(font.getFontTexture(), 0); mutThis->setBlendMode(blendMode); } #define STRINGIFY(x) #x - // ---------------------------------------------------------------------- // tig: GLSL #150 shaders written against spec: // http://www.opengl.org/registry/doc/GLSLangSpec.1.50.09.pdf #ifdef TARGET_OPENGLES -static const string vertex_shader_header = - "%extensions%\n" - "precision highp float;\n" - "#define IN attribute\n" - "#define OUT varying\n" - "#define TEXTURE texture2D\n" - "#define TARGET_OPENGLES\n"; -static const string fragment_shader_header = - "%extensions%\n" - "precision highp float;\n" - "#define IN varying\n" - "#define OUT\n" - "#define TEXTURE texture2D\n" - "#define FRAG_COLOR gl_FragColor\n" - "#define TARGET_OPENGLES\n"; +static const string vertex_shader_header = "%extensions%\n" + "precision highp float;\n" + "#define IN attribute\n" + "#define OUT varying\n" + "#define TEXTURE texture2D\n" + "#define TARGET_OPENGLES\n"; +static const string fragment_shader_header = "%extensions%\n" + "precision highp float;\n" + "#define IN varying\n" + "#define OUT\n" + "#define TEXTURE texture2D\n" + "#define FRAG_COLOR gl_FragColor\n" + "#define TARGET_OPENGLES\n"; #else -static const string vertex_shader_header = - "#version %glsl_version%\n" - "%extensions%\n" - "#define IN in\n" - "#define OUT out\n" - "#define TEXTURE texture\n"; -static const string fragment_shader_header = - "#version %glsl_version%\n" - "%extensions%\n" - "#define IN in\n" - "#define OUT out\n" - "#define TEXTURE texture\n" - "#define FRAG_COLOR fragColor\n" - "out vec4 fragColor;\n"; +static const string vertex_shader_header = "#version %glsl_version%\n" + "%extensions%\n" + "#define IN in\n" + "#define OUT out\n" + "#define TEXTURE texture\n"; +static const string fragment_shader_header = "#version %glsl_version%\n" + "%extensions%\n" + "#define IN in\n" + "#define OUT out\n" + "#define TEXTURE texture\n" + "#define FRAG_COLOR fragColor\n" + "out vec4 fragColor;\n"; #endif static const string defaultVertexShader = vertex_shader_header + STRINGIFY( @@ -2001,8 +1974,7 @@ static const string defaultFragmentShaderTexRectColor = fragment_shader_header + IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; } ); @@ -2019,8 +1991,7 @@ static const string defaultFragmentShaderTexRectNoColor = fragment_shader_header IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying)* globalColor; + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * globalColor; } ); @@ -2038,8 +2009,7 @@ static const string alphaMaskFragmentShaderTexRectNoColor = fragment_shader_head IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = vec4(TEXTURE(src_tex_unit0, texCoordVarying).rgb, TEXTURE(src_tex_unit1, texCoordVarying).r)* globalColor; + void main(){ FRAG_COLOR = vec4(TEXTURE(src_tex_unit0, texCoordVarying).rgb, TEXTURE(src_tex_unit1, texCoordVarying).r) * globalColor; } ); @@ -2057,8 +2027,7 @@ static const string alphaMaskFragmentShaderTex2DNoColor = fragment_shader_header IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = vec4(TEXTURE(src_tex_unit0, texCoordVarying).rgb, TEXTURE(src_tex_unit1, texCoordVarying).r)* globalColor; + void main(){ FRAG_COLOR = vec4(TEXTURE(src_tex_unit0, texCoordVarying).rgb, TEXTURE(src_tex_unit1, texCoordVarying).r) * globalColor; } ); @@ -2075,8 +2044,7 @@ static const string defaultFragmentShaderTex2DColor = fragment_shader_header + S IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; } ); @@ -2092,27 +2060,25 @@ static const string defaultFragmentShaderTex2DNoColor = fragment_shader_header + IN float depth; IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * globalColor; + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * globalColor; } ); // ---------------------------------------------------------------------- static const string defaultFragmentShaderOESTexNoColor = fragment_shader_header + STRINGIFY( - - uniform samplerExternalOES src_tex_unit0; - uniform float usingTexture; - uniform float usingColors; - uniform vec4 globalColor; - - IN float depth; - IN vec4 colorVarying; - IN vec2 texCoordVarying; - - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * globalColor; - } + + uniform samplerExternalOES src_tex_unit0; + uniform float usingTexture; + uniform float usingColors; + uniform vec4 globalColor; + + IN float depth; + IN vec4 colorVarying; + IN vec2 texCoordVarying; + + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * globalColor; + } ); // ---------------------------------------------------------------------- @@ -2128,8 +2094,7 @@ static const string defaultFragmentShaderOESTexColor = fragment_shader_header + IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; + void main(){ FRAG_COLOR = TEXTURE(src_tex_unit0, texCoordVarying) * colorVarying; } ); @@ -2145,8 +2110,7 @@ static const string defaultFragmentShaderNoTexColor = fragment_shader_header + S IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = colorVarying; + void main(){ FRAG_COLOR = colorVarying; } ); @@ -2162,8 +2126,7 @@ static const string defaultFragmentShaderNoTexNoColor = fragment_shader_header + IN vec4 colorVarying; IN vec2 texCoordVarying; - void main(){ - FRAG_COLOR = globalColor; + void main(){ FRAG_COLOR = globalColor; } ); @@ -2214,7 +2177,7 @@ static const string bitmapStringFragmentShader = fragment_shader_header + STRING // in desktop openGL these are not used but we declare it to avoid more ifdefs static const string uniqueVertexShader = vertex_shader_header + STRINGIFY( - + uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; uniform mat4 textureMatrix; @@ -2241,7 +2204,7 @@ static const string uniqueVertexShader = vertex_shader_header + STRINGIFY( // ---------------------------------------------------------------------- static const string uniqueFragmentShader = fragment_shader_header + STRINGIFY( - + uniform sampler2D src_tex_unit0; uniform float usingTexture; uniform float bitmapText; @@ -2275,15 +2238,15 @@ static const string FRAGMENT_SHADER_YUY2 = STRINGIFY( uniform float onePixel;\n uniform float textureWidth;\n - const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n - const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n - const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n - const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n + const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n + const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n + const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n + const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n void main(){\n - vec3 yuv;\n - yuv.x=TEXTURE(src_tex_unit0,texCoordVarying).r;\n + vec3 yuv;\n + yuv.x=TEXTURE(src_tex_unit0,texCoordVarying).r;\n float x = texCoordVarying.x * textureWidth;\n if(mod(x,2.0)>0.5){\n yuv.y=TEXTURE(src_tex_unit0,vec2(texCoordVarying.x-onePixel,texCoordVarying.y)).%g;\n @@ -2292,11 +2255,11 @@ static const string FRAGMENT_SHADER_YUY2 = STRINGIFY( yuv.y=TEXTURE(src_tex_unit0,texCoordVarying).%g;\n yuv.z=TEXTURE(src_tex_unit0,vec2(texCoordVarying.x+onePixel,texCoordVarying.y)).%g;\n }\n - yuv += offset;\n - float r = dot(yuv, rcoeff);\n - float g = dot(yuv, gcoeff);\n - float b = dot(yuv, bcoeff);\n - FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n + yuv += offset;\n + float r = dot(yuv, rcoeff);\n + float g = dot(yuv, gcoeff);\n + float b = dot(yuv, bcoeff);\n + FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n }\n ); @@ -2305,26 +2268,26 @@ static const string FRAGMENT_SHADER_NV12_NV21 = STRINGIFY( uniform SAMPLER Ytex;\n uniform SAMPLER UVtex;\n uniform vec4 globalColor;\n - uniform vec2 tex_scaleUV;\n + uniform vec2 tex_scaleUV;\n IN vec4 colorVarying;\n IN vec2 texCoordVarying;\n - const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n - const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n - const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n - const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n + const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n + const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n + const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n + const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n void main(){\n - vec3 yuv;\n - yuv.x=TEXTURE(Ytex,texCoordVarying).r;\n - yuv.yz=TEXTURE(UVtex,texCoordVarying * tex_scaleUV).%r%g;\n - yuv += offset;\n - float r = dot(yuv, rcoeff);\n - float g = dot(yuv, gcoeff);\n - float b = dot(yuv, bcoeff);\n - FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n + vec3 yuv;\n + yuv.x=TEXTURE(Ytex,texCoordVarying).r;\n + yuv.yz=TEXTURE(UVtex,texCoordVarying * tex_scaleUV).%r%g;\n + yuv += offset;\n + float r = dot(yuv, rcoeff);\n + float g = dot(yuv, gcoeff);\n + float b = dot(yuv, bcoeff);\n + FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n }\n ); @@ -2333,140 +2296,139 @@ static const string FRAGMENT_SHADER_PLANAR_YUV = STRINGIFY( uniform SAMPLER Ytex;\n uniform SAMPLER Utex;\n uniform SAMPLER Vtex;\n - uniform vec2 tex_scaleY;\n - uniform vec2 tex_scaleU;\n - uniform vec2 tex_scaleV;\n + uniform vec2 tex_scaleY;\n + uniform vec2 tex_scaleU;\n + uniform vec2 tex_scaleV;\n uniform vec4 globalColor;\n IN vec4 colorVarying;\n IN vec2 texCoordVarying;\n - const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n - const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n - const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n - const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n + const vec3 offset = vec3(-0.0625, -0.5, -0.5);\n + const vec3 rcoeff = vec3(1.164, 0.000, 1.596);\n + const vec3 gcoeff = vec3(1.164,-0.391,-0.813);\n + const vec3 bcoeff = vec3(1.164, 2.018, 0.000);\n void main(){\n - vec3 yuv;\n - yuv.x=TEXTURE(Ytex,texCoordVarying * tex_scaleY).r;\n - yuv.y=TEXTURE(Utex,texCoordVarying * tex_scaleU).r;\n - yuv.z=TEXTURE(Vtex,texCoordVarying * tex_scaleV).r;\n - yuv += offset;\n - float r = dot(yuv, rcoeff);\n - float g = dot(yuv, gcoeff);\n - float b = dot(yuv, bcoeff);\n - FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n + vec3 yuv;\n + yuv.x=TEXTURE(Ytex,texCoordVarying * tex_scaleY).r;\n + yuv.y=TEXTURE(Utex,texCoordVarying * tex_scaleU).r;\n + yuv.z=TEXTURE(Vtex,texCoordVarying * tex_scaleV).r;\n + yuv += offset;\n + float r = dot(yuv, rcoeff);\n + float g = dot(yuv, gcoeff);\n + float b = dot(yuv, bcoeff);\n + FRAG_COLOR=vec4(r,g,b,1.0) * globalColor;\n }\n ); -static string defaultShaderHeader(string header, GLenum textureTarget, int major, int minor){ - ofStringReplace(header,"%glsl_version%",ofGLSLVersionFromGL(major,minor)); +static string defaultShaderHeader(string header, GLenum textureTarget, int major, int minor) { + ofStringReplace(header, "%glsl_version%", ofGLSLVersionFromGL(major, minor)); #ifndef TARGET_OPENGLES - if(major<4 && minor<2){ - ofStringReplace(header,"%extensions%","#extension GL_ARB_texture_rectangle : enable"); - }else{ - ofStringReplace(header,"%extensions%",""); + if (major < 4 && minor < 2) { + ofStringReplace(header, "%extensions%", "#extension GL_ARB_texture_rectangle : enable"); + } else { + ofStringReplace(header, "%extensions%", ""); } -#else - ofStringReplace(header,"%extensions%","#extension GL_OES_standard_derivatives : enable"); +#else + ofStringReplace(header, "%extensions%", "#extension GL_OES_standard_derivatives : enable"); #endif - if(textureTarget==GL_TEXTURE_2D){ + if (textureTarget == GL_TEXTURE_2D) { header += "#define SAMPLER sampler2D\n"; - }else{ + } else { header += "#define SAMPLER sampler2DRect\n"; } return header; } - -static string shaderSource(const string & src, int major, int minor){ +static string shaderSource(const string & src, int major, int minor) { string shaderSrc = src; - ofStringReplace(shaderSrc,"%glsl_version%",ofGLSLVersionFromGL(major,minor)); + ofStringReplace(shaderSrc, "%glsl_version%", ofGLSLVersionFromGL(major, minor)); #ifndef TARGET_OPENGLES - if(major<4 && minor<2){ - ofStringReplace(shaderSrc,"%extensions%","#extension GL_ARB_texture_rectangle : enable"); - }else{ - ofStringReplace(shaderSrc,"%extensions%",""); + if (major < 4 && minor < 2) { + ofStringReplace(shaderSrc, "%extensions%", "#extension GL_ARB_texture_rectangle : enable"); + } else { + ofStringReplace(shaderSrc, "%extensions%", ""); } #else - ofStringReplace(shaderSrc,"%extensions%",""); + ofStringReplace(shaderSrc, "%extensions%", ""); #endif return shaderSrc; } #ifdef TARGET_ANDROID -static string shaderOESSource(const string & src, int major, int minor){ +static string shaderOESSource(const string & src, int major, int minor) { string shaderSrc = src; - ofStringReplace(shaderSrc,"%glsl_version%",ofGLSLVersionFromGL(major,minor)); - ofStringReplace(shaderSrc,"%extensions%","#extension GL_OES_EGL_image_external : require"); + ofStringReplace(shaderSrc, "%glsl_version%", ofGLSLVersionFromGL(major, minor)); + ofStringReplace(shaderSrc, "%extensions%", "#extension GL_OES_EGL_image_external : require"); return shaderSrc; } #endif -static string videoFragmentShaderSource(const ofBaseVideoDraws & video, int major, int minor){ +static string videoFragmentShaderSource(const ofBaseVideoDraws & video, int major, int minor) { string src; - switch(video.getPixelFormat()){ - case OF_PIXELS_YUY2: - src = FRAGMENT_SHADER_YUY2; - #ifndef TARGET_OPENGLES - ofStringReplace(src,"%g","g"); - #else - ofStringReplace(src,"%g","a"); - #endif - break; - case OF_PIXELS_NV12: - src = FRAGMENT_SHADER_NV12_NV21; - #ifndef TARGET_OPENGLES - ofStringReplace(src,"%r%g","rg"); - #else - ofStringReplace(src,"%r%g","ra"); - #endif - break; - case OF_PIXELS_NV21: - src = FRAGMENT_SHADER_NV12_NV21; - #ifndef TARGET_OPENGLES - ofStringReplace(src,"%r%g","gr"); - #else - ofStringReplace(src,"%r%g","ar"); - #endif - break; - case OF_PIXELS_YV12: - case OF_PIXELS_I420: - src = FRAGMENT_SHADER_PLANAR_YUV; - break; - case OF_PIXELS_RGB: - case OF_PIXELS_BGR: - case OF_PIXELS_RGB565: - case OF_PIXELS_RGBA: - case OF_PIXELS_BGRA: - case OF_PIXELS_GRAY: - default: - break; + switch (video.getPixelFormat()) { + case OF_PIXELS_YUY2: + src = FRAGMENT_SHADER_YUY2; +#ifndef TARGET_OPENGLES + ofStringReplace(src, "%g", "g"); +#else + ofStringReplace(src, "%g", "a"); +#endif + break; + case OF_PIXELS_NV12: + src = FRAGMENT_SHADER_NV12_NV21; +#ifndef TARGET_OPENGLES + ofStringReplace(src, "%r%g", "rg"); +#else + ofStringReplace(src, "%r%g", "ra"); +#endif + break; + case OF_PIXELS_NV21: + src = FRAGMENT_SHADER_NV12_NV21; +#ifndef TARGET_OPENGLES + ofStringReplace(src, "%r%g", "gr"); +#else + ofStringReplace(src, "%r%g", "ar"); +#endif + break; + case OF_PIXELS_YV12: + case OF_PIXELS_I420: + src = FRAGMENT_SHADER_PLANAR_YUV; + break; + case OF_PIXELS_RGB: + case OF_PIXELS_BGR: + case OF_PIXELS_RGB565: + case OF_PIXELS_RGBA: + case OF_PIXELS_BGRA: + case OF_PIXELS_GRAY: + default: + break; } string header = fragment_shader_header; GLenum textureTarget = video.getTexture().getTextureData().textureTarget; - if(textureTarget==GL_TEXTURE_2D){ + if (textureTarget == GL_TEXTURE_2D) { header += "#define SAMPLER sampler2D\n"; } #ifndef TARGET_OPENGLES - else if(textureTarget==GL_TEXTURE_RECTANGLE){ + else if (textureTarget == GL_TEXTURE_RECTANGLE) { header += "#define SAMPLER sampler2DRect\n"; } #endif return shaderSource(header + src, major, minor); } -string ofGLProgrammableRenderer::defaultVertexShaderHeader(GLenum textureTarget){ - return defaultShaderHeader(vertex_shader_header,textureTarget,major,minor); +string ofGLProgrammableRenderer::defaultVertexShaderHeader(GLenum textureTarget) { + return defaultShaderHeader(vertex_shader_header, textureTarget, major, minor); } -string ofGLProgrammableRenderer::defaultFragmentShaderHeader(GLenum textureTarget){ - return defaultShaderHeader(fragment_shader_header,textureTarget,major,minor); +string ofGLProgrammableRenderer::defaultFragmentShaderHeader(GLenum textureTarget) { + return defaultShaderHeader(fragment_shader_header, textureTarget, major, minor); } -void ofGLProgrammableRenderer::setup(int _major, int _minor){ +void ofGLProgrammableRenderer::setup(int _major, int _minor) { glGetError(); #ifdef TARGET_OPENGLES // OpenGL ES might have set a default frame buffer for @@ -2477,7 +2439,7 @@ void ofGLProgrammableRenderer::setup(int _major, int _minor){ GLint currentFrameBuffer; glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFrameBuffer); defaultFramebufferId = currentFrameBuffer; - currentFramebufferId = defaultFramebufferId; + currentFramebufferId = defaultFramebufferId; #endif major = _major; @@ -2488,38 +2450,37 @@ void ofGLProgrammableRenderer::setup(int _major, int _minor){ uniqueShader = false; #endif - if(uniqueShader){ - defaultUniqueShader.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(uniqueVertexShader, major, minor)); - defaultUniqueShader.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(uniqueFragmentShader, major, minor)); + if (uniqueShader) { + defaultUniqueShader.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(uniqueVertexShader, major, minor)); + defaultUniqueShader.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(uniqueFragmentShader, major, minor)); defaultUniqueShader.bindDefaults(); defaultUniqueShader.linkProgram(); beginDefaultShader(); - }else{ - #ifndef TARGET_OPENGLES - defaultTexRectColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - defaultTexRectNoColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - alphaMaskRectShader.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - #endif - defaultTex2DColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - defaultNoTexColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - defaultTex2DNoColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - defaultNoTexNoColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - alphaMask2DShader.setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major, minor)); - - #ifndef TARGET_OPENGLES - defaultTexRectColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderTexRectColor,major, minor)); - defaultTexRectNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderTexRectNoColor,major, minor)); - alphaMaskRectShader.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(alphaMaskFragmentShaderTexRectNoColor,major, minor)); - #endif - defaultTex2DColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderTex2DColor,major, minor)); - defaultNoTexColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderNoTexColor,major, minor)); - defaultTex2DNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderTex2DNoColor,major, minor)); - defaultNoTexNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(defaultFragmentShaderNoTexNoColor,major, minor)); - alphaMask2DShader.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderSource(alphaMaskFragmentShaderTex2DNoColor,major, minor)); + } else { +#ifndef TARGET_OPENGLES + defaultTexRectColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + defaultTexRectNoColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + alphaMaskRectShader.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); +#endif + defaultTex2DColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + defaultNoTexColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + defaultTex2DNoColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + defaultNoTexNoColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + alphaMask2DShader.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); +#ifndef TARGET_OPENGLES + defaultTexRectColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderTexRectColor, major, minor)); + defaultTexRectNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderTexRectNoColor, major, minor)); + alphaMaskRectShader.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(alphaMaskFragmentShaderTexRectNoColor, major, minor)); +#endif + defaultTex2DColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderTex2DColor, major, minor)); + defaultNoTexColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderNoTexColor, major, minor)); + defaultTex2DNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderTex2DNoColor, major, minor)); + defaultNoTexNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(defaultFragmentShaderNoTexNoColor, major, minor)); + alphaMask2DShader.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(alphaMaskFragmentShaderTex2DNoColor, major, minor)); - bitmapStringShader.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(bitmapStringVertexShader,major, minor)); - bitmapStringShader.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(bitmapStringFragmentShader,major, minor)); + bitmapStringShader.setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(bitmapStringVertexShader, major, minor)); + bitmapStringShader.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderSource(bitmapStringFragmentShader, major, minor)); #ifndef TARGET_OPENGLES defaultTexRectColor.bindDefaults(); @@ -2545,17 +2506,16 @@ void ofGLProgrammableRenderer::setup(int _major, int _minor){ bitmapStringShader.bindDefaults(); bitmapStringShader.linkProgram(); - - + #ifdef TARGET_ANDROID - defaultOESTexNoColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderOESSource(defaultVertexShader,major, minor)); - defaultOESTexColor.setupShaderFromSource(GL_VERTEX_SHADER,shaderOESSource(defaultVertexShader,major, minor)); - defaultOESTexColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderOESSource(defaultFragmentShaderOESTexColor,major, minor)); - defaultOESTexNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER,shaderOESSource(defaultFragmentShaderOESTexNoColor,major, minor)); - + defaultOESTexNoColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderOESSource(defaultVertexShader, major, minor)); + defaultOESTexColor.setupShaderFromSource(GL_VERTEX_SHADER, shaderOESSource(defaultVertexShader, major, minor)); + defaultOESTexColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderOESSource(defaultFragmentShaderOESTexColor, major, minor)); + defaultOESTexNoColor.setupShaderFromSource(GL_FRAGMENT_SHADER, shaderOESSource(defaultFragmentShaderOESTexNoColor, major, minor)); + defaultOESTexColor.bindDefaults(); defaultOESTexNoColor.bindDefaults(); - + defaultOESTexColor.linkProgram(); defaultOESTexNoColor.linkProgram(); #endif @@ -2566,52 +2526,52 @@ void ofGLProgrammableRenderer::setup(int _major, int _minor){ setupScreenPerspective(); } -const ofShader * ofGLProgrammableRenderer::getVideoShader(const ofBaseVideoDraws & video) const{ +const ofShader * ofGLProgrammableRenderer::getVideoShader(const ofBaseVideoDraws & video) const { const ofShader * shader = nullptr; GLenum target = video.getTexture().getTextureData().textureTarget; - switch(video.getPixelFormat()){ - case OF_PIXELS_YUY2: - if(target==GL_TEXTURE_2D){ - shader = &shaderPlanarYUY2; - }else{ - shader = &shaderPlanarYUY2Rect; - } - break; - case OF_PIXELS_NV12: - if(target==GL_TEXTURE_2D){ - shader = &shaderNV12; - }else{ - shader = &shaderNV12Rect; - } - break; - case OF_PIXELS_NV21: - if(target==GL_TEXTURE_2D){ - shader = &shaderNV21; - }else{ - shader = &shaderNV21Rect; - } - break; - case OF_PIXELS_YV12: - case OF_PIXELS_I420: - if(target==GL_TEXTURE_2D){ - shader = &shaderPlanarYUV; - }else{ - shader = &shaderPlanarYUVRect; - } - break; - case OF_PIXELS_RGB: - case OF_PIXELS_BGR: - case OF_PIXELS_RGB565: - case OF_PIXELS_RGBA: - case OF_PIXELS_BGRA: - case OF_PIXELS_GRAY: - default: - break; - } - if(shader && !shader->isLoaded()){ - ofShader * mutShader = const_cast(shader); - mutShader->setupShaderFromSource(GL_VERTEX_SHADER,shaderSource(defaultVertexShader,major,minor)); - mutShader->setupShaderFromSource(GL_FRAGMENT_SHADER,videoFragmentShaderSource(video,major,minor)); + switch (video.getPixelFormat()) { + case OF_PIXELS_YUY2: + if (target == GL_TEXTURE_2D) { + shader = &shaderPlanarYUY2; + } else { + shader = &shaderPlanarYUY2Rect; + } + break; + case OF_PIXELS_NV12: + if (target == GL_TEXTURE_2D) { + shader = &shaderNV12; + } else { + shader = &shaderNV12Rect; + } + break; + case OF_PIXELS_NV21: + if (target == GL_TEXTURE_2D) { + shader = &shaderNV21; + } else { + shader = &shaderNV21Rect; + } + break; + case OF_PIXELS_YV12: + case OF_PIXELS_I420: + if (target == GL_TEXTURE_2D) { + shader = &shaderPlanarYUV; + } else { + shader = &shaderPlanarYUVRect; + } + break; + case OF_PIXELS_RGB: + case OF_PIXELS_BGR: + case OF_PIXELS_RGB565: + case OF_PIXELS_RGBA: + case OF_PIXELS_BGRA: + case OF_PIXELS_GRAY: + default: + break; + } + if (shader && !shader->isLoaded()) { + ofShader * mutShader = const_cast(shader); + mutShader->setupShaderFromSource(GL_VERTEX_SHADER, shaderSource(defaultVertexShader, major, minor)); + mutShader->setupShaderFromSource(GL_FRAGMENT_SHADER, videoFragmentShaderSource(video, major, minor)); mutShader->bindDefaults(); mutShader->linkProgram(); } @@ -2619,114 +2579,112 @@ const ofShader * ofGLProgrammableRenderer::getVideoShader(const ofBaseVideoDraws } #ifndef TARGET_OPENGLES -static float getTextureScaleX(const ofBaseVideoDraws & video, int plane){ - if(!video.getTexturePlanes().empty()){ - return video.getTexturePlanes()[plane].getWidth()/video.getWidth(); - }else{ +static float getTextureScaleX(const ofBaseVideoDraws & video, int plane) { + if (!video.getTexturePlanes().empty()) { + return video.getTexturePlanes()[plane].getWidth() / video.getWidth(); + } else { return 1.0; } } -static float getTextureScaleY(const ofBaseVideoDraws & video, int plane){ - if(!video.getTexturePlanes().empty()){ - return video.getTexturePlanes()[plane].getHeight()/video.getHeight(); - }else{ +static float getTextureScaleY(const ofBaseVideoDraws & video, int plane) { + if (!video.getTexturePlanes().empty()) { + return video.getTexturePlanes()[plane].getHeight() / video.getHeight(); + } else { return 1.0; } } #endif -void ofGLProgrammableRenderer::setVideoShaderUniforms(const ofBaseVideoDraws & video, const ofShader & shader) const{ - switch(video.getPixelFormat()){ - case OF_PIXELS_YUY2: +void ofGLProgrammableRenderer::setVideoShaderUniforms(const ofBaseVideoDraws & video, const ofShader & shader) const { + switch (video.getPixelFormat()) { + case OF_PIXELS_YUY2: #ifndef TARGET_OPENGLES - if(video.getTexture().getTextureData().textureTarget==GL_TEXTURE_RECTANGLE){ - shader.setUniform1f("onePixel",1.0); - shader.setUniform1f("textureWidth",1.0); - }else{ + if (video.getTexture().getTextureData().textureTarget == GL_TEXTURE_RECTANGLE) { + shader.setUniform1f("onePixel", 1.0); + shader.setUniform1f("textureWidth", 1.0); + } else { #endif - shader.setUniform1f("onePixel",1.0/video.getWidth()); - shader.setUniform1f("textureWidth",video.getWidth()); + shader.setUniform1f("onePixel", 1.0 / video.getWidth()); + shader.setUniform1f("textureWidth", video.getWidth()); #ifndef TARGET_OPENGLES - } + } #endif - shader.setUniformTexture("src_tex_unit0",video.getTexturePlanes()[0],0); - break; - case OF_PIXELS_NV12: - case OF_PIXELS_NV21: - shader.setUniformTexture("Ytex",video.getTexturePlanes()[0],0); - shader.setUniformTexture("UVtex",video.getTexturePlanes()[1],1); + shader.setUniformTexture("src_tex_unit0", video.getTexturePlanes()[0], 0); + break; + case OF_PIXELS_NV12: + case OF_PIXELS_NV21: + shader.setUniformTexture("Ytex", video.getTexturePlanes()[0], 0); + shader.setUniformTexture("UVtex", video.getTexturePlanes()[1], 1); #ifndef TARGET_OPENGLES - if(video.getTexture().getTextureData().textureTarget==GL_TEXTURE_RECTANGLE){ - shader.setUniform2f("tex_scaleUV",getTextureScaleX(video,1),getTextureScaleY(video,1)); - }else{ + if (video.getTexture().getTextureData().textureTarget == GL_TEXTURE_RECTANGLE) { + shader.setUniform2f("tex_scaleUV", getTextureScaleX(video, 1), getTextureScaleY(video, 1)); + } else { #endif - shader.setUniform2f("tex_scaleUV",1.0,1.0); + shader.setUniform2f("tex_scaleUV", 1.0, 1.0); #ifndef TARGET_OPENGLES - } + } #endif - break; - case OF_PIXELS_YV12: - shader.setUniformTexture("Ytex",video.getTexturePlanes()[0],0); - shader.setUniformTexture("Utex",video.getTexturePlanes()[2],1); - shader.setUniformTexture("Vtex",video.getTexturePlanes()[1],2); + break; + case OF_PIXELS_YV12: + shader.setUniformTexture("Ytex", video.getTexturePlanes()[0], 0); + shader.setUniformTexture("Utex", video.getTexturePlanes()[2], 1); + shader.setUniformTexture("Vtex", video.getTexturePlanes()[1], 2); #ifndef TARGET_OPENGLES - if(video.getTexture().getTextureData().textureTarget==GL_TEXTURE_RECTANGLE){ - shader.setUniform2f("tex_scaleY",getTextureScaleX(video,0),getTextureScaleY(video,0)); - shader.setUniform2f("tex_scaleU",getTextureScaleX(video,2),getTextureScaleY(video,2)); - shader.setUniform2f("tex_scaleV",getTextureScaleX(video,1),getTextureScaleY(video,1)); - }else{ + if (video.getTexture().getTextureData().textureTarget == GL_TEXTURE_RECTANGLE) { + shader.setUniform2f("tex_scaleY", getTextureScaleX(video, 0), getTextureScaleY(video, 0)); + shader.setUniform2f("tex_scaleU", getTextureScaleX(video, 2), getTextureScaleY(video, 2)); + shader.setUniform2f("tex_scaleV", getTextureScaleX(video, 1), getTextureScaleY(video, 1)); + } else { #endif - shader.setUniform2f("tex_scaleY",1.0,1.0); - shader.setUniform2f("tex_scaleU",1.0,1.0); - shader.setUniform2f("tex_scaleV",1.0,1.0); + shader.setUniform2f("tex_scaleY", 1.0, 1.0); + shader.setUniform2f("tex_scaleU", 1.0, 1.0); + shader.setUniform2f("tex_scaleV", 1.0, 1.0); #ifndef TARGET_OPENGLES - } + } #endif - break; - case OF_PIXELS_I420: - shader.setUniformTexture("Ytex",video.getTexturePlanes()[0],0); - shader.setUniformTexture("Utex",video.getTexturePlanes()[1],1); - shader.setUniformTexture("Vtex",video.getTexturePlanes()[2],2); + break; + case OF_PIXELS_I420: + shader.setUniformTexture("Ytex", video.getTexturePlanes()[0], 0); + shader.setUniformTexture("Utex", video.getTexturePlanes()[1], 1); + shader.setUniformTexture("Vtex", video.getTexturePlanes()[2], 2); #ifndef TARGET_OPENGLES - if(video.getTexture().getTextureData().textureTarget==GL_TEXTURE_RECTANGLE){ - shader.setUniform2f("tex_scaleY",getTextureScaleX(video,0),getTextureScaleY(video,0)); - shader.setUniform2f("tex_scaleU",getTextureScaleX(video,1),getTextureScaleY(video,1)); - shader.setUniform2f("tex_scaleV",getTextureScaleX(video,2),getTextureScaleY(video,2)); - }else{ + if (video.getTexture().getTextureData().textureTarget == GL_TEXTURE_RECTANGLE) { + shader.setUniform2f("tex_scaleY", getTextureScaleX(video, 0), getTextureScaleY(video, 0)); + shader.setUniform2f("tex_scaleU", getTextureScaleX(video, 1), getTextureScaleY(video, 1)); + shader.setUniform2f("tex_scaleV", getTextureScaleX(video, 2), getTextureScaleY(video, 2)); + } else { #endif - shader.setUniform2f("tex_scaleY",1.0,1.0); - shader.setUniform2f("tex_scaleU",1.0,1.0); - shader.setUniform2f("tex_scaleV",1.0,1.0); + shader.setUniform2f("tex_scaleY", 1.0, 1.0); + shader.setUniform2f("tex_scaleU", 1.0, 1.0); + shader.setUniform2f("tex_scaleV", 1.0, 1.0); #ifndef TARGET_OPENGLES - } + } #endif - break; - default: - break; + break; + default: + break; } } -int ofGLProgrammableRenderer::getGLVersionMajor(){ +int ofGLProgrammableRenderer::getGLVersionMajor() { return major; } -int ofGLProgrammableRenderer::getGLVersionMinor(){ +int ofGLProgrammableRenderer::getGLVersionMinor() { return minor; } - -void ofGLProgrammableRenderer::saveFullViewport(ofPixels & pixels){ +void ofGLProgrammableRenderer::saveFullViewport(ofPixels & pixels) { ofRectangle v = getCurrentViewport(); - saveScreen(v.x,v.y,v.width,v.height,pixels); + saveScreen(v.x, v.y, v.width, v.height, pixels); } -void ofGLProgrammableRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels){ - int sh = getViewportHeight(); +void ofGLProgrammableRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels) { + int sh = getViewportHeight(); - - #ifndef TARGET_OPENGLES - if(isVFlipped()){ +#ifndef TARGET_OPENGLES + if (isVFlipped()) { y = sh - y; y -= h; // top, bottom issues } @@ -2734,7 +2692,6 @@ void ofGLProgrammableRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels.allocate(w, h, pixelFormat); auto glFormat = ofGetGLFormat(pixels); - ofBufferObject buffer; buffer.allocate(pixels.size(), GL_STATIC_READ); @@ -2742,89 +2699,88 @@ void ofGLProgrammableRenderer::saveScreen(int x, int y, int w, int h, ofPixels & glReadPixels(x, y, w, h, glFormat, GL_UNSIGNED_BYTE, 0); // read the memory.... buffer.unbind(GL_PIXEL_PACK_BUFFER); - if(unsigned char * p = buffer.map(GL_READ_ONLY)){ + if (unsigned char * p = buffer.map(GL_READ_ONLY)) { ofPixels src; - src.setFromExternalPixels(p,w,h,pixelFormat); - src.mirrorTo(pixels,true,false); + src.setFromExternalPixels(p, w, h, pixelFormat); + src.mirrorTo(pixels, true, false); buffer.unmap(); - }else{ + } else { ofLogError("ofGLProgrammableRenderer") << "Error saving screen"; } - #else +#else int sw = getViewportWidth(); - int numPixels = w*h; - if( numPixels == 0 ){ + int numPixels = w * h; + if (numPixels == 0) { ofLogError("ofImage") << "grabScreen(): unable to grab screen, image width and/or height are 0: " << w << "x" << h; return; } pixels.allocate(w, h, OF_PIXELS_RGBA); - switch(matrixStack.getOrientation()){ + switch (matrixStack.getOrientation()) { case OF_ORIENTATION_UNKNOWN: case OF_ORIENTATION_DEFAULT: - if(isVFlipped()){ - y = sh - y; // screen is flipped vertically. + if (isVFlipped()) { + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,false); + pixels.mirror(true, false); break; case OF_ORIENTATION_180: - if(isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + if (isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(false,true); + pixels.mirror(false, true); break; case OF_ORIENTATION_90_RIGHT: - swap(w,h); - swap(x,y); - if(!isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + swap(w, h); + swap(x, y); + if (!isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; - y = sh - y; // screen is flipped vertically. + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,true); + pixels.mirror(true, true); break; case OF_ORIENTATION_90_LEFT: swap(w, h); swap(x, y); - if(isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + if (isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; - y = sh - y; // screen is flipped vertically. + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,true); + pixels.mirror(true, true); break; } - #endif +#endif } -const of3dGraphics & ofGLProgrammableRenderer::get3dGraphics() const{ +const of3dGraphics & ofGLProgrammableRenderer::get3dGraphics() const { return graphics3d; } -of3dGraphics & ofGLProgrammableRenderer::get3dGraphics(){ +of3dGraphics & ofGLProgrammableRenderer::get3dGraphics() { return graphics3d; } - diff --git a/libs/openFrameworks/gl/ofGLProgrammableRenderer.h b/libs/openFrameworks/gl/ofGLProgrammableRenderer.h index 42f38f1ce40..feb69512784 100644 --- a/libs/openFrameworks/gl/ofGLProgrammableRenderer.h +++ b/libs/openFrameworks/gl/ofGLProgrammableRenderer.h @@ -1,63 +1,61 @@ #pragma once -#include "ofGLBaseTypes.h" -#include "ofPolyline.h" -#include "ofShader.h" -#include "ofMatrixStack.h" #include "of3dGraphics.h" #include "ofBitmapFont.h" +#include "ofGLBaseTypes.h" +#include "ofMatrixStack.h" #include "ofPath.h" +#include "ofPolyline.h" +#include "ofShader.h" //#include "ofMaterialBaseTypes.h" class ofShapeTessellation; class ofFbo; class ofVbo; -static const int OF_NO_TEXTURE=-1; +static const int OF_NO_TEXTURE = -1; -class ofGLProgrammableRenderer: public ofBaseGLRenderer{ +class ofGLProgrammableRenderer : public ofBaseGLRenderer { public: - ofGLProgrammableRenderer(const ofAppBaseWindow * window); + ofGLProgrammableRenderer(const ofAppBaseWindow * window); void setup(int glVersionMajor, int glVersionMinor); - static const std::string TYPE; - const std::string & getType(){ return TYPE; } - - void startRender(); - void finishRender(); + static const std::string TYPE; + const std::string & getType() { return TYPE; } + + void startRender(); + void finishRender(); - using ofBaseRenderer::draw; using ofBaseGLRenderer::draw; + using ofBaseRenderer::draw; void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const; - void draw(const of3dPrimitive& model, ofPolyRenderMode renderType) const; - void draw(const ofNode& node) const; + void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const; + void draw(const ofNode & node) const; void draw(const ofPolyline & poly) const; void draw(const ofPath & path) const; void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; void draw(const ofTexture & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; - void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const; + void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const; void draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const; void drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements = 0) const; void drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const; void drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const; void draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const; void drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const; - ofPath & getPath(); - - - + ofPath & getPath(); + //-------------------------------------------- // transformations void pushView(); - void popView(); - + void popView(); + // setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) void viewport(ofRectangle viewport); - void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=true); + void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = true); void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0); void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1); void setOrientation(ofOrientation orientation, bool vFlip); @@ -66,10 +64,10 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ int getViewportWidth() const; int getViewportHeight() const; bool isVFlipped() const; - + void setCoordHandedness(ofHandednessType handedness); ofHandednessType getCoordHandedness() const; - + //our openGL wrappers void pushMatrix(); void popMatrix(); @@ -82,41 +80,41 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ void rotateZRad(float radians); void rotateRad(float radians); void matrixMode(ofMatrixMode mode); - void loadIdentityMatrix (void); - void loadMatrix (const glm::mat4 & m); - void loadMatrix (const float * m); - void multMatrix (const glm::mat4 & m); - void multMatrix (const float * m); + void loadIdentityMatrix(void); + void loadMatrix(const glm::mat4 & m); + void loadMatrix(const float * m); + void multMatrix(const glm::mat4 & m); + void multMatrix(const float * m); void loadViewMatrix(const glm::mat4 & m); void multViewMatrix(const glm::mat4 & m); - /// \brief Queries the current OpenGL matrix state - /// - /// Returns the specified matrix as held by the renderer's current matrix - /// stack. - /// - /// You can query one of the following: - /// - /// [OF_MATRIX_MODELVIEW | OF_MATRIX_PROJECTION | OF_MATRIX_TEXTURE] - /// - /// Each query will return the state of the matrix as it was uploaded to - /// the shader currently bound. - /// - /// \param matrixMode_ Which matrix mode to query - /// \note If an invalid matrixMode is queried, this method will return the - /// identity matrix, and print an error message. + /// \brief Queries the current OpenGL matrix state + /// + /// Returns the specified matrix as held by the renderer's current matrix + /// stack. + /// + /// You can query one of the following: + /// + /// [OF_MATRIX_MODELVIEW | OF_MATRIX_PROJECTION | OF_MATRIX_TEXTURE] + /// + /// Each query will return the state of the matrix as it was uploaded to + /// the shader currently bound. + /// + /// \param matrixMode_ Which matrix mode to query + /// \note If an invalid matrixMode is queried, this method will return the + /// identity matrix, and print an error message. glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const; glm::mat4 getCurrentOrientationMatrix() const; glm::mat4 getCurrentViewMatrix() const; glm::mat4 getCurrentNormalMatrix() const; glm::mat4 getCurrentModelMatrix() const; - + glm::vec3 getCurrentEyePosition() const; - + // screen coordinate things / default gl values void setupGraphicDefaults(); void setupScreen(); - + // drawing modes void setFillMode(ofFillFlag fill); ofFillFlag getFillMode(); @@ -131,34 +129,33 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ void disablePointSprites(); void enableAntiAliasing(); void disableAntiAliasing(); - + // color options void setColor(float r, float g, float b); // 0-1 void setColor(float r, float g, float b, float a); // 0-1 void setColor(const ofFloatColor & color); void setColor(const ofFloatColor & color, float _a); void setColor(float gray); // new set a color as grayscale with one argument - void setHexColor( int hexColor ); // hex, like web 0xFF0033; + void setHexColor(int hexColor); // hex, like web 0xFF0033; + + void setBitmapTextMode(ofBitmapMode mode); - void setBitmapTextMode(ofDrawBitmapMode mode); - // bg color ofFloatColor getBackgroundColor(); void setBackgroundColor(const ofFloatColor & c); void background(const ofFloatColor & c); void background(float brightness); - void background(int hexColor, int _a=255); - void background(float r, float g, float b, float a=1.f); + void background(int hexColor, int _a = 255); + void background(float r, float g, float b, float a = 1.f); bool getBackgroundAuto(); - void setBackgroundAuto(bool bManual); // default is true - + void setBackgroundAuto(bool bManual); // default is true + void clear(); - void clear(float r, float g, float b, float a=0.f); - void clear(float brightness, float a=0.f); + void clear(float r, float g, float b, float a = 0.f); + void clear(float brightness, float a = 0.f); void clearAlpha(); - - + // drawing void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const; void drawRectangle(float x, float y, float z, float w, float h) const; @@ -168,7 +165,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ void drawString(std::string text, float x, float y, float z) const; void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const; - void enableTextureTarget(const ofTexture & tex, int textureLocation); void disableTextureTarget(int textureTarget, int textureLocation); void setAlphaMaskTex(const ofTexture & tex); @@ -198,7 +194,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ #endif void unbind(const ofFbo & fbo); - void begin(const ofFbo & fbo, ofFboMode mode); + void begin(const ofFbo & fbo, ofFboMode mode); void end(const ofFbo & fbo); ofStyle getStyle() const; @@ -211,23 +207,23 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ const ofShader * getVideoShader(const ofBaseVideoDraws & video) const; void setVideoShaderUniforms(const ofBaseVideoDraws & video, const ofShader & shader) const; - void enableLighting(); - void disableLighting(); - bool getLightingEnabled(); - void enableSeparateSpecularLight(){} - void disableSeparateSpecularLight(){} - void setSmoothLighting(bool b){} - void setGlobalAmbientColor(const ofFloatColor& c){} - void enableLight(int lightIndex); - void disableLight(int lightIndex); - void setLightSpotlightCutOff(int lightIndex, float spotCutOff){} - void setLightSpotConcentration(int lightIndex, float exponent){} - void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic ){} - void setLightAmbientColor(int lightIndex, const ofFloatColor& c){} - void setLightDiffuseColor(int lightIndex, const ofFloatColor& c){} - void setLightSpecularColor(int lightIndex, const ofFloatColor& c){} - void setLightPosition(int lightIndex, const glm::vec4 & position){} - void setLightSpotDirection(int lightIndex, const glm::vec4 & direction){} + void enableLighting(); + void disableLighting(); + bool getLightingEnabled(); + void enableSeparateSpecularLight() { } + void disableSeparateSpecularLight() { } + void setSmoothLighting(bool b) { } + void setGlobalAmbientColor(const ofFloatColor & c) { } + void enableLight(int lightIndex); + void disableLight(int lightIndex); + void setLightSpotlightCutOff(int lightIndex, float spotCutOff) { } + void setLightSpotConcentration(int lightIndex, float exponent) { } + void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic) { } + void setLightAmbientColor(int lightIndex, const ofFloatColor & c) { } + void setLightDiffuseColor(int lightIndex, const ofFloatColor & c) { } + void setLightSpecularColor(int lightIndex, const ofFloatColor & c) { } + void setLightPosition(int lightIndex, const glm::vec4 & position) { } + void setLightSpotDirection(int lightIndex, const glm::vec4 & direction) { } std::string defaultVertexShaderHeader(GLenum textureTarget); std::string defaultFragmentShaderHeader(GLenum textureTarget); @@ -242,8 +238,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ of3dGraphics & get3dGraphics(); private: - - ofPolyline circlePolyline; mutable ofMesh circleMesh; mutable ofMesh triangleMesh; @@ -253,7 +247,6 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ void uploadCurrentMatrix(); - void startSmoothing(); void endSmoothing(); @@ -264,12 +257,11 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ void setAttributes(bool vertices, bool color, bool tex, bool normals); void setAlphaBitmapText(bool bitmapText); - ofMatrixStack matrixStack; bool bBackgroundAuto; int major, minor; - + const ofShader * currentShader; bool verticesEnabled, colorsEnabled, texCoordsEnabled, normalsEnabled, bitmapStringEnabled; @@ -281,14 +273,14 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ const ofBaseMaterial * currentMaterial; int alphaMaskTextureTarget; - - const ofShadow* currentShadow; + + const ofShadow * currentShadow; bool bIsShadowDepthPass; GLenum shadowCubeFace; bool bCustomShadowShader = false; ofStyle currentStyle; - std::deque styleHistory; + std::deque styleHistory; of3dGraphics graphics3d; ofBitmapFont bitmapFont; ofPath path; @@ -305,12 +297,12 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ ofShader defaultOESTexColor; ofShader defaultOESTexNoColor; #endif - + ofShader alphaMaskRectShader; ofShader alphaMask2DShader; - + ofShader bitmapStringShader; - + ofShader shaderPlanarYUY2; ofShader shaderNV12; ofShader shaderNV21; @@ -319,7 +311,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ ofShader shaderNV12Rect; ofShader shaderNV21Rect; ofShader shaderPlanarYUVRect; - + glm::vec3 currentEyePos; //void setDefaultFramebufferId(const GLuint& fboId_); ///< windowing systems might use this to set the default framebuffer for this renderer. @@ -330,7 +322,7 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{ //void setFramebufferId(const GLuint& fboId_); // sets the current framebuffer id // framebuffer binding state - std::deque framebufferIdStack; ///< keeps track of currently bound framebuffers - GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0 - GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target + std::deque framebufferIdStack; ///< keeps track of currently bound framebuffers + GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0 + GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target }; diff --git a/libs/openFrameworks/gl/ofGLRenderer.cpp b/libs/openFrameworks/gl/ofGLRenderer.cpp index b09839b32a8..27c763144a0 100644 --- a/libs/openFrameworks/gl/ofGLRenderer.cpp +++ b/libs/openFrameworks/gl/ofGLRenderer.cpp @@ -1,29 +1,29 @@ -#include "ofGLRenderer.h" -#include "ofMesh.h" -#include "ofPath.h" #include "of3dPrimitives.h" #include "ofBitmapFont.h" +#include "ofCamera.h" +#include "ofFbo.h" +#include "ofGLRenderer.h" #include "ofGLUtils.h" #include "ofImage.h" -#include "ofFbo.h" #include "ofLight.h" -#include "ofCamera.h" -#include "ofTrueTypeFont.h" -#include "ofNode.h" -#include "ofVideoBaseTypes.h" #include "ofMaterial.h" +#include "ofMesh.h" +#include "ofNode.h" +#include "ofPath.h" +#include "ofTrueTypeFont.h" #include "ofVboMesh.h" +#include "ofVideoBaseTypes.h" using std::shared_ptr; -using std::vector; using std::string; +using std::vector; -const std::string ofGLRenderer::TYPE="GL"; +const std::string ofGLRenderer::TYPE = "GL"; //---------------------------------------------------------- ofGLRenderer::ofGLRenderer(const ofAppBaseWindow * _window) -:matrixStack(_window) -,graphics3d(this){ + : matrixStack(_window) + , graphics3d(this) { bBackgroundAuto = true; linePoints.resize(2); @@ -40,7 +40,7 @@ ofGLRenderer::ofGLRenderer(const ofAppBaseWindow * _window) path.setUseShapeColor(false); } -void ofGLRenderer::setup(){ +void ofGLRenderer::setup() { #ifdef TARGET_OPENGLES // OpenGL ES might have set a default frame buffer for // MSAA rendering to the window, bypassing ofFbo, so we @@ -50,14 +50,14 @@ void ofGLRenderer::setup(){ GLint currentFrameBuffer; glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFrameBuffer); defaultFramebufferId = currentFrameBuffer; - currentFramebufferId = defaultFramebufferId; + currentFramebufferId = defaultFramebufferId; #endif setupGraphicDefaults(); viewport(); setupScreenPerspective(); } -void ofGLRenderer::startRender(){ +void ofGLRenderer::startRender() { currentFramebufferId = defaultFramebufferId; framebufferIdStack.push_back(defaultFramebufferId); matrixStack.setRenderSurface(*window); @@ -65,260 +65,260 @@ void ofGLRenderer::startRender(){ // to do non auto clear on PC for now - we do something like "single" buffering -- // it's not that pretty but it work for the most part - #ifdef TARGET_WIN32 - if (getBackgroundAuto() == false){ - glDrawBuffer (GL_FRONT); +#ifdef TARGET_WIN32 + if (getBackgroundAuto() == false) { + glDrawBuffer(GL_FRONT); } - #endif +#endif - if ( getBackgroundAuto() ){// || ofGetFrameNum() < 3){ + if (getBackgroundAuto()) { // || ofGetFrameNum() < 3){ background(currentStyle.bgColor); } } -void ofGLRenderer::finishRender(){ +void ofGLRenderer::finishRender() { matrixStack.clearStacks(); framebufferIdStack.clear(); } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const{ - if (currentStyle.smoothing) const_cast(this)->startSmoothing(); +void ofGLRenderer::draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const { + if (currentStyle.smoothing) const_cast(this)->startSmoothing(); #ifndef TARGET_OPENGLES - glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); - if(vertexData.getNumVertices()){ - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &vertexData.getVerticesPointer()->x); - } - if(vertexData.getNumNormals() && useNormals){ - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(GL_FLOAT, sizeof(glm::vec3), &vertexData.getNormalsPointer()->x); - } - if(vertexData.getNumColors() && useColors){ - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4,GL_FLOAT, sizeof(ofFloatColor), &vertexData.getColorsPointer()->r); - } + glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); + if (vertexData.getNumVertices()) { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &vertexData.getVerticesPointer()->x); + } + if (vertexData.getNumNormals() && useNormals) { + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(GL_FLOAT, sizeof(glm::vec3), &vertexData.getNormalsPointer()->x); + } + if (vertexData.getNumColors() && useColors) { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, sizeof(ofFloatColor), &vertexData.getColorsPointer()->r); + } - if(vertexData.getNumTexCoords() && useTextures){ - if(textureLocationsEnabled.size() == 0){ - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(glm::vec2), &vertexData.getTexCoordsPointer()->x); - }else{ - std::set::iterator textureLocation = textureLocationsEnabled.begin(); - for(;textureLocation!=textureLocationsEnabled.end();textureLocation++){ - glActiveTexture(GL_TEXTURE0+*textureLocation); - glClientActiveTexture(GL_TEXTURE0+*textureLocation); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(glm::vec2), &vertexData.getTexCoordsPointer()->x); - } - glActiveTexture(GL_TEXTURE0); - glClientActiveTexture(GL_TEXTURE0); + if (vertexData.getNumTexCoords() && useTextures) { + if (textureLocationsEnabled.size() == 0) { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(glm::vec2), &vertexData.getTexCoordsPointer()->x); + } else { + std::set::iterator textureLocation = textureLocationsEnabled.begin(); + for (; textureLocation != textureLocationsEnabled.end(); textureLocation++) { + glActiveTexture(GL_TEXTURE0 + *textureLocation); + glClientActiveTexture(GL_TEXTURE0 + *textureLocation); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(glm::vec2), &vertexData.getTexCoordsPointer()->x); } + glActiveTexture(GL_TEXTURE0); + glClientActiveTexture(GL_TEXTURE0); } + } - if(vertexData.getNumIndices()){ + if (vertexData.getNumIndices()) { // This is never executed right now but this branch of the ifdef should be used for GLES 3 so let's keep it for future uses #ifdef TARGET_OPENGLES - glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer()); + glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(), GL_UNSIGNED_SHORT, vertexData.getIndexPointer()); #else - glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(),GL_UNSIGNED_INT,vertexData.getIndexPointer()); + glDrawElements(ofGetGLPrimitiveMode(vertexData.getMode()), vertexData.getNumIndices(), GL_UNSIGNED_INT, vertexData.getIndexPointer()); #endif - }else{ - glDrawArrays(ofGetGLPrimitiveMode(vertexData.getMode()), 0, vertexData.getNumVertices()); - } + } else { + glDrawArrays(ofGetGLPrimitiveMode(vertexData.getMode()), 0, vertexData.getNumVertices()); + } - if(vertexData.getNumColors() && useColors){ - glDisableClientState(GL_COLOR_ARRAY); - } - if(vertexData.getNumNormals() && useNormals){ - glDisableClientState(GL_NORMAL_ARRAY); - } - if(vertexData.getNumTexCoords() && useTextures){ - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } - glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); + if (vertexData.getNumColors() && useColors) { + glDisableClientState(GL_COLOR_ARRAY); + } + if (vertexData.getNumNormals() && useNormals) { + glDisableClientState(GL_NORMAL_ARRAY); + } + if (vertexData.getNumTexCoords() && useTextures) { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } + glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); #else - if(vertexData.getNumVertices()){ - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_FLOAT, sizeof(typename ofMesh::VertexType), vertexData.getVerticesPointer()); - } - if(vertexData.getNumNormals() && useNormals){ - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(GL_FLOAT, 0, vertexData.getNormalsPointer()); - } - if(vertexData.getNumColors() && useColors){ - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4,GL_FLOAT, sizeof(ofFloatColor), vertexData.getColorsPointer()); - } + if (vertexData.getNumVertices()) { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, sizeof(typename ofMesh::VertexType), vertexData.getVerticesPointer()); + } + if (vertexData.getNumNormals() && useNormals) { + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(GL_FLOAT, 0, vertexData.getNormalsPointer()); + } + if (vertexData.getNumColors() && useColors) { + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, sizeof(ofFloatColor), vertexData.getColorsPointer()); + } - if(vertexData.getNumTexCoords() && useTextures){ - if(textureLocationsEnabled.size() == 0){ - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(typename ofMesh::TexCoordType), &vertexData.getTexCoordsPointer()->x); - }else{ - std::set::iterator textureLocation = textureLocationsEnabled.begin(); - for(;textureLocation!=textureLocationsEnabled.end();textureLocation++){ - glActiveTexture(GL_TEXTURE0+*textureLocation); - glClientActiveTexture(GL_TEXTURE0+*textureLocation); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, sizeof(typename ofMesh::TexCoordType), &vertexData.getTexCoordsPointer()->x); - } - glActiveTexture(GL_TEXTURE0); - glClientActiveTexture(GL_TEXTURE0); + if (vertexData.getNumTexCoords() && useTextures) { + if (textureLocationsEnabled.size() == 0) { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(typename ofMesh::TexCoordType), &vertexData.getTexCoordsPointer()->x); + } else { + std::set::iterator textureLocation = textureLocationsEnabled.begin(); + for (; textureLocation != textureLocationsEnabled.end(); textureLocation++) { + glActiveTexture(GL_TEXTURE0 + *textureLocation); + glClientActiveTexture(GL_TEXTURE0 + *textureLocation); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, sizeof(typename ofMesh::TexCoordType), &vertexData.getTexCoordsPointer()->x); } + glActiveTexture(GL_TEXTURE0); + glClientActiveTexture(GL_TEXTURE0); } + } - GLenum drawMode; - switch(renderType){ - case OF_MESH_POINTS: - drawMode = GL_POINTS; - break; - case OF_MESH_WIREFRAME: - drawMode = GL_LINES; - break; - case OF_MESH_FILL: - drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); - break; - default: - drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); - break; - } + GLenum drawMode; + switch (renderType) { + case OF_MESH_POINTS: + drawMode = GL_POINTS; + break; + case OF_MESH_WIREFRAME: + drawMode = GL_LINES; + break; + case OF_MESH_FILL: + drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); + break; + default: + drawMode = ofGetGLPrimitiveMode(vertexData.getMode()); + break; + } - if(vertexData.getNumIndices()){ - glDrawElements(drawMode, vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer()); - }else{ - glDrawArrays(drawMode, 0, vertexData.getNumVertices()); - } - if(vertexData.getNumColors() && useColors){ - glDisableClientState(GL_COLOR_ARRAY); - } - if(vertexData.getNumNormals() && useNormals){ - glDisableClientState(GL_NORMAL_ARRAY); - } - if(vertexData.getNumTexCoords() && useTextures){ - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - } + if (vertexData.getNumIndices()) { + glDrawElements(drawMode, vertexData.getNumIndices(), GL_UNSIGNED_SHORT, vertexData.getIndexPointer()); + } else { + glDrawArrays(drawMode, 0, vertexData.getNumVertices()); + } + if (vertexData.getNumColors() && useColors) { + glDisableClientState(GL_COLOR_ARRAY); + } + if (vertexData.getNumNormals() && useNormals) { + glDisableClientState(GL_NORMAL_ARRAY); + } + if (vertexData.getNumTexCoords() && useTextures) { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + } #endif - if (currentStyle.smoothing) const_cast(this)->endSmoothing(); + if (currentStyle.smoothing) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const{ - drawInstanced(mesh,renderType,1); +void ofGLRenderer::draw(const ofVboMesh & mesh, ofPolyRenderMode renderType) const { + drawInstanced(mesh, renderType, 1); } //---------------------------------------------------------- -void ofGLRenderer::drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const{ - if(mesh.getNumVertices()==0) return; +void ofGLRenderer::drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const { + if (mesh.getNumVertices() == 0) return; GLuint mode = ofGetGLPrimitiveMode(mesh.getMode()); #ifndef TARGET_OPENGLES glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType)); - if(mesh.getNumIndices() && renderType!=OF_MESH_POINTS){ + if (mesh.getNumIndices() && renderType != OF_MESH_POINTS) { if (primCount <= 1) { - drawElements(mesh.getVbo(),mode,mesh.getNumIndices()); + drawElements(mesh.getVbo(), mode, mesh.getNumIndices()); } else { - drawElementsInstanced(mesh.getVbo(),mode,mesh.getNumIndices(),primCount); + drawElementsInstanced(mesh.getVbo(), mode, mesh.getNumIndices(), primCount); } - }else{ + } else { if (primCount <= 1) { - draw(mesh.getVbo(),mode,0,mesh.getNumVertices()); + draw(mesh.getVbo(), mode, 0, mesh.getNumVertices()); } else { - drawInstanced(mesh.getVbo(),mode,0,mesh.getNumVertices(),primCount); + drawInstanced(mesh.getVbo(), mode, 0, mesh.getNumVertices(), primCount); } } - glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); + glPolygonMode(GL_FRONT_AND_BACK, currentStyle.bFill ? GL_FILL : GL_LINE); #else - if(renderType == OF_MESH_POINTS){ - draw(mesh.getVbo(),GL_POINTS,0,mesh.getNumVertices()); - }else if(renderType == OF_MESH_WIREFRAME){ - if(mesh.getNumIndices()){ - drawElements(mesh.getVbo(),GL_LINES,mesh.getNumIndices()); - }else{ - draw(mesh.getVbo(),GL_LINES,0,mesh.getNumVertices()); + if (renderType == OF_MESH_POINTS) { + draw(mesh.getVbo(), GL_POINTS, 0, mesh.getNumVertices()); + } else if (renderType == OF_MESH_WIREFRAME) { + if (mesh.getNumIndices()) { + drawElements(mesh.getVbo(), GL_LINES, mesh.getNumIndices()); + } else { + draw(mesh.getVbo(), GL_LINES, 0, mesh.getNumVertices()); } - }else{ - if(mesh.getNumIndices()){ - drawElements(mesh.getVbo(),mode,mesh.getNumIndices()); - }else{ - draw(mesh.getVbo(),mode,0,mesh.getNumVertices()); + } else { + if (mesh.getNumIndices()) { + drawElements(mesh.getVbo(), mode, mesh.getNumIndices()); + } else { + draw(mesh.getVbo(), mode, 0, mesh.getNumVertices()); } } #endif } //---------------------------------------------------------- -void ofGLRenderer::draw( const of3dPrimitive& model, ofPolyRenderMode renderType) const{ - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); - if(model.isUsingVbo()){ - draw(static_cast(model.getMesh()),renderType); - }else{ - draw(model.getMesh(),renderType); +void ofGLRenderer::draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const { + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); + if (model.isUsingVbo()) { + draw(static_cast(model.getMesh()), renderType); + } else { + draw(model.getMesh(), renderType); } - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofNode& node) const{ - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); +void ofGLRenderer::draw(const ofNode & node) const { + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); node.customDraw(this); - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofPolyline & poly) const{ - if(!poly.getVertices().empty()) { +void ofGLRenderer::draw(const ofPolyline & poly) const { + if (!poly.getVertices().empty()) { // use smoothness, if requested: - if (currentStyle.smoothing) const_cast(this)->startSmoothing(); + if (currentStyle.smoothing) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &poly.getVertices()[0].x); - glDrawArrays(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size()); + glDrawArrays(poly.isClosed() ? GL_LINE_LOOP : GL_LINE_STRIP, 0, poly.size()); // use smoothness, if requested: - if (currentStyle.smoothing) const_cast(this)->endSmoothing(); + if (currentStyle.smoothing) const_cast(this)->endSmoothing(); } } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofPath & shape) const{ +void ofGLRenderer::draw(const ofPath & shape) const { ofFloatColor prevColor; - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { prevColor = currentStyle.color; } - ofGLRenderer * mut_this = const_cast(this); - if(shape.isFilled()){ + ofGLRenderer * mut_this = const_cast(this); + if (shape.isFilled()) { const ofMesh & mesh = shape.getTessellation(); - if(shape.getUseShapeColor()){ - mut_this->setColor( shape.getFillColor(),shape.getFillColor().a); + if (shape.getUseShapeColor()) { + mut_this->setColor(shape.getFillColor(), shape.getFillColor().a); } - draw(mesh,OF_MESH_FILL); + draw(mesh, OF_MESH_FILL); } - if(shape.hasOutline()){ + if (shape.hasOutline()) { float lineWidth = currentStyle.lineWidth; - if(shape.getUseShapeColor()){ - mut_this->setColor( shape.getStrokeColor(), shape.getStrokeColor().a); + if (shape.getUseShapeColor()) { + mut_this->setColor(shape.getStrokeColor(), shape.getStrokeColor().a); } - mut_this->setLineWidth( shape.getStrokeWidth() ); + mut_this->setLineWidth(shape.getStrokeWidth()); const vector & outlines = shape.getOutline(); - for(int i=0; i<(int)outlines.size(); i++) + for (int i = 0; i < (int)outlines.size(); i++) draw(outlines[i]); mut_this->setLineWidth(lineWidth); } - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { mut_this->setColor(prevColor); } } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLRenderer::draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLRenderer") << "drawing an unallocated texture"; } @@ -326,13 +326,13 @@ void ofGLRenderer::draw(const ofImage & image, float x, float y, float z, float } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLRenderer") << "draw(): texture is not allocated"; } @@ -340,13 +340,13 @@ void ofGLRenderer::draw(const ofFloatImage & image, float x, float y, float z, f } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(image.isUsingTexture()){ - const ofTexture& tex = image.getTexture(); - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (image.isUsingTexture()) { + const ofTexture & tex = image.getTexture(); + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLRenderer") << "draw(): texture is not allocated"; } @@ -354,28 +354,28 @@ void ofGLRenderer::draw(const ofShortImage & image, float x, float y, float z, f } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofTexture & tex, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - if(tex.isAllocated()) { - const_cast(this)->bind(tex,0); - draw(tex.getMeshForSubsection(x,y,z,w,h,sx,sy,sw,sh,isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(tex,0); +void ofGLRenderer::draw(const ofTexture & tex, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + if (tex.isAllocated()) { + const_cast(this)->bind(tex, 0); + draw(tex.getMeshForSubsection(x, y, z, w, h, sx, sy, sw, sh, isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(tex, 0); } else { ofLogWarning("ofGLRenderer") << "draw(): texture is not allocated"; } } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{ - if(video.isInitialized() && video.isUsingTexture()){ - const_cast(this)->bind(video); - draw(video.getTexture().getMeshForSubsection(x,y,0,w,h,0,0,video.getWidth(),video.getHeight(),isVFlipped(),currentStyle.rectMode),OF_MESH_FILL,false,true,false); - const_cast(this)->unbind(video); +void ofGLRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const { + if (video.isInitialized() && video.isUsingTexture()) { + const_cast(this)->bind(video); + draw(video.getTexture().getMeshForSubsection(x, y, 0, w, h, 0, 0, video.getWidth(), video.getHeight(), isVFlipped(), currentStyle.rectMode), OF_MESH_FILL, false, true, false); + const_cast(this)->unbind(video); } } //---------------------------------------------------------- -void ofGLRenderer::draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const{ - if(vbo.getUsingVerts()) { +void ofGLRenderer::draw(const ofVbo & vbo, GLuint drawMode, int first, int total) const { + if (vbo.getUsingVerts()) { vbo.bind(); glDrawArrays(drawMode, first, total); vbo.unbind(); @@ -383,21 +383,21 @@ void ofGLRenderer::draw(const ofVbo & vbo, GLuint drawMode, int first, int total } //---------------------------------------------------------- -void ofGLRenderer::drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements) const{ - if(vbo.getUsingVerts()) { +void ofGLRenderer::drawElements(const ofVbo & vbo, GLuint drawMode, int amt, int offsetelements) const { + if (vbo.getUsingVerts()) { vbo.bind(); #ifdef TARGET_OPENGLES - glDrawElements(drawMode, amt, GL_UNSIGNED_SHORT, (void*)(sizeof(ofIndexType) * offsetelements)); + glDrawElements(drawMode, amt, GL_UNSIGNED_SHORT, (void *)(sizeof(ofIndexType) * offsetelements)); #else - glDrawElements(drawMode, amt, GL_UNSIGNED_INT, (void*)(sizeof(ofIndexType) * offsetelements)); + glDrawElements(drawMode, amt, GL_UNSIGNED_INT, (void *)(sizeof(ofIndexType) * offsetelements)); #endif vbo.unbind(); } } //---------------------------------------------------------- -void ofGLRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const{ - if(vbo.getUsingVerts()) { +void ofGLRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, int total, int primCount) const { + if (vbo.getUsingVerts()) { vbo.bind(); #ifdef TARGET_OPENGLES // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 @@ -413,8 +413,8 @@ void ofGLRenderer::drawInstanced(const ofVbo & vbo, GLuint drawMode, int first, } //---------------------------------------------------------- -void ofGLRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const{ - if(vbo.getUsingVerts()) { +void ofGLRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int amt, int primCount) const { + if (vbo.getUsingVerts()) { vbo.bind(); #ifdef TARGET_OPENGLES // todo: activate instancing once OPENGL ES supports instancing, starting with version 3.0 @@ -430,50 +430,50 @@ void ofGLRenderer::drawElementsInstanced(const ofVbo & vbo, GLuint drawMode, int } //---------------------------------------------------------- -ofPath & ofGLRenderer::getPath(){ +ofPath & ofGLRenderer::getPath() { return path; } //---------------------------------------------------------- -void ofGLRenderer::bind(const ofBaseVideoDraws & video){ - if(video.isInitialized() && video.isUsingTexture()){ - bind(video.getTexture(),0); +void ofGLRenderer::bind(const ofBaseVideoDraws & video) { + if (video.isInitialized() && video.isUsingTexture()) { + bind(video.getTexture(), 0); } } //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofBaseVideoDraws & video){ - if(video.isInitialized() && video.isUsingTexture()){ +void ofGLRenderer::unbind(const ofBaseVideoDraws & video) { + if (video.isInitialized() && video.isUsingTexture()) { video.getTexture().unbind(); } } //---------------------------------------------------------- -void ofGLRenderer::bind(const ofShader & shader){ +void ofGLRenderer::bind(const ofShader & shader) { glUseProgram(shader.getProgram()); } //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofShader & shader){ +void ofGLRenderer::unbind(const ofShader & shader) { glUseProgram(0); } //---------------------------------------------------------- -void ofGLRenderer::begin(const ofFbo & fbo, ofFboMode mode){ +void ofGLRenderer::begin(const ofFbo & fbo, ofFboMode mode) { pushView(); pushStyle(); - if(mode & OF_FBOMODE_MATRIXFLIP){ - matrixStack.setRenderSurface(fbo); - }else{ - matrixStack.setRenderSurfaceNoMatrixFlip(fbo); - } + if (mode & OF_FBOMODE_MATRIXFLIP) { + matrixStack.setRenderSurface(fbo); + } else { + matrixStack.setRenderSurfaceNoMatrixFlip(fbo); + } viewport(); - if(mode & OF_FBOMODE_PERSPECTIVE){ + if (mode & OF_FBOMODE_PERSPECTIVE) { setupScreenPerspective(); - }else{ + } else { glm::mat4 m = glm::mat4(1.0); glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(m)); - m = matrixStack.getOrientationMatrixInverse() * m; + m = matrixStack.getOrientationMatrixInverse() * m; ofMatrixMode currentMode = matrixStack.getCurrentMatrixMode(); matrixStack.matrixMode(OF_MATRIX_PROJECTION); matrixStack.loadMatrix(m); @@ -485,7 +485,7 @@ void ofGLRenderer::begin(const ofFbo & fbo, ofFboMode mode){ } //---------------------------------------------------------- -void ofGLRenderer::end(const ofFbo & fbo){ +void ofGLRenderer::end(const ofFbo & fbo) { unbind(fbo); matrixStack.setRenderSurface(*window); popStyle(); @@ -493,10 +493,10 @@ void ofGLRenderer::end(const ofFbo & fbo){ } //---------------------------------------------------------- -void ofGLRenderer::bind(const ofFbo & fbo){ - if (currentFramebufferId == fbo.getId()){ - ofLogWarning() << "Framebuffer with id: " << fbo.getId() << " cannot be bound onto itself. \n" << - "Most probably you forgot to end() the current framebuffer before calling begin() again or you forgot to allocate() before calling begin()."; +void ofGLRenderer::bind(const ofFbo & fbo) { + if (currentFramebufferId == fbo.getId()) { + ofLogWarning() << "Framebuffer with id: " << fbo.getId() << " cannot be bound onto itself. \n" + << "Most probably you forgot to end() the current framebuffer before calling begin() again or you forgot to allocate() before calling begin()."; return; } // this method could just as well have been placed in ofBaseGLRenderer @@ -511,10 +511,10 @@ void ofGLRenderer::bind(const ofFbo & fbo){ #ifndef TARGET_OPENGLES //---------------------------------------------------------- -void ofGLRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fboDst, int attachmentPoint){ - if (currentFramebufferId == fboSrc.getId()){ - ofLogWarning() << "Framebuffer with id: " << fboSrc.getId() << " cannot be bound onto itself. \n" << - "Most probably you forgot to end() the current framebuffer before calling getTexture()."; +void ofGLRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fboDst, int attachmentPoint) { + if (currentFramebufferId == fboSrc.getId()) { + ofLogWarning() << "Framebuffer with id: " << fboSrc.getId() << " cannot be bound onto itself. \n" + << "Most probably you forgot to end() the current framebuffer before calling getTexture()."; return; } // this method could just as well have been placed in ofBaseGLRenderer @@ -532,11 +532,11 @@ void ofGLRenderer::bindForBlitting(const ofFbo & fboSrc, ofFbo & fboDst, int att #endif //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofFbo & fbo){ - if(framebufferIdStack.empty()){ +void ofGLRenderer::unbind(const ofFbo & fbo) { + if (framebufferIdStack.empty()) { ofLogError() << "unbalanced fbo bind/unbind binding default framebuffer"; currentFramebufferId = defaultFramebufferId; - }else{ + } else { currentFramebufferId = framebufferIdStack.back(); framebufferIdStack.pop_back(); } @@ -545,7 +545,7 @@ void ofGLRenderer::unbind(const ofFbo & fbo){ } //---------------------------------------------------------- -void ofGLRenderer::bind(const ofBaseMaterial & material){ +void ofGLRenderer::bind(const ofBaseMaterial & material) { ofFloatColor diffuse = material.getDiffuseColor(); ofFloatColor specular = material.getSpecularColor(); ofFloatColor ambient = material.getAmbientColor(); @@ -561,7 +561,7 @@ void ofGLRenderer::bind(const ofBaseMaterial & material){ } //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofBaseMaterial &){ +void ofGLRenderer::unbind(const ofBaseMaterial &) { // Set default material colors and properties ofMaterial::Data defaultData; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &defaultData.diffuse.r); @@ -571,7 +571,7 @@ void ofGLRenderer::unbind(const ofBaseMaterial &){ glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &defaultData.shininess); // Re-enable global color as material ambient and diffuse materialBound = false; - if(lightingEnabled){ + if (lightingEnabled) { setColor(currentStyle.color); } } @@ -593,21 +593,20 @@ void ofGLRenderer::unbind(const ofShadow & shadow) {}; void ofGLRenderer::unbind(const ofShadow & shadow, GLenum aCubeFace) {}; //---------------------------------------------------------- -void ofGLRenderer::bind(const ofTexture & texture, int location){ +void ofGLRenderer::bind(const ofTexture & texture, int location) { //we could check if it has been allocated - but we don't do that in draw() - if(texture.getAlphaMask()){ + if (texture.getAlphaMask()) { setAlphaMaskTex(*texture.getAlphaMask()); } - enableTextureTarget(texture,location); - + enableTextureTarget(texture, location); - if(ofGetUsingNormalizedTexCoords()) { + if (ofGetUsingNormalizedTexCoords()) { matrixMode(OF_MATRIX_TEXTURE); pushMatrix(); glm::mat4 m = glm::mat4(1.0); #ifndef TARGET_OPENGLES - if(texture.texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) + if (texture.texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB) m = glm::scale(m, glm::vec3(texture.texData.width, texture.texData.height, 1.0f)); else #endif @@ -616,22 +615,22 @@ void ofGLRenderer::bind(const ofTexture & texture, int location){ loadMatrix(m); matrixMode(OF_MATRIX_MODELVIEW); } - if(texture.isUsingTextureMatrix()){ + if (texture.isUsingTextureMatrix()) { matrixMode(OF_MATRIX_TEXTURE); - if(!ofGetUsingNormalizedTexCoords()) pushMatrix(); + if (!ofGetUsingNormalizedTexCoords()) pushMatrix(); multMatrix(texture.getTextureMatrix()); matrixMode(OF_MATRIX_MODELVIEW); } } //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofTexture & texture, int location){ - disableTextureTarget(texture.texData.textureTarget,location); - if(texture.getAlphaMask()){ +void ofGLRenderer::unbind(const ofTexture & texture, int location) { + disableTextureTarget(texture.texData.textureTarget, location); + if (texture.getAlphaMask()) { disableAlphaMask(); } - if(texture.isUsingTextureMatrix() || ofGetUsingNormalizedTexCoords()) { + if (texture.isUsingTextureMatrix() || ofGetUsingNormalizedTexCoords()) { matrixMode(OF_MATRIX_TEXTURE); popMatrix(); matrixMode(OF_MATRIX_MODELVIEW); @@ -639,10 +638,10 @@ void ofGLRenderer::unbind(const ofTexture & texture, int location){ } //---------------------------------------------------------- -void ofGLRenderer::bind(const ofCamera & camera, const ofRectangle & _viewport){ +void ofGLRenderer::bind(const ofCamera & camera, const ofRectangle & _viewport) { pushView(); viewport(_viewport); - setOrientation(matrixStack.getOrientation(),camera.isVFlipped()); + setOrientation(matrixStack.getOrientation(), camera.isVFlipped()); matrixMode(OF_MATRIX_PROJECTION); loadMatrix(camera.getProjectionMatrix(_viewport)); matrixMode(OF_MATRIX_MODELVIEW); @@ -650,7 +649,7 @@ void ofGLRenderer::bind(const ofCamera & camera, const ofRectangle & _viewport){ } //---------------------------------------------------------- -void ofGLRenderer::unbind(const ofCamera & camera){ +void ofGLRenderer::unbind(const ofCamera & camera) { popView(); } @@ -660,10 +659,10 @@ void ofGLRenderer::pushView() { glm::mat4 m = glm::mat4(1.0); ofMatrixMode matrixMode = matrixStack.getCurrentMatrixMode(); - glGetFloatv(GL_PROJECTION_MATRIX,glm::value_ptr(m)); + glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(m)); matrixStack.matrixMode(OF_MATRIX_PROJECTION); matrixStack.loadMatrix(m); - glGetFloatv(GL_MODELVIEW_MATRIX,glm::value_ptr(m)); + glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(m)); matrixStack.matrixMode(OF_MATRIX_MODELVIEW); matrixStack.loadMatrix(m); @@ -672,7 +671,6 @@ void ofGLRenderer::pushView() { matrixStack.pushView(); } - //---------------------------------------------------------- void ofGLRenderer::popView() { matrixStack.popView(); @@ -690,80 +688,78 @@ void ofGLRenderer::popView() { viewport(matrixStack.getCurrentViewport()); } - //---------------------------------------------------------- -void ofGLRenderer::viewport(ofRectangle viewport_){ +void ofGLRenderer::viewport(ofRectangle viewport_) { viewport(viewport_.x, viewport_.y, viewport_.width, viewport_.height, isVFlipped()); } //---------------------------------------------------------- void ofGLRenderer::viewport(float x, float y, float width, float height, bool vflip) { - matrixStack.viewport(x,y,width,height,vflip); + matrixStack.viewport(x, y, width, height, vflip); ofRectangle nativeViewport = matrixStack.getNativeViewport(); - glViewport(nativeViewport.x,nativeViewport.y,nativeViewport.width,nativeViewport.height); + glViewport(nativeViewport.x, nativeViewport.y, nativeViewport.width, nativeViewport.height); } //---------------------------------------------------------- -ofRectangle ofGLRenderer::getCurrentViewport() const{ +ofRectangle ofGLRenderer::getCurrentViewport() const { getNativeViewport(); return matrixStack.getCurrentViewport(); } //---------------------------------------------------------- -ofRectangle ofGLRenderer::getNativeViewport() const{ - GLint viewport[4]; // Where The Viewport Values Will Be Stored +ofRectangle ofGLRenderer::getNativeViewport() const { + GLint viewport[4]; // Where The Viewport Values Will Be Stored glGetIntegerv(GL_VIEWPORT, viewport); - ofGLRenderer * mutRenderer = const_cast(this); + ofGLRenderer * mutRenderer = const_cast(this); ofRectangle nativeViewport(viewport[0], viewport[1], viewport[2], viewport[3]); mutRenderer->matrixStack.nativeViewport(nativeViewport); return nativeViewport; } //---------------------------------------------------------- -int ofGLRenderer::getViewportWidth() const{ +int ofGLRenderer::getViewportWidth() const { return getCurrentViewport().width; } //---------------------------------------------------------- -int ofGLRenderer::getViewportHeight() const{ +int ofGLRenderer::getViewportHeight() const { return getCurrentViewport().height; } //---------------------------------------------------------- void ofGLRenderer::setCoordHandedness(ofHandednessType handedness) { - } //---------------------------------------------------------- -ofHandednessType ofGLRenderer::getCoordHandedness() const{ +ofHandednessType ofGLRenderer::getCoordHandedness() const { return matrixStack.getHandedness(); } //---------------------------------------------------------- -void ofGLRenderer::setOrientation(ofOrientation orientation, bool vFlip){ - matrixStack.setOrientation(orientation,vFlip); +void ofGLRenderer::setOrientation(ofOrientation orientation, bool vFlip) { + matrixStack.setOrientation(orientation, vFlip); } //---------------------------------------------------------- -bool ofGLRenderer::isVFlipped() const{ +bool ofGLRenderer::isVFlipped() const { return matrixStack.isVFlipped(); } //---------------------------------------------------------- -bool ofGLRenderer::texturesNeedVFlip() const{ +bool ofGLRenderer::texturesNeedVFlip() const { return matrixStack.customMatrixNeedsFlip(); } //---------------------------------------------------------- void ofGLRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { float viewW, viewH; - if(width<0 || height<0){ + if (width < 0 || height < 0) { ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; - }else{ + } else { viewW = width; viewH = height; } @@ -773,30 +769,29 @@ void ofGLRenderer::setupScreenPerspective(float width, float height, float fov, float halfFov = glm::pi() * fov / 360.0f; float theTan = tanf(halfFov); float dist = eyeY / theTan; - float aspect = (float) viewW / viewH; - - if(nearDist == 0) nearDist = dist / 10.0f; - if(farDist == 0) farDist = dist * 10.0f; + float aspect = (float)viewW / viewH; + if (nearDist == 0) nearDist = dist / 10.0f; + if (farDist == 0) farDist = dist * 10.0f; matrixMode(OF_MATRIX_PROJECTION); glm::mat4 persp = glm::perspective(ofDegToRad(fov), aspect, nearDist, farDist); - loadMatrix( persp ); + loadMatrix(persp); matrixMode(OF_MATRIX_MODELVIEW); - glm::mat4 lookAtMat = glm::lookAt( glm::vec3(eyeX, eyeY, dist), glm::vec3(eyeX, eyeY, 0), glm::vec3(0, 1, 0) ); + glm::mat4 lookAtMat = glm::lookAt(glm::vec3(eyeX, eyeY, dist), glm::vec3(eyeX, eyeY, 0), glm::vec3(0, 1, 0)); loadViewMatrix(lookAtMat); } //---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist) { float viewW, viewH; - if(width<0 || height<0){ + if (width < 0 || height < 0) { ofRectangle currentViewport = getCurrentViewport(); viewW = currentViewport.width; viewH = currentViewport.height; - }else{ + } else { viewW = width; viewH = height; } @@ -808,12 +803,11 @@ void ofGLRenderer::setupScreenOrtho(float width, float height, float nearDist, f matrixMode(OF_MATRIX_MODELVIEW); loadViewMatrix(glm::mat4(1.0)); - } //---------------------------------------------------------- //Resets openGL parameters back to OF defaults -void ofGLRenderer::setupGraphicDefaults(){ +void ofGLRenderer::setupGraphicDefaults() { glEnableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); @@ -824,128 +818,128 @@ void ofGLRenderer::setupGraphicDefaults(){ } //---------------------------------------------------------- -void ofGLRenderer::setupScreen(){ - setupScreenPerspective(); // assume defaults +void ofGLRenderer::setupScreen() { + setupScreenPerspective(); // assume defaults } //---------------------------------------------------------- -void ofGLRenderer::setCircleResolution(int res){ - if((int)circlePolyline.size()!=res+1){ +void ofGLRenderer::setCircleResolution(int res) { + if ((int)circlePolyline.size() != res + 1) { circlePolyline.clear(); - circlePolyline.arc(0,0,0,1,1,0,360,res); + circlePolyline.arc(0, 0, 0, 1, 1, 0, 360, res); circlePoints.resize(circlePolyline.size()); path.setCircleResolution(res); } currentStyle.circleResolution = res; } -void ofGLRenderer::setPolyMode(ofPolyWindingMode mode){ +void ofGLRenderer::setPolyMode(ofPolyWindingMode mode) { currentStyle.polyMode = mode; path.setPolyWindingMode(mode); } //our openGL wrappers //---------------------------------------------------------- -void ofGLRenderer::pushMatrix(){ +void ofGLRenderer::pushMatrix() { glPushMatrix(); } //---------------------------------------------------------- -void ofGLRenderer::popMatrix(){ +void ofGLRenderer::popMatrix() { glPopMatrix(); } //---------------------------------------------------------- -void ofGLRenderer::translate(const glm::vec3& p){ +void ofGLRenderer::translate(const glm::vec3 & p) { glTranslatef(p.x, p.y, p.z); } //---------------------------------------------------------- -void ofGLRenderer::translate(float x, float y, float z){ +void ofGLRenderer::translate(float x, float y, float z) { glTranslatef(x, y, z); } //---------------------------------------------------------- -void ofGLRenderer::scale(float xAmnt, float yAmnt, float zAmnt){ +void ofGLRenderer::scale(float xAmnt, float yAmnt, float zAmnt) { glScalef(xAmnt, yAmnt, zAmnt); } //---------------------------------------------------------- -void ofGLRenderer::rotateDeg(float degrees, float vecX, float vecY, float vecZ){ +void ofGLRenderer::rotateDeg(float degrees, float vecX, float vecY, float vecZ) { glRotatef(degrees, vecX, vecY, vecZ); } //---------------------------------------------------------- -void ofGLRenderer::rotateXDeg(float degrees){ +void ofGLRenderer::rotateXDeg(float degrees) { glRotatef(degrees, 1, 0, 0); } //---------------------------------------------------------- -void ofGLRenderer::rotateYDeg(float degrees){ +void ofGLRenderer::rotateYDeg(float degrees) { glRotatef(degrees, 0, 1, 0); } //---------------------------------------------------------- -void ofGLRenderer::rotateZDeg(float degrees){ +void ofGLRenderer::rotateZDeg(float degrees) { glRotatef(degrees, 0, 0, 1); } //same as ofRotateZ //---------------------------------------------------------- -void ofGLRenderer::rotateDeg(float degrees){ +void ofGLRenderer::rotateDeg(float degrees) { glRotatef(degrees, 0, 0, 1); } //---------------------------------------------------------- -void ofGLRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ){ +void ofGLRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ) { glRotatef(ofRadToDeg(radians), vecX, vecY, vecZ); } //---------------------------------------------------------- -void ofGLRenderer::rotateXRad(float radians){ +void ofGLRenderer::rotateXRad(float radians) { glRotatef(ofRadToDeg(radians), 1, 0, 0); } //---------------------------------------------------------- -void ofGLRenderer::rotateYRad(float radians){ +void ofGLRenderer::rotateYRad(float radians) { glRotatef(ofRadToDeg(radians), 0, 1, 0); } //---------------------------------------------------------- -void ofGLRenderer::rotateZRad(float radians){ +void ofGLRenderer::rotateZRad(float radians) { glRotatef(ofRadToDeg(radians), 0, 0, 1); } //same as ofRotateZ //---------------------------------------------------------- -void ofGLRenderer::rotateRad(float radians){ +void ofGLRenderer::rotateRad(float radians) { glRotatef(ofRadToDeg(radians), 0, 0, 1); } //---------------------------------------------------------- -void ofGLRenderer::matrixMode(ofMatrixMode mode){ - glMatrixMode(GL_MODELVIEW+mode); +void ofGLRenderer::matrixMode(ofMatrixMode mode) { + glMatrixMode(GL_MODELVIEW + mode); matrixStack.matrixMode(mode); } //---------------------------------------------------------- -void ofGLRenderer::loadIdentityMatrix (void){ +void ofGLRenderer::loadIdentityMatrix(void) { loadMatrix(glm::mat4(1.0)); } //---------------------------------------------------------- -void ofGLRenderer::loadMatrix (const glm::mat4 & m){ - if(matrixStack.getCurrentMatrixMode()==OF_MATRIX_PROJECTION){ +void ofGLRenderer::loadMatrix(const glm::mat4 & m) { + if (matrixStack.getCurrentMatrixMode() == OF_MATRIX_PROJECTION) { matrixStack.loadMatrix(m); glLoadMatrixf(glm::value_ptr(matrixStack.getProjectionMatrix())); - }else{ + } else { glLoadMatrixf(glm::value_ptr(m)); } } //---------------------------------------------------------- -void ofGLRenderer::loadMatrix (const float *m){ - loadMatrix( glm::make_mat4(m) ); +void ofGLRenderer::loadMatrix(const float * m) { + loadMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- @@ -965,18 +959,18 @@ void ofGLRenderer::loadMatrix (const float *m){ glm::mat4 ofGLRenderer::getCurrentMatrix(ofMatrixMode matrixMode_) const { glm::mat4 mat = glm::mat4(1.0); switch (matrixMode_) { - case OF_MATRIX_MODELVIEW: - glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(mat)); - break; - case OF_MATRIX_PROJECTION: - glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(mat)); - break; - case OF_MATRIX_TEXTURE: - glGetFloatv(GL_TEXTURE_MATRIX, glm::value_ptr(mat)); - break; - default: - ofLogWarning() << "Invalid getCurrentMatrix query"; - break; + case OF_MATRIX_MODELVIEW: + glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(mat)); + break; + case OF_MATRIX_PROJECTION: + glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(mat)); + break; + case OF_MATRIX_TEXTURE: + glGetFloatv(GL_TEXTURE_MATRIX, glm::value_ptr(mat)); + break; + default: + ofLogWarning() << "Invalid getCurrentMatrix query"; + break; } return mat; } @@ -987,41 +981,41 @@ glm::mat4 ofGLRenderer::getCurrentOrientationMatrix() const { } //---------------------------------------------------------- -void ofGLRenderer::multMatrix (const glm::mat4 & m){ - if(matrixStack.getCurrentMatrixMode()==OF_MATRIX_PROJECTION){ +void ofGLRenderer::multMatrix(const glm::mat4 & m) { + if (matrixStack.getCurrentMatrixMode() == OF_MATRIX_PROJECTION) { glm::mat4 current = glm::mat4(1.0); glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(current)); - if(matrixStack.customMatrixNeedsFlip()){ - current = glm::scale(current, glm::vec3(1,-1,1)); + if (matrixStack.customMatrixNeedsFlip()) { + current = glm::scale(current, glm::vec3(1, -1, 1)); } matrixStack.loadMatrix(current); matrixStack.multMatrix(m); glLoadMatrixf(glm::value_ptr(matrixStack.getProjectionMatrix())); - }else{ + } else { glMultMatrixf(glm::value_ptr(m)); } } //---------------------------------------------------------- -void ofGLRenderer::multMatrix (const float *m){ - multMatrix( glm::make_mat4(m) ); +void ofGLRenderer::multMatrix(const float * m) { + multMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- -void ofGLRenderer::loadViewMatrix(const glm::mat4 & m){ +void ofGLRenderer::loadViewMatrix(const glm::mat4 & m) { int matrixMode; - glGetIntegerv(GL_MATRIX_MODE,&matrixMode); + glGetIntegerv(GL_MATRIX_MODE, &matrixMode); matrixStack.loadViewMatrix(m); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(glm::value_ptr(m)); glMatrixMode(matrixMode); - if(lightingEnabled){ - for(size_t i=0;i lightData = ofLightsData()[i].lock(); - if(lightData && lightData->isEnabled){ + if (lightData && lightData->isEnabled) { glLightfv(GL_LIGHT0 + lightData->glIndex, GL_POSITION, &lightData->position.x); - if(lightData->lightType == OF_LIGHT_SPOT || lightData->lightType == OF_LIGHT_AREA) { + if (lightData->lightType == OF_LIGHT_SPOT || lightData->lightType == OF_LIGHT_AREA) { glLightfv(GL_LIGHT0 + lightData->glIndex, GL_SPOT_DIRECTION, &lightData->direction.x); } } @@ -1030,35 +1024,35 @@ void ofGLRenderer::loadViewMatrix(const glm::mat4 & m){ } //---------------------------------------------------------- -void ofGLRenderer::multViewMatrix(const glm::mat4 & m){ +void ofGLRenderer::multViewMatrix(const glm::mat4 & m) { ofLogError() << "mutlViewMatrix not implemented on fixed GL renderer"; } //---------------------------------------------------------- -glm::mat4 ofGLRenderer::getCurrentViewMatrix() const{ +glm::mat4 ofGLRenderer::getCurrentViewMatrix() const { return matrixStack.getViewMatrix(); } //---------------------------------------------------------- -glm::mat4 ofGLRenderer::getCurrentNormalMatrix() const{ +glm::mat4 ofGLRenderer::getCurrentNormalMatrix() const { return glm::transpose(glm::inverse(getCurrentMatrix(OF_MATRIX_MODELVIEW))); } //---------------------------------------------------------- -void ofGLRenderer::setColor(const ofFloatColor & color){ - setColor(color.r,color.g,color.b,color.a); +void ofGLRenderer::setColor(const ofFloatColor & color) { + setColor(color.r, color.g, color.b, color.a); } //---------------------------------------------------------- -void ofGLRenderer::setColor(const ofFloatColor & color, float _a){ - setColor(color.r,color.g,color.b,_a); +void ofGLRenderer::setColor(const ofFloatColor & color, float _a) { + setColor(color.r, color.g, color.b, _a); } //---------------------------------------------------------- -void ofGLRenderer::setColor(float r, float g, float b){ - currentStyle.color.set(r,g,b); - glColor4f(r,g,b,1.f); - if(lightingEnabled && !materialBound){ +void ofGLRenderer::setColor(float r, float g, float b) { + currentStyle.color.set(r, g, b); + glColor4f(r, g, b, 1.f); + if (lightingEnabled && !materialBound) { #ifndef TARGET_OPENGLES glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); #endif @@ -1066,12 +1060,11 @@ void ofGLRenderer::setColor(float r, float g, float b){ } } - //---------------------------------------------------------- -void ofGLRenderer::setColor(float r, float g, float b, float a){ - currentStyle.color.set(r,g,b,a); - glColor4f(r,g,b,a); - if(lightingEnabled && !materialBound){ +void ofGLRenderer::setColor(float r, float g, float b, float a) { + currentStyle.color.set(r, g, b, a); + glColor4f(r, g, b, a); + if (lightingEnabled && !materialBound) { #ifndef TARGET_OPENGLES glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); #endif @@ -1080,20 +1073,20 @@ void ofGLRenderer::setColor(float r, float g, float b, float a){ } //---------------------------------------------------------- -void ofGLRenderer::setColor(float gray){ +void ofGLRenderer::setColor(float gray) { setColor(gray, gray, gray); } //---------------------------------------------------------- -void ofGLRenderer::setHexColor(int hexColor){ +void ofGLRenderer::setHexColor(int hexColor) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - setColor((float)r/255.f,(float)g/255.f,(float)b/255.f); + setColor((float)r / 255.f, (float)g / 255.f, (float)b / 255.f); } //---------------------------------------------------------- -void ofGLRenderer::clear(){ +void ofGLRenderer::clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -1117,30 +1110,30 @@ void ofGLRenderer::clearAlpha() { } //---------------------------------------------------------- -void ofGLRenderer::setBackgroundAuto(bool bAuto){ +void ofGLRenderer::setBackgroundAuto(bool bAuto) { bBackgroundAuto = bAuto; } //---------------------------------------------------------- -bool ofGLRenderer::getBackgroundAuto(){ +bool ofGLRenderer::getBackgroundAuto() { return bBackgroundAuto; } //---------------------------------------------------------- -ofFloatColor ofGLRenderer::getBackgroundColor(){ +ofFloatColor ofGLRenderer::getBackgroundColor() { return currentStyle.bgColor; } //---------------------------------------------------------- -void ofGLRenderer::setBackgroundColor(const ofFloatColor & color){ +void ofGLRenderer::setBackgroundColor(const ofFloatColor & color) { currentStyle.bgColor = color; - glClearColor(currentStyle.bgColor[0],currentStyle.bgColor[1],currentStyle.bgColor[2], currentStyle.bgColor[3]); + glClearColor(currentStyle.bgColor[0], currentStyle.bgColor[1], currentStyle.bgColor[2], currentStyle.bgColor[3]); } //---------------------------------------------------------- -void ofGLRenderer::background(const ofFloatColor & c){ +void ofGLRenderer::background(const ofFloatColor & c) { setBackgroundColor(c); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } //---------------------------------------------------------- @@ -1149,69 +1142,69 @@ void ofGLRenderer::background(float brightness) { } //---------------------------------------------------------- -void ofGLRenderer::background(int hexColor, int _a){ +void ofGLRenderer::background(int hexColor, int _a) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - background ( (float)r/255.f, (float)g/255.f, (float)b/255.f, _a/255.f); + background((float)r / 255.f, (float)g / 255.f, (float)b / 255.f, _a / 255.f); } //---------------------------------------------------------- -void ofGLRenderer::background(float r, float g, float b, float a){ - background(ofFloatColor(r,g,b,a)); +void ofGLRenderer::background(float r, float g, float b, float a) { + background(ofFloatColor(r, g, b, a)); } //---------------------------------------------------------- -void ofGLRenderer::setFillMode(ofFillFlag fill){ - currentStyle.bFill = (fill==OF_FILLED); - if(currentStyle.bFill){ +void ofGLRenderer::setFillMode(ofFillFlag fill) { + currentStyle.bFill = (fill == OF_FILLED); + if (currentStyle.bFill) { path.setFilled(true); path.setStrokeWidth(0); - #ifndef TARGET_OPENGLES - // GLES does not support glPolygonMode - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - #endif - }else{ +#ifndef TARGET_OPENGLES + // GLES does not support glPolygonMode + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); +#endif + } else { path.setFilled(false); path.setStrokeWidth(currentStyle.lineWidth); - #ifndef TARGET_OPENGLES - // GLES does not support glPolygonMode - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - #endif +#ifndef TARGET_OPENGLES + // GLES does not support glPolygonMode + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); +#endif } } //---------------------------------------------------------- -ofFillFlag ofGLRenderer::getFillMode(){ - if(currentStyle.bFill){ +ofFillFlag ofGLRenderer::getFillMode() { + if (currentStyle.bFill) { return OF_FILLED; - }else{ + } else { return OF_OUTLINE; } } //---------------------------------------------------------- -void ofGLRenderer::setRectMode(ofRectMode mode){ +void ofGLRenderer::setRectMode(ofRectMode mode) { currentStyle.rectMode = mode; } //---------------------------------------------------------- -ofRectMode ofGLRenderer::getRectMode(){ +ofRectMode ofGLRenderer::getRectMode() { return currentStyle.rectMode; } //---------------------------------------------------------- -void ofGLRenderer::setLineWidth(float lineWidth){ +void ofGLRenderer::setLineWidth(float lineWidth) { currentStyle.lineWidth = lineWidth; - if(!currentStyle.bFill){ + if (!currentStyle.bFill) { path.setStrokeWidth(lineWidth); } glLineWidth(lineWidth); } //---------------------------------------------------------- -void ofGLRenderer::setDepthTest(bool depthTest){ - if(depthTest) { +void ofGLRenderer::setDepthTest(bool depthTest) { + if (depthTest) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); @@ -1219,16 +1212,15 @@ void ofGLRenderer::setDepthTest(bool depthTest){ } //---------------------------------------------------------- -void ofGLRenderer::setLineSmoothing(bool smooth){ +void ofGLRenderer::setLineSmoothing(bool smooth) { currentStyle.smoothing = smooth; } - //---------------------------------------------------------- -void ofGLRenderer::startSmoothing(){ - #ifndef TARGET_OPENGLES - glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); - #endif +void ofGLRenderer::startSmoothing() { +#ifndef TARGET_OPENGLES + glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT); +#endif glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_LINE_SMOOTH); @@ -1238,89 +1230,88 @@ void ofGLRenderer::startSmoothing(){ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - //---------------------------------------------------------- -void ofGLRenderer::endSmoothing(){ - #ifndef TARGET_OPENGLES - glPopAttrib(); - #endif +void ofGLRenderer::endSmoothing() { +#ifndef TARGET_OPENGLES + glPopAttrib(); +#endif } //---------------------------------------------------------- -void ofGLRenderer::setBlendMode(ofBlendMode blendMode){ - switch (blendMode){ - case OF_BLENDMODE_DISABLED: - glDisable(GL_BLEND); - break; +void ofGLRenderer::setBlendMode(ofBlendMode blendMode) { + switch (blendMode) { + case OF_BLENDMODE_DISABLED: + glDisable(GL_BLEND); + break; - case OF_BLENDMODE_ALPHA:{ - glEnable(GL_BLEND); - #ifndef TARGET_OPENGLES - glBlendEquation(GL_FUNC_ADD); - #endif - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - } + case OF_BLENDMODE_ALPHA: { + glEnable(GL_BLEND); +#ifndef TARGET_OPENGLES + glBlendEquation(GL_FUNC_ADD); +#endif + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; + } - case OF_BLENDMODE_ADD:{ - glEnable(GL_BLEND); - #ifndef TARGET_OPENGLES - glBlendEquation(GL_FUNC_ADD); - #endif - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - } + case OF_BLENDMODE_ADD: { + glEnable(GL_BLEND); +#ifndef TARGET_OPENGLES + glBlendEquation(GL_FUNC_ADD); +#endif + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; + } - case OF_BLENDMODE_MULTIPLY:{ - glEnable(GL_BLEND); - #ifndef TARGET_OPENGLES - glBlendEquation(GL_FUNC_ADD); - #endif - glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA /* GL_ZERO or GL_ONE_MINUS_SRC_ALPHA */); - break; - } + case OF_BLENDMODE_MULTIPLY: { + glEnable(GL_BLEND); +#ifndef TARGET_OPENGLES + glBlendEquation(GL_FUNC_ADD); +#endif + glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA /* GL_ZERO or GL_ONE_MINUS_SRC_ALPHA */); + break; + } - case OF_BLENDMODE_SCREEN:{ - glEnable(GL_BLEND); - #ifndef TARGET_OPENGLES - glBlendEquation(GL_FUNC_ADD); - #endif - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); - break; - } + case OF_BLENDMODE_SCREEN: { + glEnable(GL_BLEND); +#ifndef TARGET_OPENGLES + glBlendEquation(GL_FUNC_ADD); +#endif + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE); + break; + } - case OF_BLENDMODE_SUBTRACT:{ - glEnable(GL_BLEND); - #ifndef TARGET_OPENGLES - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - #else - ofLogWarning("ofGLRenderer") << "OF_BLENDMODE_SUBTRACT not currently supported on OpenGL ES"; - #endif - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - break; - } + case OF_BLENDMODE_SUBTRACT: { + glEnable(GL_BLEND); +#ifndef TARGET_OPENGLES + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); +#else + ofLogWarning("ofGLRenderer") << "OF_BLENDMODE_SUBTRACT not currently supported on OpenGL ES"; +#endif + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; + } - default: - break; + default: + break; } currentStyle.blendingMode = blendMode; } //---------------------------------------------------------- -void ofGLRenderer::setBitmapTextMode(ofDrawBitmapMode mode){ - currentStyle.drawBitmapMode = mode; +void ofGLRenderer::setBitmapTextMode(ofBitmapMode mode) { + currentStyle.bitmapMode = mode; } //---------------------------------------------------------- -ofStyle ofGLRenderer::getStyle() const{ +ofStyle ofGLRenderer::getStyle() const { return currentStyle; } //---------------------------------------------------------- -void ofGLRenderer::pushStyle(){ +void ofGLRenderer::pushStyle() { styleHistory.push_back(currentStyle); //if we are over the max number of styles we have set, then delete the oldest styles. - if( styleHistory.size() > OF_MAX_STYLE_HISTORY ){ + if (styleHistory.size() > OF_MAX_STYLE_HISTORY) { styleHistory.pop_front(); //should we warn here? ofLogWarning("ofGraphics") << "ofPushStyle(): maximum number of style pushes << " << OF_MAX_STYLE_HISTORY << " reached, did you forget to pop somewhere?"; @@ -1328,15 +1319,15 @@ void ofGLRenderer::pushStyle(){ } //---------------------------------------------------------- -void ofGLRenderer::popStyle(){ - if( styleHistory.size() ){ +void ofGLRenderer::popStyle() { + if (styleHistory.size()) { setStyle(styleHistory.back()); styleHistory.pop_back(); } } //---------------------------------------------------------- -void ofGLRenderer::setStyle(const ofStyle & style){ +void ofGLRenderer::setStyle(const ofStyle & style) { //color setColor((int)style.color.r, (int)style.color.g, (int)style.color.b, (int)style.color.a); @@ -1360,9 +1351,9 @@ void ofGLRenderer::setStyle(const ofStyle & style){ setPolyMode(style.polyMode); //fill - if(style.bFill ){ + if (style.bFill) { setFillMode(OF_FILLED); - }else{ + } else { setFillMode(OF_OUTLINE); } @@ -1380,13 +1371,13 @@ void ofGLRenderer::setStyle(const ofStyle & style){ } //---------------------------------------------------------- -void ofGLRenderer::setCurveResolution(int resolution){ +void ofGLRenderer::setCurveResolution(int resolution) { currentStyle.curveResolution = resolution; path.setCurveResolution(resolution); } //---------------------------------------------------------- -void ofGLRenderer::enablePointSprites(){ +void ofGLRenderer::enablePointSprites() { #ifdef TARGET_OPENGLES glEnable(GL_POINT_SPRITE_OES); @@ -1400,11 +1391,10 @@ void ofGLRenderer::enablePointSprites(){ glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif - } //---------------------------------------------------------- -void ofGLRenderer::disablePointSprites(){ +void ofGLRenderer::disablePointSprites() { #ifdef TARGET_OPENGLES glDisable(GL_POINT_SPRITE_OES); @@ -1414,125 +1404,119 @@ void ofGLRenderer::disablePointSprites(){ } //---------------------------------------------------------- -void ofGLRenderer::enableAntiAliasing(){ +void ofGLRenderer::enableAntiAliasing() { glEnable(GL_MULTISAMPLE); } //---------------------------------------------------------- -void ofGLRenderer::disableAntiAliasing(){ +void ofGLRenderer::disableAntiAliasing() { glDisable(GL_MULTISAMPLE); } //---------------------------------------------------------- -void ofGLRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{ - linePoints[0] = {x1,y1,z1}; - linePoints[1] = {x2,y2,z2}; +void ofGLRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const { + linePoints[0] = { x1, y1, z1 }; + linePoints[1] = { x2, y2, z2 }; // use smoothness, if requested: - if (currentStyle.smoothing) const_cast(this)->startSmoothing(); + if (currentStyle.smoothing) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), linePoints.data()); glDrawArrays(GL_LINES, 0, 2); // use smoothness, if requested: - if (currentStyle.smoothing) const_cast(this)->endSmoothing(); - + if (currentStyle.smoothing) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::drawRectangle(float x, float y, float z,float w, float h) const{ +void ofGLRenderer::drawRectangle(float x, float y, float z, float w, float h) const { - if (currentStyle.rectMode == OF_RECTMODE_CORNER){ - rectPoints[0] = {x,y,z}; - rectPoints[1] = {x+w, y, z}; - rectPoints[2] = {x+w, y+h, z}; - rectPoints[3] = {x, y+h, z}; - }else{ - rectPoints[0] = {x-w/2.0f, y-h/2.0f, z}; - rectPoints[1] = {x+w/2.0f, y-h/2.0f, z}; - rectPoints[2] = {x+w/2.0f, y+h/2.0f, z}; - rectPoints[3] = {x-w/2.0f, y+h/2.0f, z}; + if (currentStyle.rectMode == OF_RECTMODE_CORNER) { + rectPoints[0] = { x, y, z }; + rectPoints[1] = { x + w, y, z }; + rectPoints[2] = { x + w, y + h, z }; + rectPoints[3] = { x, y + h, z }; + } else { + rectPoints[0] = { x - w / 2.0f, y - h / 2.0f, z }; + rectPoints[1] = { x + w / 2.0f, y - h / 2.0f, z }; + rectPoints[2] = { x + w / 2.0f, y + h / 2.0f, z }; + rectPoints[3] = { x - w / 2.0f, y + h / 2.0f, z }; } // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &rectPoints[0].x); glDrawArrays(currentStyle.bFill ? GL_TRIANGLE_FAN : GL_LINE_LOOP, 0, 4); // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); - + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{ - triPoints[0] = {x1,y1,z1}; - triPoints[1] = {x2,y2,z2}; - triPoints[2] = {x3,y3,z3}; +void ofGLRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const { + triPoints[0] = { x1, y1, z1 }; + triPoints[1] = { x2, y2, z2 }; + triPoints[2] = { x3, y3, z3 }; // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &triPoints[0].x); glDrawArrays(currentStyle.bFill ? GL_TRIANGLE_FAN : GL_LINE_LOOP, 0, 3); // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); - + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::drawCircle(float x, float y, float z, float radius) const{ +void ofGLRenderer::drawCircle(float x, float y, float z, float radius) const { const auto & circleCache = circlePolyline.getVertices(); - for(size_t i=0;i(this)->startSmoothing(); + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &circlePoints[0].x); glDrawArrays(currentStyle.bFill ? GL_TRIANGLE_FAN : GL_LINE_STRIP, 0, circlePoints.size()); // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); - + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::drawEllipse(float x, float y, float z, float width, float height) const{ - float radiusX = width*0.5; - float radiusY = height*0.5; +void ofGLRenderer::drawEllipse(float x, float y, float z, float width, float height) const { + float radiusX = width * 0.5; + float radiusY = height * 0.5; const auto & circleCache = circlePolyline.getVertices(); - for(size_t i=0;i(this)->startSmoothing(); + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->startSmoothing(); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(glm::vec3), &circlePoints[0].x); glDrawArrays(currentStyle.bFill ? GL_TRIANGLE_FAN : GL_LINE_STRIP, 0, circlePoints.size()); // use smoothness, if requested: - if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); - + if (currentStyle.smoothing && !currentStyle.bFill) const_cast(this)->endSmoothing(); } //---------------------------------------------------------- -void ofGLRenderer::drawString(std::string textString, float x, float y, float z) const{ +void ofGLRenderer::drawString(std::string textString, float x, float y, float z) const { - ofGLRenderer * mutThis = const_cast(this); + ofGLRenderer * mutThis = const_cast(this); float sx = 0; float sy = 0; - /////////////////////////// // APPLY TRANSFORM / VIEW /////////////////////////// @@ -1545,125 +1529,122 @@ void ofGLRenderer::drawString(std::string textString, float x, float y, float z) ofRectangle rViewport; bool vflipped = isVFlipped(); - switch (currentStyle.drawBitmapMode) { - - case OF_BITMAPMODE_SIMPLE: + switch (currentStyle.bitmapMode) { - sx += x; - sy += y; - break; + case OF_BITMAPMODE_SIMPLE: - case OF_BITMAPMODE_SCREEN: + sx += x; + sy += y; + break; - hasViewport = true; - mutThis->pushView(); + case OF_BITMAPMODE_SCREEN: - rViewport = matrixStack.getFullSurfaceViewport(); - mutThis->viewport(rViewport); + hasViewport = true; + mutThis->pushView(); - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->loadIdentityMatrix(); - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->loadIdentityMatrix(); + rViewport = matrixStack.getFullSurfaceViewport(); + mutThis->viewport(rViewport); - mutThis->translate(-1, 1, 0); - mutThis->scale(2/rViewport.width, -2/rViewport.height, 1); - mutThis->translate(x, rViewport.height - y, 0); - vflipped = false; - break; + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->loadIdentityMatrix(); + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->loadIdentityMatrix(); - case OF_BITMAPMODE_VIEWPORT: + mutThis->translate(-1, 1, 0); + mutThis->scale(2 / rViewport.width, -2 / rViewport.height, 1); + mutThis->translate(x, rViewport.height - y, 0); + vflipped = false; + break; - rViewport = getCurrentViewport(); + case OF_BITMAPMODE_VIEWPORT: - hasProjection = true; - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + rViewport = getCurrentViewport(); - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + hasProjection = true; + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); - mutThis->translate(-1, 1, 0); - mutThis->scale(2/rViewport.width, -2/rViewport.height, 1); - mutThis->translate(x, rViewport.height - y, 0); - vflipped = false; - break; + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); - case OF_BITMAPMODE_MODEL: + mutThis->translate(-1, 1, 0); + mutThis->scale(2 / rViewport.width, -2 / rViewport.height, 1); + mutThis->translate(x, rViewport.height - y, 0); + vflipped = false; + break; - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); + case OF_BITMAPMODE_MODEL: - mutThis->translate(x, y, z); - break; + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); - case OF_BITMAPMODE_MODEL_BILLBOARD: - { - //our aim here is to draw to screen - //at the viewport position related - //to the world position x,y,z + mutThis->translate(x, y, z); + break; - // tig: we want to get the signed normalised screen coordinates (-1,+1) of our point (x,y,z) - // that's projection * modelview * point in GLSL multiplication order - // then doing the good old (v + 1.0) / 2. to get unsigned normalized screen (0,1) coordinates. - // we then multiply x by width and y by height to get window coordinates. + case OF_BITMAPMODE_MODEL_BILLBOARD: { + //our aim here is to draw to screen + //at the viewport position related + //to the world position x,y,z - // previous implementations used gluProject, which made it incompatible with GLES (and the future) - // https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/gluProject.3.html - // - // this could probably be backported to the GL2 Renderer =) + // tig: we want to get the signed normalised screen coordinates (-1,+1) of our point (x,y,z) + // that's projection * modelview * point in GLSL multiplication order + // then doing the good old (v + 1.0) / 2. to get unsigned normalized screen (0,1) coordinates. + // we then multiply x by width and y by height to get window coordinates. - rViewport = getCurrentViewport(); + // previous implementations used gluProject, which made it incompatible with GLES (and the future) + // https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/gluProject.3.html + // + // this could probably be backported to the GL2 Renderer =) - glm::mat4 modelview = glm::mat4(1.0), projection = glm::mat4(1.0); - glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(modelview)); - glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(projection)); - glm::mat4 mat = matrixStack.getOrientationMatrixInverse() * projection * modelview; - glm::vec4 dScreen4 = mat * glm::vec4(x,y,z,1.0); - glm::vec3 dScreen = glm::vec3(dScreen4) / dScreen4.w; - dScreen += glm::vec3(1.0) ; - dScreen *= 0.5; + rViewport = getCurrentViewport(); - dScreen.x *= rViewport.width; - dScreen.x += rViewport.x; + glm::mat4 modelview = glm::mat4(1.0), projection = glm::mat4(1.0); + glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(modelview)); + glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(projection)); + glm::mat4 mat = matrixStack.getOrientationMatrixInverse() * projection * modelview; + glm::vec4 dScreen4 = mat * glm::vec4(x, y, z, 1.0); + glm::vec3 dScreen = glm::vec3(dScreen4) / dScreen4.w; + dScreen += glm::vec3(1.0); + dScreen *= 0.5; - dScreen.y *= rViewport.height; - dScreen.y += rViewport.y; + dScreen.x *= rViewport.width; + dScreen.x += rViewport.x; - if (dScreen.z >= 1){ - return; - } + dScreen.y *= rViewport.height; + dScreen.y += rViewport.y; + if (dScreen.z >= 1) { + return; + } - hasProjection = true; - mutThis->matrixMode(OF_MATRIX_PROJECTION); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + hasProjection = true; + mutThis->matrixMode(OF_MATRIX_PROJECTION); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); - hasModelView = true; - mutThis->matrixMode(OF_MATRIX_MODELVIEW); - mutThis->pushMatrix(); - mutThis->loadIdentityMatrix(); + hasModelView = true; + mutThis->matrixMode(OF_MATRIX_MODELVIEW); + mutThis->pushMatrix(); + mutThis->loadIdentityMatrix(); - mutThis->translate(-1, -1, 0); + mutThis->translate(-1, -1, 0); - mutThis->scale(2/rViewport.width, 2/rViewport.height, 1); + mutThis->scale(2 / rViewport.width, 2 / rViewport.height, 1); - mutThis->translate(dScreen.x, dScreen.y, 0); - } - break; + mutThis->translate(dScreen.x, dScreen.y, 0); + } break; - default: - break; + default: + break; } // remember the current blend mode so that we can restore it at the end of this method. GLint blend_src, blend_dst; - glGetIntegerv( GL_BLEND_SRC, &blend_src ); - glGetIntegerv( GL_BLEND_DST, &blend_dst ); + glGetIntegerv(GL_BLEND_SRC, &blend_src); + glGetIntegerv(GL_BLEND_DST, &blend_dst); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1675,10 +1656,10 @@ void ofGLRenderer::drawString(std::string textString, float x, float y, float z) glAlphaFunc(GL_GREATER, 0); #endif - ofMesh charMesh = bitmapFont.getMesh(textString,sx,sy,currentStyle.drawBitmapMode,vflipped); - mutThis->bind(bitmapFont.getTexture(),0); - draw(charMesh,OF_MESH_FILL,false,true,false); - mutThis->unbind(bitmapFont.getTexture(),0); + ofMesh charMesh = bitmapFont.getMesh(textString, sx, sy, currentStyle.bitmapMode, vflipped); + mutThis->bind(bitmapFont.getTexture(), 0); + draw(charMesh, OF_MESH_FILL, false, true, false); + mutThis->unbind(bitmapFont.getTexture(), 0); #ifndef TARGET_OPENGLES glPopAttrib(); @@ -1689,8 +1670,7 @@ void ofGLRenderer::drawString(std::string textString, float x, float y, float z) if (hasModelView) mutThis->popMatrix(); - if (hasProjection) - { + if (hasProjection) { mutThis->matrixMode(OF_MATRIX_PROJECTION); mutThis->popMatrix(); mutThis->matrixMode(OF_MATRIX_MODELVIEW); @@ -1698,38 +1678,37 @@ void ofGLRenderer::drawString(std::string textString, float x, float y, float z) if (hasViewport) mutThis->popView(); - } //---------------------------------------------------------- -void ofGLRenderer::drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const{ - ofGLRenderer * mutThis = const_cast(this); +void ofGLRenderer::drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const { + ofGLRenderer * mutThis = const_cast(this); bool blendEnabled = glIsEnabled(GL_BLEND); GLint blend_src, blend_dst; - glGetIntegerv( GL_BLEND_SRC, &blend_src ); - glGetIntegerv( GL_BLEND_DST, &blend_dst ); + glGetIntegerv(GL_BLEND_SRC, &blend_src); + glGetIntegerv(GL_BLEND_DST, &blend_dst); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - mutThis->bind(font.getFontTexture(),0); - draw(font.getStringMesh(text,x,y,isVFlipped()),OF_MESH_FILL); - mutThis->unbind(font.getFontTexture(),0); + mutThis->bind(font.getFontTexture(), 0); + draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL); + mutThis->unbind(font.getFontTexture(), 0); - if(!blendEnabled){ + if (!blendEnabled) { glDisable(GL_BLEND); } glBlendFunc(blend_src, blend_dst); } //---------------------------------------------------------- -void ofGLRenderer::enableTextureTarget(const ofTexture & tex, int textureLocation){ - glActiveTexture(GL_TEXTURE0+textureLocation); - glClientActiveTexture(GL_TEXTURE0+textureLocation); - glEnable( tex.getTextureData().textureTarget); - glBindTexture( tex.getTextureData().textureTarget, (GLuint)tex.getTextureData().textureID); +void ofGLRenderer::enableTextureTarget(const ofTexture & tex, int textureLocation) { + glActiveTexture(GL_TEXTURE0 + textureLocation); + glClientActiveTexture(GL_TEXTURE0 + textureLocation); + glEnable(tex.getTextureData().textureTarget); + glBindTexture(tex.getTextureData().textureTarget, (GLuint)tex.getTextureData().textureID); #ifndef TARGET_OPENGLES - if(tex.getTextureData().bufferId!=0){ + if (tex.getTextureData().bufferId != 0) { glTexBuffer(GL_TEXTURE_BUFFER, tex.getTextureData().glInternalFormat, tex.getTextureData().bufferId); } #endif @@ -1737,27 +1716,27 @@ void ofGLRenderer::enableTextureTarget(const ofTexture & tex, int textureLocatio } //---------------------------------------------------------- -void ofGLRenderer::disableTextureTarget(int textureTarget, int textureLocation){ - glActiveTexture(GL_TEXTURE0+textureLocation); - glBindTexture( textureTarget, 0); +void ofGLRenderer::disableTextureTarget(int textureTarget, int textureLocation) { + glActiveTexture(GL_TEXTURE0 + textureLocation); + glBindTexture(textureTarget, 0); glDisable(textureTarget); glActiveTexture(GL_TEXTURE0); textureLocationsEnabled.erase(textureLocation); } //---------------------------------------------------------- -void ofGLRenderer::setAlphaMaskTex(const ofTexture & tex){ +void ofGLRenderer::setAlphaMaskTex(const ofTexture & tex) { enableTextureTarget(tex, 1); alphaMaskTextureTarget = tex.getTextureData().textureTarget; } //---------------------------------------------------------- -void ofGLRenderer::disableAlphaMask(){ - disableTextureTarget(alphaMaskTextureTarget,1); +void ofGLRenderer::disableAlphaMask() { + disableTextureTarget(alphaMaskTextureTarget, 1); } //---------------------------------------------------------- -void ofGLRenderer::enableLighting(){ +void ofGLRenderer::enableLighting() { glEnable(GL_LIGHTING); lightingEnabled = true; setColor(currentStyle.color); @@ -1765,19 +1744,19 @@ void ofGLRenderer::enableLighting(){ // but if someone enables it between ofEnableLighting it'll be disabled // on ofDisableLighting. by now it seems the best option to not loose // performance when drawing lots of primitives - normalsEnabled = glIsEnabled( GL_NORMALIZE ); + normalsEnabled = glIsEnabled(GL_NORMALIZE); glEnable(GL_NORMALIZE); int matrixMode; - glGetIntegerv(GL_MATRIX_MODE,&matrixMode); + glGetIntegerv(GL_MATRIX_MODE, &matrixMode); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(glm::value_ptr(matrixStack.getViewMatrix())); - for(size_t i=0;i lightData = ofLightsData()[i].lock(); - if(lightData && lightData->isEnabled){ + if (lightData && lightData->isEnabled) { glLightfv(GL_LIGHT0 + lightData->glIndex, GL_POSITION, &lightData->position.x); - if(lightData->lightType == OF_LIGHT_SPOT || lightData->lightType == OF_LIGHT_AREA) { + if (lightData->lightType == OF_LIGHT_SPOT || lightData->lightType == OF_LIGHT_AREA) { glLightfv(GL_LIGHT0 + lightData->glIndex, GL_SPOT_DIRECTION, &lightData->direction.x); } } @@ -1787,99 +1766,101 @@ void ofGLRenderer::enableLighting(){ } //---------------------------------------------------------- -void ofGLRenderer::disableLighting(){ +void ofGLRenderer::disableLighting() { glDisable(GL_LIGHTING); - if(!normalsEnabled){ + if (!normalsEnabled) { glDisable(GL_NORMALIZE); } lightingEnabled = false; } //---------------------------------------------------------- -void ofGLRenderer::enableSeparateSpecularLight(){ +void ofGLRenderer::enableSeparateSpecularLight() { #ifndef TARGET_OPENGLES - glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR); + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); #endif } //---------------------------------------------------------- -void ofGLRenderer::disableSeparateSpecularLight(){ +void ofGLRenderer::disableSeparateSpecularLight() { #ifndef TARGET_OPENGLES - glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR); + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR); #endif } //---------------------------------------------------------- -bool ofGLRenderer::getLightingEnabled(){ +bool ofGLRenderer::getLightingEnabled() { return glIsEnabled(GL_LIGHTING); } //---------------------------------------------------------- -void ofGLRenderer::setSmoothLighting(bool b){ - if (b) glShadeModel(GL_SMOOTH); - else glShadeModel(GL_FLAT); +void ofGLRenderer::setSmoothLighting(bool b) { + if (b) + glShadeModel(GL_SMOOTH); + else + glShadeModel(GL_FLAT); } //---------------------------------------------------------- -void ofGLRenderer::setGlobalAmbientColor(const ofFloatColor& c){ - GLfloat cc[] = {c.r, c.g, c.b, c.a}; +void ofGLRenderer::setGlobalAmbientColor(const ofFloatColor & c) { + GLfloat cc[] = { c.r, c.g, c.b, c.a }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, cc); } //---------------------------------------------------------- -void ofGLRenderer::enableLight(int lightIndex){ +void ofGLRenderer::enableLight(int lightIndex) { enableLighting(); glEnable(GL_LIGHT0 + lightIndex); } //---------------------------------------------------------- -void ofGLRenderer::disableLight(int lightIndex){ - if(lightIndex!=-1) { +void ofGLRenderer::disableLight(int lightIndex) { + if (lightIndex != -1) { glDisable(GL_LIGHT0 + lightIndex); } } //---------------------------------------------------------- -void ofGLRenderer::setLightSpotlightCutOff(int lightIndex, float spotCutOff){ - glLightf(GL_LIGHT0 + lightIndex, GL_SPOT_CUTOFF, spotCutOff ); +void ofGLRenderer::setLightSpotlightCutOff(int lightIndex, float spotCutOff) { + glLightf(GL_LIGHT0 + lightIndex, GL_SPOT_CUTOFF, spotCutOff); } //---------------------------------------------------------- -void ofGLRenderer::setLightSpotConcentration(int lightIndex, float exponent){ +void ofGLRenderer::setLightSpotConcentration(int lightIndex, float exponent) { glLightf(GL_LIGHT0 + lightIndex, GL_SPOT_EXPONENT, exponent); } //---------------------------------------------------------- -void ofGLRenderer::setLightAttenuation(int lightIndex, float constant, float linear, float quadratic ){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightAttenuation(int lightIndex, float constant, float linear, float quadratic) { + if (lightIndex == -1) return; glLightf(GL_LIGHT0 + lightIndex, GL_CONSTANT_ATTENUATION, constant); glLightf(GL_LIGHT0 + lightIndex, GL_LINEAR_ATTENUATION, linear); glLightf(GL_LIGHT0 + lightIndex, GL_QUADRATIC_ATTENUATION, quadratic); } //---------------------------------------------------------- -void ofGLRenderer::setLightAmbientColor(int lightIndex, const ofFloatColor& c){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightAmbientColor(int lightIndex, const ofFloatColor & c) { + if (lightIndex == -1) return; glLightfv(GL_LIGHT0 + lightIndex, GL_AMBIENT, &c.r); } //---------------------------------------------------------- -void ofGLRenderer::setLightDiffuseColor(int lightIndex, const ofFloatColor& c){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightDiffuseColor(int lightIndex, const ofFloatColor & c) { + if (lightIndex == -1) return; glLightfv(GL_LIGHT0 + lightIndex, GL_DIFFUSE, &c.r); } //---------------------------------------------------------- -void ofGLRenderer::setLightSpecularColor(int lightIndex, const ofFloatColor& c){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightSpecularColor(int lightIndex, const ofFloatColor & c) { + if (lightIndex == -1) return; glLightfv(GL_LIGHT0 + lightIndex, GL_SPECULAR, &c.r); } //---------------------------------------------------------- -void ofGLRenderer::setLightPosition(int lightIndex, const glm::vec4 & position){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightPosition(int lightIndex, const glm::vec4 & position) { + if (lightIndex == -1) return; int matrixMode; - glGetIntegerv(GL_MATRIX_MODE,&matrixMode); + glGetIntegerv(GL_MATRIX_MODE, &matrixMode); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(glm::value_ptr(matrixStack.getViewMatrix())); @@ -1889,10 +1870,10 @@ void ofGLRenderer::setLightPosition(int lightIndex, const glm::vec4 & position){ } //---------------------------------------------------------- -void ofGLRenderer::setLightSpotDirection(int lightIndex, const glm::vec4 & direction){ - if(lightIndex==-1) return; +void ofGLRenderer::setLightSpotDirection(int lightIndex, const glm::vec4 & direction) { + if (lightIndex == -1) return; int matrixMode; - glGetIntegerv(GL_MATRIX_MODE,&matrixMode); + glGetIntegerv(GL_MATRIX_MODE, &matrixMode); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(glm::value_ptr(matrixStack.getViewMatrix())); @@ -1902,7 +1883,7 @@ void ofGLRenderer::setLightSpotDirection(int lightIndex, const glm::vec4 & direc } //---------------------------------------------------------- -int ofGLRenderer::getGLVersionMajor(){ +int ofGLRenderer::getGLVersionMajor() { #ifdef TARGET_OPENGLES return 1; #else @@ -1911,7 +1892,7 @@ int ofGLRenderer::getGLVersionMajor(){ } //---------------------------------------------------------- -int ofGLRenderer::getGLVersionMinor(){ +int ofGLRenderer::getGLVersionMinor() { #ifdef TARGET_OPENGLES return 0; #else @@ -1920,18 +1901,17 @@ int ofGLRenderer::getGLVersionMinor(){ } //---------------------------------------------------------- -void ofGLRenderer::saveFullViewport(ofPixels & pixels){ +void ofGLRenderer::saveFullViewport(ofPixels & pixels) { ofRectangle v = getCurrentViewport(); - saveScreen(v.x,v.y,v.width,v.height,pixels); + saveScreen(v.x, v.y, v.width, v.height, pixels); } //---------------------------------------------------------- -void ofGLRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels){ +void ofGLRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels) { int sh = getViewportHeight(); - - #ifndef TARGET_OPENGLES - if(isVFlipped()){ +#ifndef TARGET_OPENGLES + if (isVFlipped()) { y = sh - y; y -= h; // top, bottom issues } @@ -1939,84 +1919,83 @@ void ofGLRenderer::saveScreen(int x, int y, int w, int h, ofPixels & pixels){ pixels.allocate(w, h, pixelFormat); auto glFormat = ofGetGLFormat(pixels); - glReadPixels(x, y, w, h, glFormat, GL_UNSIGNED_BYTE, pixels.begin()); // read the memory.... pixels.mirror(true, false); - #else +#else int sw = getViewportWidth(); - int numPixels = w*h; - if( numPixels == 0 ){ + int numPixels = w * h; + if (numPixels == 0) { ofLogError("ofImage") << "grabScreen(): unable to grab screen, image width and/or height are 0: " << w << "x" << h; return; } pixels.allocate(w, h, OF_PIXELS_RGBA); - switch(matrixStack.getOrientation()){ + switch (matrixStack.getOrientation()) { case OF_ORIENTATION_UNKNOWN: case OF_ORIENTATION_DEFAULT: - if(isVFlipped()){ - y = sh - y; // screen is flipped vertically. + if (isVFlipped()) { + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,false); + pixels.mirror(true, false); break; case OF_ORIENTATION_180: - if(isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + if (isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(false,true); + pixels.mirror(false, true); break; case OF_ORIENTATION_90_RIGHT: - std::swap(w,h); - std::swap(x,y); - if(!isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + std::swap(w, h); + std::swap(x, y); + if (!isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; - y = sh - y; // screen is flipped vertically. + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,true); + pixels.mirror(true, true); break; case OF_ORIENTATION_90_LEFT: std::swap(w, h); std::swap(x, y); - if(isVFlipped()){ - x = sw - x; // screen is flipped horizontally. + if (isVFlipped()) { + x = sw - x; // screen is flipped horizontally. x -= w; - y = sh - y; // screen is flipped vertically. + y = sh - y; // screen is flipped vertically. y -= h; } glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels.getData()); - pixels.mirror(true,true); + pixels.mirror(true, true); break; } - #endif +#endif } //---------------------------------------------------------- -const of3dGraphics & ofGLRenderer::get3dGraphics() const{ +const of3dGraphics & ofGLRenderer::get3dGraphics() const { return graphics3d; } //---------------------------------------------------------- -of3dGraphics & ofGLRenderer::get3dGraphics(){ +of3dGraphics & ofGLRenderer::get3dGraphics() { return graphics3d; } diff --git a/libs/openFrameworks/gl/ofGLRenderer.h b/libs/openFrameworks/gl/ofGLRenderer.h index bb37f64e333..f550dc860e9 100644 --- a/libs/openFrameworks/gl/ofGLRenderer.h +++ b/libs/openFrameworks/gl/ofGLRenderer.h @@ -1,35 +1,35 @@ #pragma once -#include "ofGraphicsBaseTypes.h" -#include "ofPolyline.h" #include "of3dGraphics.h" #include "ofBitmapFont.h" +#include "ofGLBaseTypes.h" +#include "ofGraphicsBaseTypes.h" #include "ofMatrixStack.h" #include "ofPath.h" -#include "ofGLBaseTypes.h" +#include "ofPolyline.h" class ofShapeTessellation; class ofFbo; class of3dPrimitive; -class ofGLRenderer: public ofBaseGLRenderer{ +class ofGLRenderer : public ofBaseGLRenderer { public: ofGLRenderer(const ofAppBaseWindow * window); - ~ofGLRenderer(){} + ~ofGLRenderer() { } static const std::string TYPE; - const std::string & getType(){ return TYPE; } + const std::string & getType() { return TYPE; } - void setup(); + void setup(); void startRender(); void finishRender(); - using ofBaseRenderer::draw; using ofBaseGLRenderer::draw; + using ofBaseRenderer::draw; void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const; - void draw(const of3dPrimitive& model, ofPolyRenderMode renderType) const; - void draw(const ofNode& model) const; + void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const; + void draw(const ofNode & model) const; void draw(const ofPolyline & poly) const; void draw(const ofPath & path) const; void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; @@ -45,8 +45,6 @@ class ofGLRenderer: public ofBaseGLRenderer{ void drawInstanced(const ofVboMesh & mesh, ofPolyRenderMode renderType, int primCount) const; ofPath & getPath(); - - //-------------------------------------------- // transformations void pushView(); @@ -56,7 +54,7 @@ class ofGLRenderer: public ofBaseGLRenderer{ // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) void viewport(ofRectangle viewport); - void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=true); + void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = true); void setOrientation(ofOrientation orientation, bool vFlip); void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0); void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1); @@ -87,11 +85,11 @@ class ofGLRenderer: public ofBaseGLRenderer{ void rotateZRad(float radians); void rotateRad(float radians); void matrixMode(ofMatrixMode mode); - void loadIdentityMatrix (void); - void loadMatrix (const glm::mat4 & m); - void loadMatrix (const float * m); - void multMatrix (const glm::mat4 & m); - void multMatrix (const float * m); + void loadIdentityMatrix(void); + void loadMatrix(const glm::mat4 & m); + void loadMatrix(const float * m); + void multMatrix(const glm::mat4 & m); + void multMatrix(const float * m); void loadViewMatrix(const glm::mat4 & m); void multViewMatrix(const glm::mat4 & m); @@ -99,7 +97,7 @@ class ofGLRenderer: public ofBaseGLRenderer{ glm::mat4 getCurrentOrientationMatrix() const; glm::mat4 getCurrentViewMatrix() const; glm::mat4 getCurrentNormalMatrix() const; - + // screen coordinate things / default gl values void setupGraphicDefaults(); void setupScreen(); @@ -125,24 +123,24 @@ class ofGLRenderer: public ofBaseGLRenderer{ void setColor(const ofFloatColor & color); void setColor(const ofFloatColor & color, float _a); void setColor(float gray); // new set a color as grayscale with one argument - void setHexColor( int hexColor ); // hex, like web 0xFF0033; + void setHexColor(int hexColor); // hex, like web 0xFF0033; - void setBitmapTextMode(ofDrawBitmapMode mode); + void setBitmapTextMode(ofBitmapMode mode); // bg color ofFloatColor getBackgroundColor(); void setBackgroundColor(const ofFloatColor & c); void background(const ofFloatColor & c); void background(float brightness); - void background(int hexColor, int _a=255); - void background(float r, float g, float b, float a=1.f); + void background(int hexColor, int _a = 255); + void background(float r, float g, float b, float a = 1.f); - void setBackgroundAuto(bool bManual); // default is true + void setBackgroundAuto(bool bManual); // default is true bool getBackgroundAuto(); void clear(); - void clear(float r, float g, float b, float a=0); - void clear(float brightness, float a=0); + void clear(float r, float g, float b, float a = 0); + void clear(float brightness, float a = 0); void clearAlpha(); ofStyle getStyle() const; @@ -152,7 +150,6 @@ class ofGLRenderer: public ofBaseGLRenderer{ void setCurveResolution(int resolution); void setPolyMode(ofPolyWindingMode mode); - // drawing void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const; void drawRectangle(float x, float y, float z, float w, float h) const; @@ -162,7 +159,6 @@ class ofGLRenderer: public ofBaseGLRenderer{ void drawString(std::string text, float x, float y, float z) const; void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const; - // gl specifics void enableTextureTarget(const ofTexture & tex, int textureLocation); void disableTextureTarget(int textureTarget, int textureLocation); @@ -176,21 +172,20 @@ class ofGLRenderer: public ofBaseGLRenderer{ void disableSeparateSpecularLight(); bool getLightingEnabled(); void setSmoothLighting(bool b); - void setGlobalAmbientColor(const ofFloatColor& c); + void setGlobalAmbientColor(const ofFloatColor & c); // lighting per light void enableLight(int lightIndex); void disableLight(int lightIndex); void setLightSpotlightCutOff(int lightIndex, float spotCutOff); void setLightSpotConcentration(int lightIndex, float exponent); - void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic ); - void setLightAmbientColor(int lightIndex, const ofFloatColor& c); - void setLightDiffuseColor(int lightIndex, const ofFloatColor& c); - void setLightSpecularColor(int lightIndex, const ofFloatColor& c); + void setLightAttenuation(int lightIndex, float constant, float linear, float quadratic); + void setLightAmbientColor(int lightIndex, const ofFloatColor & c); + void setLightDiffuseColor(int lightIndex, const ofFloatColor & c); + void setLightSpecularColor(int lightIndex, const ofFloatColor & c); void setLightPosition(int lightIndex, const glm::vec4 & position); void setLightSpotDirection(int lightIndex, const glm::vec4 & direction); - void bind(const ofBaseVideoDraws & video); void bind(const ofBaseMaterial & material); void bind(const ofShadow & shadow); // does nothing, only programmable renderer supported @@ -206,7 +201,7 @@ class ofGLRenderer: public ofBaseGLRenderer{ void unbind(const ofTexture & texture, int location); void unbind(const ofCamera & camera); - void begin(const ofFbo & fbo, ofFboMode mode); + void begin(const ofFbo & fbo, ofFboMode mode); void end(const ofFbo & fbo); void bind(const ofFbo & fbo); @@ -223,11 +218,11 @@ class ofGLRenderer: public ofBaseGLRenderer{ const of3dGraphics & get3dGraphics() const; of3dGraphics & get3dGraphics(); + private: void startSmoothing(); void endSmoothing(); - bool bBackgroundAuto; mutable std::vector linePoints; @@ -239,20 +234,19 @@ class ofGLRenderer: public ofBaseGLRenderer{ ofMatrixStack matrixStack; bool normalsEnabled; bool lightingEnabled; - bool materialBound; + bool materialBound; std::set textureLocationsEnabled; int alphaMaskTextureTarget; ofStyle currentStyle; - std::deque styleHistory; + std::deque styleHistory; of3dGraphics graphics3d; ofBitmapFont bitmapFont; ofPath path; const ofAppBaseWindow * window; - std::deque framebufferIdStack; ///< keeps track of currently bound framebuffers - GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0 - GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target - + std::deque framebufferIdStack; ///< keeps track of currently bound framebuffers + GLuint defaultFramebufferId; ///< default GL_FRAMEBUFFER_BINDING, windowing frameworks might want to set this to their MSAA framebuffer, defaults to 0 + GLuint currentFramebufferId; ///< the framebuffer id currently bound to the GL_FRAMEBUFFER target }; diff --git a/libs/openFrameworks/graphics/of3dGraphics.cpp b/libs/openFrameworks/graphics/of3dGraphics.cpp index 73e96938b1c..70eec606a56 100644 --- a/libs/openFrameworks/graphics/of3dGraphics.cpp +++ b/libs/openFrameworks/graphics/of3dGraphics.cpp @@ -4,47 +4,43 @@ // // Created by Nick Hardeman on 9/14/12. // -// #include "of3dGraphics.h" - enum of3dPrimitiveType { OF_3D_PRIMITIVE_PLANE, - OF_3D_PRIMITIVE_SPHERE, - OF_3D_PRIMITIVE_ICO_SPHERE, + OF_3D_PRIMITIVE_SPHERE, + OF_3D_PRIMITIVE_ICO_SPHERE, OF_3D_PRIMITIVE_BOX, OF_3D_PRIMITIVE_CONE, - OF_3D_PRIMITIVE_CYLINDER, - OF_3D_PRIMITIVE_BOX_WIREFRAME + OF_3D_PRIMITIVE_CYLINDER, + OF_3D_PRIMITIVE_BOX_WIREFRAME }; - of3dGraphics::of3dGraphics(ofBaseRenderer * renderer) -:renderer(renderer) -,plane(1.0f, 1.0f, 6, 4) -,sphere(1.0f, 20) -,icoSphere(1.0f, 2) -,box(1.f, 1.f, 1.f, 1, 1, 1) -,cone( 1.f, 1.f, 9, 3, 2 ) -,cylinder(1.f, 1.f, 8, 4, 2, true) -,boxWireframe(1.f, 1.f, 1.f ) -,axis(ofMesh::axis()) -{ - - ofMesh* boxWireframeMesh = boxWireframe.getMeshPtr(); + : renderer(renderer) + , plane(1.0f, 1.0f, 6, 4) + , sphere(1.0f, 20) + , icoSphere(1.0f, 2) + , box(1.f, 1.f, 1.f, 1, 1, 1) + , cone(1.f, 1.f, 9, 3, 2) + , cylinder(1.f, 1.f, 8, 4, 2, true) + , boxWireframe(1.f, 1.f, 1.f) + , axis(ofMesh::axis()) { + + ofMesh * boxWireframeMesh = boxWireframe.getMeshPtr(); boxWireframeMesh->clear(); - boxWireframeMesh->setMode( OF_PRIMITIVE_LINES ); + boxWireframeMesh->setMode(OF_PRIMITIVE_LINES); - boxWireframeMesh->addVertex({-.5f, -.5f, -.5f}); - boxWireframeMesh->addVertex({.5f, -.5f, -.5f}); - boxWireframeMesh->addVertex({.5f, .5f, -.5f}); - boxWireframeMesh->addVertex({-.5f, .5f, -.5f}); + boxWireframeMesh->addVertex({ -.5f, -.5f, -.5f }); + boxWireframeMesh->addVertex({ .5f, -.5f, -.5f }); + boxWireframeMesh->addVertex({ .5f, .5f, -.5f }); + boxWireframeMesh->addVertex({ -.5f, .5f, -.5f }); - boxWireframeMesh->addVertex({-.5f, -.5f, .5f}); - boxWireframeMesh->addVertex({.5f, -.5f, .5f}); - boxWireframeMesh->addVertex({.5f, .5f, .5f}); - boxWireframeMesh->addVertex({-.5f, .5f, .5f}); + boxWireframeMesh->addVertex({ -.5f, -.5f, .5f }); + boxWireframeMesh->addVertex({ .5f, -.5f, .5f }); + boxWireframeMesh->addVertex({ .5f, .5f, .5f }); + boxWireframeMesh->addVertex({ -.5f, .5f, .5f }); // front face boxWireframeMesh->addIndex(0); @@ -72,7 +68,6 @@ of3dGraphics::of3dGraphics(ofBaseRenderer * renderer) boxWireframeMesh->addIndex(7); boxWireframeMesh->addIndex(4); - boxWireframeMesh->addIndex(0); boxWireframeMesh->addIndex(4); @@ -84,325 +79,316 @@ of3dGraphics::of3dGraphics(ofBaseRenderer * renderer) boxWireframeMesh->addIndex(3); boxWireframeMesh->addIndex(7); - } //---------------------------------------------------------- -void of3dGraphics::renderCached3dPrimitive( const of3dPrimitive& model ) const{ - if(renderer->getFillMode() == OF_FILLED) { - renderer->draw(model,OF_MESH_FILL); +void of3dGraphics::renderCached3dPrimitive(const of3dPrimitive & model) const { + if (renderer->getFillMode() == OF_FILLED) { + renderer->draw(model, OF_MESH_FILL); } else { - renderer->draw(model,OF_MESH_WIREFRAME); + renderer->draw(model, OF_MESH_WIREFRAME); } } // Plane // //---------------------------------------------------------- -void of3dGraphics::setPlaneResolution( int columns, int rows ) { - plane.setResolution(columns, rows); +void of3dGraphics::setPlaneResolution(int columns, int rows) { + plane.setResolution(columns, rows); } // returns columns as x value of vector and rows as y value //---------------------------------------------------------- -glm::vec2 of3dGraphics::getPlaneResolution() const{ - return plane.getResolution(); +glm::vec2 of3dGraphics::getPlaneResolution() const { + return plane.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawPlane(float x, float y, float width, float height) const{ - of3dGraphics::drawPlane( x, y, 0, width, height); +void of3dGraphics::drawPlane(float x, float y, float width, float height) const { + of3dGraphics::drawPlane(x, y, 0, width, height); } //---------------------------------------------------------- -void of3dGraphics::drawPlane(float x, float y, float z, float width, float height) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(width,height,1)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( plane ); - renderer->popMatrix(); +void of3dGraphics::drawPlane(float x, float y, float z, float width, float height) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(width, height, 1)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(plane); + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawPlane(const glm::vec3& position, float width, float height) const{ - drawPlane(position.x,position.y,position.z,width, height); +void of3dGraphics::drawPlane(const glm::vec3 & position, float width, float height) const { + drawPlane(position.x, position.y, position.z, width, height); } //---------------------------------------------------------- -void of3dGraphics::drawPlane( float width, float height ) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(width,height,1)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( plane ); - renderer->popMatrix(); +void of3dGraphics::drawPlane(float width, float height) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(width, height, 1)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(plane); + renderer->popMatrix(); } - // UV SPHERE // //---------------------------------------------------------- void of3dGraphics::setSphereResolution(int res) { - if(getSphereResolution() != res) { - sphere.setResolution(res); - } + if (getSphereResolution() != res) { + sphere.setResolution(res); + } } //--------------------------------------------------------- -int of3dGraphics::getSphereResolution() const{ - return sphere.getResolution(); +int of3dGraphics::getSphereResolution() const { + return sphere.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawSphere(float x, float y, float z, float radius) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(radius,radius,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( sphere ); - renderer->popMatrix(); +void of3dGraphics::drawSphere(float x, float y, float z, float radius) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(radius, radius, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(sphere); + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawSphere(float x, float y, float radius) const{ - drawSphere(x, y, 0, radius); +void of3dGraphics::drawSphere(float x, float y, float radius) const { + drawSphere(x, y, 0, radius); } //---------------------------------------------------------- -void of3dGraphics::drawSphere(const glm::vec3& position, float radius) const{ - drawSphere(position.x,position.y,position.z,radius); +void of3dGraphics::drawSphere(const glm::vec3 & position, float radius) const { + drawSphere(position.x, position.y, position.z, radius); } //---------------------------------------------------------- -void of3dGraphics::drawSphere(float radius) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius,radius,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( sphere ); - renderer->popMatrix(); +void of3dGraphics::drawSphere(float radius) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius, radius, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(sphere); + renderer->popMatrix(); } - // ICO SPHERE // //---------------------------------------------------------- -void of3dGraphics::setIcoSphereResolution( int res ) { - if(getIcoSphereResolution() != res) { - icoSphere.setResolution(res); - } +void of3dGraphics::setIcoSphereResolution(int res) { + if (getIcoSphereResolution() != res) { + icoSphere.setResolution(res); + } } //---------------------------------------------------------- -int of3dGraphics::getIcoSphereResolution() const{ - return icoSphere.getResolution(); +int of3dGraphics::getIcoSphereResolution() const { + return icoSphere.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawIcoSphere(float x, float y, float z, float radius) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(radius,radius,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( icoSphere ); - renderer->popMatrix(); +void of3dGraphics::drawIcoSphere(float x, float y, float z, float radius) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(radius, radius, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(icoSphere); + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawIcoSphere(float x, float y, float radius) const{ - drawIcoSphere(x, y, 0, radius); +void of3dGraphics::drawIcoSphere(float x, float y, float radius) const { + drawIcoSphere(x, y, 0, radius); } //---------------------------------------------------------- -void of3dGraphics::drawIcoSphere(const glm::vec3& position, float radius) const{ - drawIcoSphere(position.x,position.y,position.z,radius); +void of3dGraphics::drawIcoSphere(const glm::vec3 & position, float radius) const { + drawIcoSphere(position.x, position.y, position.z, radius); } //---------------------------------------------------------- -void of3dGraphics::drawIcoSphere(float radius) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius,radius,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( icoSphere ); - renderer->popMatrix(); +void of3dGraphics::drawIcoSphere(float radius) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius, radius, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(icoSphere); + renderer->popMatrix(); } - // Cylinder // //---------------------------------------------------------- -void of3dGraphics::setCylinderResolution( int radiusSegments, int heightSegments, int capSegments ) { - if(getCylinderResolution() != glm::vec3{ radiusSegments, heightSegments, capSegments }) { - cylinder.setResolution(radiusSegments, heightSegments, capSegments); - } +void of3dGraphics::setCylinderResolution(int radiusSegments, int heightSegments, int capSegments) { + if (getCylinderResolution() != glm::vec3 { radiusSegments, heightSegments, capSegments }) { + cylinder.setResolution(radiusSegments, heightSegments, capSegments); + } } //---------------------------------------------------------- -glm::vec3 of3dGraphics::getCylinderResolution() const{ - return cylinder.getResolution(); +glm::vec3 of3dGraphics::getCylinderResolution() const { + return cylinder.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawCylinder(float x, float y, float radius, float height) const{ - drawCylinder( x, y, 0, radius, height ); +void of3dGraphics::drawCylinder(float x, float y, float radius, float height) const { + drawCylinder(x, y, 0, radius, height); } //---------------------------------------------------------- -void of3dGraphics::drawCylinder(float x, float y, float z, float radius, float height) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(radius,height,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( cylinder ); - renderer->popMatrix(); +void of3dGraphics::drawCylinder(float x, float y, float z, float radius, float height) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(radius, height, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(cylinder); + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawCylinder(const glm::vec3& position, float radius, float height) const{ - drawCylinder( position.x, position.y, position.z, radius, height ); +void of3dGraphics::drawCylinder(const glm::vec3 & position, float radius, float height) const { + drawCylinder(position.x, position.y, position.z, radius, height); } //---------------------------------------------------------- -void of3dGraphics::drawCylinder(float radius, float height) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius,height,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( cylinder ); - renderer->popMatrix(); +void of3dGraphics::drawCylinder(float radius, float height) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius, height, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(cylinder); + renderer->popMatrix(); } - - // CONE // //---------------------------------------------------------- -void of3dGraphics::setConeResolution( int radiusSegments, int heightSegments, int capSegments){ - if(getConeResolution() != glm::vec3( radiusSegments, heightSegments, capSegments )) { - cone.setResolution(radiusSegments, heightSegments, capSegments); - } +void of3dGraphics::setConeResolution(int radiusSegments, int heightSegments, int capSegments) { + if (getConeResolution() != glm::vec3(radiusSegments, heightSegments, capSegments)) { + cone.setResolution(radiusSegments, heightSegments, capSegments); + } } //---------------------------------------------------------- -glm::vec3 of3dGraphics::getConeResolution() const{ - return cone.getResolution(); +glm::vec3 of3dGraphics::getConeResolution() const { + return cone.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawCone(float x, float y, float z, float radius, float height) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(radius,height,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( cone ); - renderer->popMatrix(); +void of3dGraphics::drawCone(float x, float y, float z, float radius, float height) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(radius, height, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(cone); + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawCone(float x, float y, float radius, float height) const{ - drawCone( x, y, 0, radius, height ); +void of3dGraphics::drawCone(float x, float y, float radius, float height) const { + drawCone(x, y, 0, radius, height); } //---------------------------------------------------------- -void of3dGraphics::drawCone(const glm::vec3& position, float radius, float height) const{ - drawCone( position.x, position.y, position.z, radius, height ); +void of3dGraphics::drawCone(const glm::vec3 & position, float radius, float height) const { + drawCone(position.x, position.y, position.z, radius, height); } //---------------------------------------------------------- -void of3dGraphics::drawCone(float radius, float height) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius,height,radius)); - renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( cone ); - renderer->popMatrix(); +void of3dGraphics::drawCone(float radius, float height) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(radius, height, radius)); + renderer->pushMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(cone); + renderer->popMatrix(); } - - // BOX // //---------------------------------------------------------- -void of3dGraphics::setBoxResolution( int res ) { - setBoxResolution(res, res, res); +void of3dGraphics::setBoxResolution(int res) { + setBoxResolution(res, res, res); } //---------------------------------------------------------- -void of3dGraphics::setBoxResolution( int resWidth, int resHeight, int resDepth ) { - if(getBoxResolution() != glm::vec3( resWidth, resHeight, resDepth )) { - box.setResolution(resWidth, resHeight, resDepth); +void of3dGraphics::setBoxResolution(int resWidth, int resHeight, int resDepth) { + if (getBoxResolution() != glm::vec3(resWidth, resHeight, resDepth)) { + box.setResolution(resWidth, resHeight, resDepth); } } //---------------------------------------------------------- -glm::vec3 of3dGraphics::getBoxResolution() const{ - return box.getResolution(); +glm::vec3 of3dGraphics::getBoxResolution() const { + return box.getResolution(); } //---------------------------------------------------------- -void of3dGraphics::drawBox( float x, float y, float z, float width, float height, float depth) const{ - glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x,y,z)); - m = glm::scale(m, glm::vec3(width,height,depth)); +void of3dGraphics::drawBox(float x, float y, float z, float width, float height, float depth) const { + glm::mat4 m = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); + m = glm::scale(m, glm::vec3(width, height, depth)); - renderer->pushMatrix(); - renderer->multMatrix(m); - if(renderer->getFillMode() == OF_FILLED || box.getResolution() != glm::vec3(1,1,1)) { - renderCached3dPrimitive( box ); - } else { - renderCached3dPrimitive( boxWireframe ); - } - renderer->popMatrix(); + renderer->pushMatrix(); + renderer->multMatrix(m); + if (renderer->getFillMode() == OF_FILLED || box.getResolution() != glm::vec3(1, 1, 1)) { + renderCached3dPrimitive(box); + } else { + renderCached3dPrimitive(boxWireframe); + } + renderer->popMatrix(); } //---------------------------------------------------------- -void of3dGraphics::drawBox(float x, float y, float z, float size) const{ - drawBox( x, y, z, size, size, size ); +void of3dGraphics::drawBox(float x, float y, float z, float size) const { + drawBox(x, y, z, size, size, size); } //---------------------------------------------------------- -void of3dGraphics::drawBox(const glm::vec3& position, float width, float height, float depth) const{ - drawBox( position.x, position.y, position.z, width, height, depth ); +void of3dGraphics::drawBox(const glm::vec3 & position, float width, float height, float depth) const { + drawBox(position.x, position.y, position.z, width, height, depth); } //---------------------------------------------------------- -void of3dGraphics::drawBox(const glm::vec3& position, float size) const{ - drawBox( position.x, position.y, position.z, size, size, size ); +void of3dGraphics::drawBox(const glm::vec3 & position, float size) const { + drawBox(position.x, position.y, position.z, size, size, size); } //---------------------------------------------------------- -void of3dGraphics::drawBox(float size) const{ - drawBox( size, size, size ); +void of3dGraphics::drawBox(float size) const { + drawBox(size, size, size); } //---------------------------------------------------------- -void of3dGraphics::drawBox( float width, float height, float depth ) const{ - drawBox(0,0,0,width,height,depth); +void of3dGraphics::drawBox(float width, float height, float depth) const { + drawBox(0, 0, 0, width, height, depth); } - -void of3dGraphics::drawAxis(float size) const{ - glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(size,size,size)); +void of3dGraphics::drawAxis(float size) const { + glm::mat4 m = glm::scale(glm::mat4(1.0), glm::vec3(size, size, size)); renderer->pushMatrix(); - renderer->multMatrix(m); - renderCached3dPrimitive( axis ); - renderer->popMatrix(); + renderer->multMatrix(m); + renderCached3dPrimitive(axis); + renderer->popMatrix(); } //-------------------------------------------------------------- -void of3dGraphics::drawGrid(float stepSize, size_t numberOfSteps, bool labels, bool x, bool y, bool z) const{ +void of3dGraphics::drawGrid(float stepSize, size_t numberOfSteps, bool labels, bool x, bool y, bool z) const { ofFloatColor c; ofFloatColor prevColor = renderer->getStyle().color; if (x) { - c.setHsb(0.0f, 200.0f/255.f, 1.f); + c.setHsb(0.0f, 200.0f / 255.f, 1.f); renderer->setColor(c); drawGridPlane(stepSize, numberOfSteps, labels); } if (y) { - c.setHsb((255.0f / 3.0f)/255.f, 200.0f/255.f, 1.f); + c.setHsb((255.0f / 3.0f) / 255.f, 200.0f / 255.f, 1.f); renderer->setColor(c); - glm::mat4 m = glm::rotate(glm::mat4(1.0), glm::half_pi(), glm::vec3(0,0,-1)); + glm::mat4 m = glm::rotate(glm::mat4(1.0), glm::half_pi(), glm::vec3(0, 0, -1)); renderer->pushMatrix(); renderer->multMatrix(m); drawGridPlane(stepSize, numberOfSteps, labels); renderer->popMatrix(); } if (z) { - c.setHsb((255.0f * 2.0f / 3.0f)/255.f, 200.0f/255.f, 1.f); + c.setHsb((255.0f * 2.0f / 3.0f) / 255.f, 200.0f / 255.f, 1.f); renderer->setColor(c); - glm::mat4 m = glm::rotate(glm::mat4(1.0), glm::half_pi(), glm::vec3(0,1,0)); + glm::mat4 m = glm::rotate(glm::mat4(1.0), glm::half_pi(), glm::vec3(0, 1, 0)); renderer->pushMatrix(); renderer->multMatrix(m); drawGridPlane(stepSize, numberOfSteps, labels); @@ -410,7 +396,7 @@ void of3dGraphics::drawGrid(float stepSize, size_t numberOfSteps, bool labels, b } if (labels) { - ofDrawBitmapMode mode = renderer->getStyle().drawBitmapMode; + ofBitmapMode mode = renderer->getStyle().bitmapMode; renderer->setColor(1.f, 1.f, 1.f); float labelPos = stepSize * (numberOfSteps + 0.5); renderer->setBitmapTextMode(OF_BITMAPMODE_MODEL_BILLBOARD); @@ -422,32 +408,29 @@ void of3dGraphics::drawGrid(float stepSize, size_t numberOfSteps, bool labels, b renderer->setColor(prevColor); } - //-------------------------------------------------------------- -void of3dGraphics::drawGridPlane(float stepSize, size_t numberOfSteps, bool labels) const{ +void of3dGraphics::drawGridPlane(float stepSize, size_t numberOfSteps, bool labels) const { float scale = stepSize * numberOfSteps; float lineWidth = renderer->getStyle().lineWidth; - for (int iDimension=0; iDimension<2; iDimension++) - { - for (size_t i=0; i <= numberOfSteps; i++) - { + for (int iDimension = 0; iDimension < 2; iDimension++) { + for (size_t i = 0; i <= numberOfSteps; i++) { float yz = i * stepSize; if (i == numberOfSteps || i == 0) - renderer->setLineWidth(2); // central axis or cap line - else if ( i % 2 == 0){ + renderer->setLineWidth(2); // central axis or cap line + else if (i % 2 == 0) { renderer->setLineWidth(1.5); // major } else { - renderer->setLineWidth(1); // minor + renderer->setLineWidth(1); // minor } - if (iDimension == 0 ) { + if (iDimension == 0) { renderer->drawLine(0, yz, -scale, 0, yz, scale); - if (yz !=0) renderer->drawLine(0, -yz, -scale, 0, -yz, scale); + if (yz != 0) renderer->drawLine(0, -yz, -scale, 0, -yz, scale); } else { renderer->drawLine(0, -scale, yz, 0, scale, yz); - if (yz !=0) renderer->drawLine(0, -scale, -yz, 0, scale, -yz); + if (yz != 0) renderer->drawLine(0, -scale, -yz, 0, scale, -yz); } } } @@ -456,15 +439,14 @@ void of3dGraphics::drawGridPlane(float stepSize, size_t numberOfSteps, bool labe if (labels) { //draw numbers on axes ofFloatColor prevColor = renderer->getStyle().color; - ofDrawBitmapMode mode = renderer->getStyle().drawBitmapMode; + ofBitmapMode mode = renderer->getStyle().bitmapMode; renderer->setColor(1.f, 1.f, 1.f); renderer->setBitmapTextMode(OF_BITMAPMODE_MODEL_BILLBOARD); renderer->drawString(ofToString(0), 0, 0, 0); - for (float i = 1; i <= numberOfSteps; i++) - { + for (float i = 1; i <= numberOfSteps; i++) { float yz = i * stepSize; renderer->drawString(ofToString(yz), 0, yz, 0); renderer->drawString(ofToString(-yz), 0, -yz, 0); @@ -475,28 +457,27 @@ void of3dGraphics::drawGridPlane(float stepSize, size_t numberOfSteps, bool labe renderer->setColor(prevColor); renderer->setBitmapTextMode(mode); } - } //-------------------------------------------------------------- -void of3dGraphics::drawArrow(const glm::vec3& start, const glm::vec3& end, float headSize) const{ +void of3dGraphics::drawArrow(const glm::vec3 & start, const glm::vec3 & end, float headSize) const { //draw line - renderer->drawLine(start.x,start.y,start.z, end.x,end.y,end.z); + renderer->drawLine(start.x, start.y, start.z, end.x, end.y, end.z); // Note that `glm::rotation` requires its parameters to be normalized `glm::vec3`s - const glm::mat4 cone_rotation = glm::mat4_cast(glm::rotation(glm::vec3(0,1,0), glm::normalize(start-end))); + const glm::mat4 cone_rotation = glm::mat4_cast(glm::rotation(glm::vec3(0, 1, 0), glm::normalize(start - end))); const glm::mat4 cone_translation = glm::translate(end); - const glm::mat4 cone_transform = cone_translation * cone_rotation; + const glm::mat4 cone_transform = cone_translation * cone_rotation; renderer->pushMatrix(); renderer->multMatrix(cone_transform); - drawCone(headSize, headSize*2.); - renderer->popMatrix(); + drawCone(headSize, headSize * 2.); + renderer->popMatrix(); } //-------------------------------------------------------------- -void of3dGraphics::drawRotationAxes(float radius, float stripWidth, int circleRes) const{ +void of3dGraphics::drawRotationAxes(float radius, float stripWidth, int circleRes) const { ofMesh axisXMesh; axisXMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); @@ -507,23 +488,23 @@ void of3dGraphics::drawRotationAxes(float radius, float stripWidth, int circleRe ofMesh axisZMesh; axisZMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); - for (int j = 0; j<=circleRes; j++) { - float x = cos(glm::two_pi() * j/circleRes); - float y = sin(glm::two_pi() * j/circleRes); + for (int j = 0; j <= circleRes; j++) { + float x = cos(glm::two_pi() * j / circleRes); + float y = sin(glm::two_pi() * j / circleRes); axisXMesh.addColor(ofFloatColor(ofFloatColor::red)); - axisXMesh.addVertex({-stripWidth, x*radius, y*radius}); + axisXMesh.addVertex({ -stripWidth, x * radius, y * radius }); axisXMesh.addColor(ofFloatColor(ofFloatColor::red)); - axisXMesh.addVertex({ stripWidth, x*radius, y*radius}); + axisXMesh.addVertex({ stripWidth, x * radius, y * radius }); axisYMesh.addColor(ofFloatColor(ofFloatColor::green)); - axisYMesh.addVertex({x*radius, -stripWidth, y*radius}); + axisYMesh.addVertex({ x * radius, -stripWidth, y * radius }); axisYMesh.addColor(ofFloatColor(ofFloatColor::green)); - axisYMesh.addVertex({x*radius, stripWidth, y*radius}); + axisYMesh.addVertex({ x * radius, stripWidth, y * radius }); axisZMesh.addColor(ofFloatColor(ofFloatColor::blue)); - axisZMesh.addVertex({x*radius, y*radius, -stripWidth}); + axisZMesh.addVertex({ x * radius, y * radius, -stripWidth }); axisZMesh.addColor(ofFloatColor(ofFloatColor::blue)); - axisZMesh.addVertex({x*radius, y*radius, stripWidth}); + axisZMesh.addVertex({ x * radius, y * radius, stripWidth }); } axisXMesh.draw(); @@ -532,286 +513,271 @@ void of3dGraphics::drawRotationAxes(float radius, float stripWidth, int circleRe drawAxis(radius); } - //---------------------------------------------------------- -void ofSetPlaneResolution( int columns, int rows ){ - ofGetCurrentRenderer()->setPlaneResolution(columns,rows); +void ofSetPlaneResolution(int columns, int rows) { + ofGetCurrentRenderer()->setPlaneResolution(columns, rows); } //---------------------------------------------------------- -glm::vec2 ofGetPlaneResolution(){ +glm::vec2 ofGetPlaneResolution() { return ofGetCurrentRenderer()->getPlaneResolution(); } //---------------------------------------------------------- -void ofDrawPlane(float x, float y, float width, float height){ - ofGetCurrentRenderer()->drawPlane(x,y,width,height); +void ofDrawPlane(float x, float y, float width, float height) { + ofGetCurrentRenderer()->drawPlane(x, y, width, height); } //---------------------------------------------------------- -void ofDrawPlane(float x, float y, float z, float width, float height){ - ofGetCurrentRenderer()->drawPlane(x,y,z,width,height); +void ofDrawPlane(float x, float y, float z, float width, float height) { + ofGetCurrentRenderer()->drawPlane(x, y, z, width, height); } //---------------------------------------------------------- -void ofDrawPlane(const glm::vec3& position, float width, float height){ - ofGetCurrentRenderer()->drawPlane(position,width,height); +void ofDrawPlane(const glm::vec3 & position, float width, float height) { + ofGetCurrentRenderer()->drawPlane(position, width, height); } //---------------------------------------------------------- -void ofDrawPlane( float width, float height ){ - ofGetCurrentRenderer()->drawPlane(width,height); +void ofDrawPlane(float width, float height) { + ofGetCurrentRenderer()->drawPlane(width, height); } - // UV Sphere //---------------------------------------------------------- -void ofSetSphereResolution(int res){ +void ofSetSphereResolution(int res) { ofGetCurrentRenderer()->setSphereResolution(res); } //---------------------------------------------------------- -int ofGetSphereResolution(){ +int ofGetSphereResolution() { return ofGetCurrentRenderer()->getSphereResolution(); } //---------------------------------------------------------- -void ofDrawSphere(float x, float y, float radius){ - ofGetCurrentRenderer()->drawSphere(x,y,radius); +void ofDrawSphere(float x, float y, float radius) { + ofGetCurrentRenderer()->drawSphere(x, y, radius); } //---------------------------------------------------------- -void ofDrawSphere(float x, float y, float z, float radius){ - ofGetCurrentRenderer()->drawSphere(x,y,z,radius); +void ofDrawSphere(float x, float y, float z, float radius) { + ofGetCurrentRenderer()->drawSphere(x, y, z, radius); } //---------------------------------------------------------- -void ofDrawSphere(const glm::vec3& position, float radius){ - ofGetCurrentRenderer()->drawSphere(position,radius); +void ofDrawSphere(const glm::vec3 & position, float radius) { + ofGetCurrentRenderer()->drawSphere(position, radius); } //---------------------------------------------------------- -void ofDrawSphere(float radius){ +void ofDrawSphere(float radius) { ofGetCurrentRenderer()->drawSphere(radius); } - // Ico Sphere //---------------------------------------------------------- -void ofSetIcoSphereResolution( int res ){ +void ofSetIcoSphereResolution(int res) { ofGetCurrentRenderer()->setIcoSphereResolution(res); } //---------------------------------------------------------- -int ofGetIcoSphereResolution(){ +int ofGetIcoSphereResolution() { return ofGetCurrentRenderer()->getIcoSphereResolution(); } //---------------------------------------------------------- -void ofDrawIcoSphere(float x, float y, float z, float radius){ - ofGetCurrentRenderer()->drawIcoSphere(x,y,z,radius); +void ofDrawIcoSphere(float x, float y, float z, float radius) { + ofGetCurrentRenderer()->drawIcoSphere(x, y, z, radius); } //---------------------------------------------------------- -void ofDrawIcoSphere(float x, float y, float radius){ - ofGetCurrentRenderer()->drawIcoSphere(x,y,radius); +void ofDrawIcoSphere(float x, float y, float radius) { + ofGetCurrentRenderer()->drawIcoSphere(x, y, radius); } //---------------------------------------------------------- -void ofDrawIcoSphere(const glm::vec3& position, float radius){ - ofGetCurrentRenderer()->drawIcoSphere(position,radius); +void ofDrawIcoSphere(const glm::vec3 & position, float radius) { + ofGetCurrentRenderer()->drawIcoSphere(position, radius); } //---------------------------------------------------------- -void ofDrawIcoSphere(float radius){ +void ofDrawIcoSphere(float radius) { ofGetCurrentRenderer()->drawIcoSphere(radius); } - // Cylinder // //---------------------------------------------------------- -void ofSetCylinderResolution( int radiusSegments, int heightSegments, int capSegments ){ - ofGetCurrentRenderer()->setCylinderResolution(radiusSegments,heightSegments,capSegments); +void ofSetCylinderResolution(int radiusSegments, int heightSegments, int capSegments) { + ofGetCurrentRenderer()->setCylinderResolution(radiusSegments, heightSegments, capSegments); } //---------------------------------------------------------- -glm::vec3 ofGetCylinderResolution(){ +glm::vec3 ofGetCylinderResolution() { return ofGetCurrentRenderer()->getCylinderResolution(); } //---------------------------------------------------------- -void ofDrawCylinder(float x, float y, float radius, float height){ - ofGetCurrentRenderer()->drawCylinder(x,y,radius,height); +void ofDrawCylinder(float x, float y, float radius, float height) { + ofGetCurrentRenderer()->drawCylinder(x, y, radius, height); } //---------------------------------------------------------- -void ofDrawCylinder(float x, float y, float z, float radius, float height){ - ofGetCurrentRenderer()->drawCylinder(x,y,z,radius,height); +void ofDrawCylinder(float x, float y, float z, float radius, float height) { + ofGetCurrentRenderer()->drawCylinder(x, y, z, radius, height); } //---------------------------------------------------------- -void ofDrawCylinder(const glm::vec3& position, float radius, float height){ - ofGetCurrentRenderer()->drawCylinder(position,radius,height); +void ofDrawCylinder(const glm::vec3 & position, float radius, float height) { + ofGetCurrentRenderer()->drawCylinder(position, radius, height); } //---------------------------------------------------------- -void ofDrawCylinder(float radius, float height){ - ofGetCurrentRenderer()->drawCylinder(radius,height); +void ofDrawCylinder(float radius, float height) { + ofGetCurrentRenderer()->drawCylinder(radius, height); } //---------------------------------------------------------- -void ofSetConeResolution( int radiusSegments, int heightSegments, int capSegments){ - ofGetCurrentRenderer()->setConeResolution(radiusSegments,heightSegments,capSegments); +void ofSetConeResolution(int radiusSegments, int heightSegments, int capSegments) { + ofGetCurrentRenderer()->setConeResolution(radiusSegments, heightSegments, capSegments); } //---------------------------------------------------------- -glm::vec3 ofGetConeResolution(){ +glm::vec3 ofGetConeResolution() { return ofGetCurrentRenderer()->getConeResolution(); } //---------------------------------------------------------- -void ofDrawCone(float x, float y, float z, float radius, float height){ - ofGetCurrentRenderer()->drawCone(x,y,z,radius,height); +void ofDrawCone(float x, float y, float z, float radius, float height) { + ofGetCurrentRenderer()->drawCone(x, y, z, radius, height); } //---------------------------------------------------------- -void ofDrawCone(float x, float y, float radius, float height){ - ofGetCurrentRenderer()->drawCone(x,y,radius,height); +void ofDrawCone(float x, float y, float radius, float height) { + ofGetCurrentRenderer()->drawCone(x, y, radius, height); } //---------------------------------------------------------- -void ofDrawCone(const glm::vec3& position, float radius, float height){ - ofGetCurrentRenderer()->drawCone(position,radius,height); +void ofDrawCone(const glm::vec3 & position, float radius, float height) { + ofGetCurrentRenderer()->drawCone(position, radius, height); } //---------------------------------------------------------- -void ofDrawCone(float radius, float height){ - ofGetCurrentRenderer()->drawCone(radius,height); +void ofDrawCone(float radius, float height) { + ofGetCurrentRenderer()->drawCone(radius, height); } //---------------------------------------------------------- -void ofSetBoxResolution( int res ){ +void ofSetBoxResolution(int res) { ofGetCurrentRenderer()->setBoxResolution(res); } //---------------------------------------------------------- -void ofSetBoxResolution( int resWidth, int resHeight, int resDepth ){ - ofGetCurrentRenderer()->setBoxResolution(resWidth,resHeight,resDepth); +void ofSetBoxResolution(int resWidth, int resHeight, int resDepth) { + ofGetCurrentRenderer()->setBoxResolution(resWidth, resHeight, resDepth); } //---------------------------------------------------------- -glm::vec3 ofGetBoxResolution(){ +glm::vec3 ofGetBoxResolution() { return ofGetCurrentRenderer()->getBoxResolution(); } //---------------------------------------------------------- -void ofDrawBox( float x, float y, float z, float width, float height, float depth){ - ofGetCurrentRenderer()->drawBox(x,y,z,width,height,depth); +void ofDrawBox(float x, float y, float z, float width, float height, float depth) { + ofGetCurrentRenderer()->drawBox(x, y, z, width, height, depth); } //---------------------------------------------------------- -void ofDrawBox(float x, float y, float z, float size){ - ofGetCurrentRenderer()->drawBox(x,y,z,size); +void ofDrawBox(float x, float y, float z, float size) { + ofGetCurrentRenderer()->drawBox(x, y, z, size); } //---------------------------------------------------------- -void ofDrawBox(const glm::vec3& position, float width, float height, float depth){ - ofGetCurrentRenderer()->drawBox(position,width,height,depth); +void ofDrawBox(const glm::vec3 & position, float width, float height, float depth) { + ofGetCurrentRenderer()->drawBox(position, width, height, depth); } //---------------------------------------------------------- -void ofDrawBox(const glm::vec3& position, float size){ - ofGetCurrentRenderer()->drawBox(position,size); +void ofDrawBox(const glm::vec3 & position, float size) { + ofGetCurrentRenderer()->drawBox(position, size); } //---------------------------------------------------------- -void ofDrawBox(float size){ +void ofDrawBox(float size) { ofGetCurrentRenderer()->drawBox(size); } -void ofDrawBox( float width, float height, float depth ){ - ofGetCurrentRenderer()->drawBox(width,height,depth); +void ofDrawBox(float width, float height, float depth) { + ofGetCurrentRenderer()->drawBox(width, height, depth); } - // Deprecated methods - for compatability with previous versions of OF // //---------------------------------------------------------- void ofSphere(float x, float y, float z, float radius) { - ofDrawSphere(x, y, z, radius); + ofDrawSphere(x, y, z, radius); } //---------------------------------------------------------- void ofSphere(float x, float y, float radius) { - ofDrawSphere(x, y, 0, radius); + ofDrawSphere(x, y, 0, radius); } //---------------------------------------------------------- -void ofSphere(const glm::vec3& position, float radius) { - ofDrawSphere(position.x,position.y,position.z,radius); +void ofSphere(const glm::vec3 & position, float radius) { + ofDrawSphere(position.x, position.y, position.z, radius); } //---------------------------------------------------------- void ofSphere(float radius) { - ofDrawSphere(radius); + ofDrawSphere(radius); } //---------------------------------------------------------- void ofCone(float x, float y, float z, float radius, float height) { - ofDrawCone(x, y, z, radius, height); + ofDrawCone(x, y, z, radius, height); } //---------------------------------------------------------- void ofCone(float x, float y, float radius, float height) { - ofDrawCone( x, y, 0, radius, height ); + ofDrawCone(x, y, 0, radius, height); } //---------------------------------------------------------- -void ofCone(const glm::vec3& position, float radius, float height) { - ofDrawCone( position.x, position.y, position.z, radius, height ); +void ofCone(const glm::vec3 & position, float radius, float height) { + ofDrawCone(position.x, position.y, position.z, radius, height); } //---------------------------------------------------------- void ofCone(float radius, float height) { - ofDrawCone(radius, height ); + ofDrawCone(radius, height); } - - // deprecated methods // //---------------------------------------------------------- -void ofBox( float x, float y, float z, float width, float height, float depth) { - ofDrawBox(x,y,z,width,height,depth); +void ofBox(float x, float y, float z, float width, float height, float depth) { + ofDrawBox(x, y, z, width, height, depth); } //---------------------------------------------------------- void ofBox(float x, float y, float z, float size) { - ofDrawBox( x, y, z, size, size, size ); + ofDrawBox(x, y, z, size, size, size); } //---------------------------------------------------------- -void ofBox(const glm::vec3& position, float width, float height, float depth) { - ofDrawBox( position.x, position.y, position.z, width, height, depth ); +void ofBox(const glm::vec3 & position, float width, float height, float depth) { + ofDrawBox(position.x, position.y, position.z, width, height, depth); } //---------------------------------------------------------- -void ofBox(const glm::vec3& position, float size) { - ofDrawBox( position.x, position.y, position.z, size, size, size ); +void ofBox(const glm::vec3 & position, float size) { + ofDrawBox(position.x, position.y, position.z, size, size, size); } //---------------------------------------------------------- void ofBox(float size) { - ofDrawBox( size, size, size ); + ofDrawBox(size, size, size); } //---------------------------------------------------------- -void ofBox( float width, float height, float depth ) { - ofDrawBox(width,height,depth); +void ofBox(float width, float height, float depth) { + ofDrawBox(width, height, depth); } - - - - - - - - diff --git a/libs/openFrameworks/graphics/ofBitmapFont.cpp b/libs/openFrameworks/graphics/ofBitmapFont.cpp index e4f31082c98..8e6846474e0 100644 --- a/libs/openFrameworks/graphics/ofBitmapFont.cpp +++ b/libs/openFrameworks/graphics/ofBitmapFont.cpp @@ -1,9 +1,8 @@ - #include "ofBitmapFont.h" #include "ofMesh.h" #ifdef TARGET_ANDROID -#include "ofxAndroidUtils.h" + #include "ofxAndroidUtils.h" #endif // ============================================================== @@ -34,7 +33,7 @@ * * Copyright (c) 1999-2000 by Pawel W. Olszta * Written by Pawel W. Olszta, - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -47,7 +46,7 @@ */ // ============================================================== - +// clang-format off static const unsigned char bmpChar_8x13_000[] = { 8, 0, 0, 0,170, 0,130, 0,130, 0,130, 0,170, 0, 0}; static const unsigned char bmpChar_8x13_001[] = { 8, 0, 0, 0, 0, 16, 56,124,254,124, 56, 16, 0, 0, 0}; static const unsigned char bmpChar_8x13_002[] = { 8, 0,170, 85,170, 85,170, 85,170, 85,170, 85,170, 85,170}; @@ -323,78 +322,77 @@ static const unsigned char* bmpChar_8x13_Map[] = { bmpChar_8x13_000,bmpChar_8x13 bmpChar_8x13_224,bmpChar_8x13_225,bmpChar_8x13_226,bmpChar_8x13_227,bmpChar_8x13_228,bmpChar_8x13_229,bmpChar_8x13_230,bmpChar_8x13_231,bmpChar_8x13_232,bmpChar_8x13_233,bmpChar_8x13_234,bmpChar_8x13_235,bmpChar_8x13_236,bmpChar_8x13_237,bmpChar_8x13_238,bmpChar_8x13_239, bmpChar_8x13_240,bmpChar_8x13_241,bmpChar_8x13_242,bmpChar_8x13_243,bmpChar_8x13_244,bmpChar_8x13_245,bmpChar_8x13_246,bmpChar_8x13_247,bmpChar_8x13_248,bmpChar_8x13_249,bmpChar_8x13_250,bmpChar_8x13_251,bmpChar_8x13_252,bmpChar_8x13_253,bmpChar_8x13_254,bmpChar_8x13_255,nullptr}; - +// clang-format on #include "ofTexture.h" -static const float widthTex = 8.0f/256.0f; -static const float heightTex = 14.0f/256.0f; +static const float widthTex = 8.0f / 256.0f; +static const float heightTex = 14.0f / 256.0f; ofPixels ofBitmapFont::pixels; using std::numeric_limits; using std::string; -void ofBitmapFont::init(){ - if(pixels.isAllocated()) return; - pixels.allocate(16*16, 16*16, OF_PIXELS_GRAY_ALPHA); // letter size:8x14pixels, texture size:16x8letters, gl_r: 1bytes/1pixel +void ofBitmapFont::init() { + if (pixels.isAllocated()) return; + pixels.allocate(16 * 16, 16 * 16, OF_PIXELS_GRAY_ALPHA); // letter size:8x14pixels, texture size:16x8letters, gl_r: 1bytes/1pixel pixels.set(0); for (size_t i = 0; i < 256; i++) { const unsigned char * face = bmpChar_8x13_Map[i]; - for (size_t j = 1; j < 15; j++){ - for (size_t k = 0; k < 8; k++){ - if ( ((face[15-j] << k) & (128)) > 0 ){ - pixels[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2] = 255; - pixels[(((i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*2+1] = 255; + for (size_t j = 1; j < 15; j++) { + for (size_t k = 0; k < 8; k++) { + if (((face[15 - j] << k) & (128)) > 0) { + pixels[(((i / 16)) * 16 * 16 * 16 + (i % 16) * 16 + (j - 1) * 16 * 16 + k) * 2] = 255; + pixels[(((i / 16)) * 16 * 16 * 16 + (i % 16) * 16 + (j - 1) * 16 * 16 + k) * 2 + 1] = 255; } } } } - } - + //--------------------------------------------------------------------- -static void addBitmapCharacter(ofMesh & charMesh, int & vertexCount, int character, int x , int y, bool vFlipped){ - if (character < 128) { +static void addBitmapCharacter(ofMesh & charMesh, int & vertexCount, int character, int x, int y, bool vFlipped) { + if (character < 128) { - float posTexW = (float)(character % 16)/16.0f; - float posTexH = ((int)(character / 16.0f))/16.0f; + float posTexW = (float)(character % 16) / 16.0f; + float posTexH = ((int)(character / 16.0f)) / 16.0f; float texY1 = posTexH; - float texY2 = posTexH+heightTex; + float texY2 = posTexH + heightTex; //TODO: look into a better fix. //old ofDrawBitmapString was 3 pixels higher, so this version renders text in a different position. //3 pixel adjustment corrects that when y is flpped 5 when it's not. int yOffset = 14; - if(!vFlipped){ + if (!vFlipped) { y += 5; y += yOffset; yOffset *= -1; - }else{ + } else { y -= 3; } size_t vC = vertexCount; - charMesh.getTexCoords()[vC] = {posTexW,texY1}; - charMesh.getTexCoords()[vC+1] = {posTexW + widthTex,texY1}; - charMesh.getTexCoords()[vC+2] = {posTexW+widthTex,texY2}; + charMesh.getTexCoords()[vC] = { posTexW, texY1 }; + charMesh.getTexCoords()[vC + 1] = { posTexW + widthTex, texY1 }; + charMesh.getTexCoords()[vC + 2] = { posTexW + widthTex, texY2 }; - charMesh.getTexCoords()[vC+3] = {posTexW + widthTex,texY2}; - charMesh.getTexCoords()[vC+4] = {posTexW,texY2}; - charMesh.getTexCoords()[vC+5] = {posTexW,texY1}; + charMesh.getTexCoords()[vC + 3] = { posTexW + widthTex, texY2 }; + charMesh.getTexCoords()[vC + 4] = { posTexW, texY2 }; + charMesh.getTexCoords()[vC + 5] = { posTexW, texY1 }; - charMesh.getVertices()[vC] = glm::vec3(x,y,0.f); - charMesh.getVertices()[vC+1] = glm::vec3(x+8,y,0.f); - charMesh.getVertices()[vC+2] = glm::vec3(x+8,y+yOffset,0.f); + charMesh.getVertices()[vC] = glm::vec3(x, y, 0.f); + charMesh.getVertices()[vC + 1] = glm::vec3(x + 8, y, 0.f); + charMesh.getVertices()[vC + 2] = glm::vec3(x + 8, y + yOffset, 0.f); - charMesh.getVertices()[vC+3] = glm::vec3(x+8,y+yOffset,0.f); - charMesh.getVertices()[vC+4] = glm::vec3(x,y+yOffset,0.f); - charMesh.getVertices()[vC+5] = glm::vec3(x,y,0.f); + charMesh.getVertices()[vC + 3] = glm::vec3(x + 8, y + yOffset, 0.f); + charMesh.getVertices()[vC + 4] = glm::vec3(x, y + yOffset, 0.f); + charMesh.getVertices()[vC + 5] = glm::vec3(x, y, 0.f); vertexCount += 6; - } + } } -ofMesh ofBitmapFont::getMesh(const string & text, int x, int y, ofDrawBitmapMode mode, bool vFlipped) const{ +ofMesh ofBitmapFont::getMesh(const string & text, int x, int y, ofBitmapMode mode, bool vFlipped) const { int len = (int)text.length(); float fontSize = 8.0f; @@ -405,37 +403,37 @@ ofMesh ofBitmapFont::getMesh(const string & text, int x, int y, ofDrawBitmapMode int vertexCount = 0; int column = 0; - float lineHeight = fontSize*1.7f; + float lineHeight = fontSize * 1.7f; int newLineDirection = 1.0f; - if(!vFlipped){ - newLineDirection = -1; + if (!vFlipped) { + newLineDirection = -1; // this would align multiline texts to the last line when vflip is disabled //int lines = ofStringTimesInString(textString,"\n"); //y = lines*lineHeight; } float sx = x; - float sy = y-fontSize; + float sy = y - fontSize; - for(int c = 0; c < len; c++){ - if(text[c] == '\n'){ + for (int c = 0; c < len; c++) { + if (text[c] == '\n') { - sy += lineHeight*newLineDirection; -// if(mode == OF_BITMAPMODE_SIMPLE) { - sx = x; -// } else { -// sx = 0; -// } + sy += lineHeight * newLineDirection; + // if(mode == OF_BITMAPMODE_SIMPLE) { + sx = x; + // } else { + // sx = 0; + // } column = 0; - } else if (text[c] == '\t'){ + } else if (text[c] == '\t') { //move the cursor to the position of the next tab //8 is the default tab spacing in osx terminal and windows command line int out = column + 8 - (column % 8); - sx += fontSize * (out-column); + sx += fontSize * (out - column); column = out; - } else if (text[c] >= 32){ + } else if (text[c] >= 32) { // < 32 = control characters - don't draw // solves a bug with control characters // getting drawn when they ought to not be @@ -449,48 +447,46 @@ ofMesh ofBitmapFont::getMesh(const string & text, int x, int y, ofDrawBitmapMode charMesh.getVertices().resize(vertexCount); charMesh.getTexCoords().resize(vertexCount); return charMesh; - } -ofBitmapFont::ofBitmapFont(){ +ofBitmapFont::ofBitmapFont() { #ifdef TARGET_ANDROID - ofAddListener(ofxAndroidEvents().unloadGL,this,&ofBitmapFont::unloadTexture); + ofAddListener(ofxAndroidEvents().unloadGL, this, &ofBitmapFont::unloadTexture); #endif } -ofBitmapFont::~ofBitmapFont(){ +ofBitmapFont::~ofBitmapFont() { #ifdef TARGET_ANDROID - ofRemoveListener(ofxAndroidEvents().unloadGL,this,&ofBitmapFont::unloadTexture); + ofRemoveListener(ofxAndroidEvents().unloadGL, this, &ofBitmapFont::unloadTexture); #endif } -void ofBitmapFont::unloadTexture(){ +void ofBitmapFont::unloadTexture() { texture.clear(); } -const ofTexture & ofBitmapFont::getTexture() const{ - if(!texture.isAllocated()){ +const ofTexture & ofBitmapFont::getTexture() const { + if (!texture.isAllocated()) { ofBitmapFont::init(); - texture.allocate(pixels,false); - texture.setTextureMinMagFilter(GL_LINEAR,GL_NEAREST); + texture.allocate(pixels, false); + texture.setTextureMinMagFilter(GL_LINEAR, GL_NEAREST); } return texture; } +ofRectangle ofBitmapFont::getBoundingBox(const string & text, int x, int y, ofBitmapMode mode, bool vFlipped) const { + if (text.empty()) { + return ofRectangle(x, y, 0, 0); + } -ofRectangle ofBitmapFont::getBoundingBox(const string & text, int x, int y, ofDrawBitmapMode mode, bool vFlipped) const{ - if(text.empty()){ - return ofRectangle(x,y,0,0); - } - - const ofMesh & mesh = getMesh(text,x,y, mode, vFlipped); - glm::vec2 max(numeric_limits::lowest(),numeric_limits::lowest()); - glm::vec2 min(numeric_limits::max(),numeric_limits::max()); - for(const auto & p : mesh.getVertices()){ - if(p.xmax.x) max.x = p.x; - if(p.y>max.y) max.y = p.y; + const ofMesh & mesh = getMesh(text, x, y, mode, vFlipped); + glm::vec2 max(numeric_limits::lowest(), numeric_limits::lowest()); + glm::vec2 min(numeric_limits::max(), numeric_limits::max()); + for (const auto & p : mesh.getVertices()) { + if (p.x < min.x) min.x = p.x; + if (p.y < min.y) min.y = p.y; + if (p.x > max.x) max.x = p.x; + if (p.y > max.y) max.y = p.y; } - return ofRectangle(min,max); + return ofRectangle(min, max); } diff --git a/libs/openFrameworks/graphics/ofBitmapFont.h b/libs/openFrameworks/graphics/ofBitmapFont.h index f7a812af5d2..e44eedd8e63 100644 --- a/libs/openFrameworks/graphics/ofBitmapFont.h +++ b/libs/openFrameworks/graphics/ofBitmapFont.h @@ -1,28 +1,25 @@ #pragma once -#include "ofRectangle.h" -#include "ofPixels.h" -#include "ofTexture.h" -#include "ofGraphics.h" #include "ofConstants.h" +#include "ofGraphics.h" +#include "ofPixels.h" +#include "ofRectangle.h" +#include "ofTexture.h" -/* - - note, the data in this code is taken from freeglut, and included in OF for compatability - with non glut windowing toolkits. see .cpp for license info - - also, note that while this is used internally in ofGraphics, it's not really useful for end user usage. - - */ +// note, the data in this code is taken from freeglut, and included in OF for compatability +// with non glut windowing toolkits. see .cpp for license info +// +// also, note that while this is used internally in ofGraphics, it's not really useful for end user usage. -class ofBitmapFont{ +class ofBitmapFont { public: ofBitmapFont(); ~ofBitmapFont(); - ofMesh getMesh(const std::string & text, int x, int y, ofDrawBitmapMode mode=OF_BITMAPMODE_MODEL_BILLBOARD, bool vFlipped=true) const; + ofMesh getMesh(const std::string & text, int x, int y, ofBitmapMode mode = OF_BITMAPMODE_MODEL_BILLBOARD, bool vFlipped = true) const; const ofTexture & getTexture() const; - ofRectangle getBoundingBox(const std::string & text, int x, int y, ofDrawBitmapMode mode = ofGetStyle().drawBitmapMode, bool vFlipped = ofIsVFlipped()) const; + ofRectangle getBoundingBox(const std::string & text, int x, int y, ofBitmapMode mode = ofGetStyle().bitmapMode, bool vFlipped = ofIsVFlipped()) const; + private: static void init(); static ofPixels pixels; diff --git a/libs/openFrameworks/graphics/ofCairoRenderer.cpp b/libs/openFrameworks/graphics/ofCairoRenderer.cpp index b1412191ab8..a1cf7d40b16 100644 --- a/libs/openFrameworks/graphics/ofCairoRenderer.cpp +++ b/libs/openFrameworks/graphics/ofCairoRenderer.cpp @@ -1,28 +1,27 @@ +#include "cairo-features.h" +#include "cairo-pdf.h" +#include "cairo-svg.h" #include "ofCairoRenderer.h" -#include "ofMesh.h" +#include "ofGraphics.h" #include "ofImage.h" +#include "ofMesh.h" #include "ofTrueTypeFont.h" -#include "ofGraphics.h" #include "ofVideoBaseTypes.h" -#include "cairo-features.h" -#include "cairo-pdf.h" -#include "cairo-svg.h" -using std::vector; using std::string; +using std::vector; -const string ofCairoRenderer::TYPE="cairo"; +const string ofCairoRenderer::TYPE = "cairo"; -_cairo_status ofCairoRenderer::stream_function(void *closure,const unsigned char *data, unsigned int length){ - ((ofCairoRenderer*)closure)->streamBuffer.append((const char*)data,length); +_cairo_status ofCairoRenderer::stream_function(void * closure, const unsigned char * data, unsigned int length) { + ((ofCairoRenderer *)closure)->streamBuffer.append((const char *)data, length); return CAIRO_STATUS_SUCCESS; } ofCairoRenderer::ofCairoRenderer() -:graphics3d(this) -,projection(1) -,modelView(1) -{ + : graphics3d(this) + , projection(1) + , modelView(1) { type = PDF; surface = nullptr; cr = nullptr; @@ -30,15 +29,15 @@ ofCairoRenderer::ofCairoRenderer() page = 0; multiPage = false; b3D = false; - currentMatrixMode=OF_MATRIX_MODELVIEW; + currentMatrixMode = OF_MATRIX_MODELVIEW; } -ofCairoRenderer::~ofCairoRenderer(){ +ofCairoRenderer::~ofCairoRenderer() { close(); } -void ofCairoRenderer::setup(const of::filesystem::path & _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize){ - if( outputsize.width == 0 || outputsize.height == 0 ){ +void ofCairoRenderer::setup(const of::filesystem::path & _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize) { + if (outputsize.width == 0 || outputsize.height == 0) { outputsize.set(0, 0, ofGetViewportWidth(), ofGetViewportHeight()); } @@ -46,49 +45,49 @@ void ofCairoRenderer::setup(const of::filesystem::path & _filename, Type _type, type = _type; streamBuffer.clear(); - if(type == FROM_FILE_EXTENSION){ + if (type == FROM_FILE_EXTENSION) { auto ext = filename.extension(); - if(ext == of::filesystem::path{".svg"} || ext == of::filesystem::path{".SVG"} ){ + if (ext == of::filesystem::path { ".svg" } || ext == of::filesystem::path { ".SVG" }) { type = SVG; - }else if(ext == of::filesystem::path {".pdf"} || ext == of::filesystem::path{".PDF"} ){ + } else if (ext == of::filesystem::path { ".pdf" } || ext == of::filesystem::path { ".PDF" }) { type = PDF; - }else{ // default to image + } else { // default to image type = IMAGE; } } - if(filename != "") { - switch(type) { - case PDF: - case SVG: - case IMAGE: - ofFilePath::createEnclosingDirectory(filename); - case FROM_FILE_EXTENSION: - break; + if (filename != "") { + switch (type) { + case PDF: + case SVG: + case IMAGE: + ofFilePath::createEnclosingDirectory(filename); + case FROM_FILE_EXTENSION: + break; } } - switch(type){ + switch (type) { case PDF: - if(filename==""){ - surface = cairo_pdf_surface_create_for_stream(&ofCairoRenderer::stream_function,this,outputsize.width, outputsize.height); - }else{ + if (filename == "") { + surface = cairo_pdf_surface_create_for_stream(&ofCairoRenderer::stream_function, this, outputsize.width, outputsize.height); + } else { // FIXME: Future - once ofToDataPath returns fs::path, remove c_str() - surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(),outputsize.width, outputsize.height); + surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(), outputsize.width, outputsize.height); } break; case SVG: - if(filename==""){ - surface = cairo_svg_surface_create_for_stream(&ofCairoRenderer::stream_function,this,outputsize.width, outputsize.height); - }else{ + if (filename == "") { + surface = cairo_svg_surface_create_for_stream(&ofCairoRenderer::stream_function, this, outputsize.width, outputsize.height); + } else { // FIXME: Future - once ofToDataPath returns fs::path, remove c_str() - surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(),outputsize.width, outputsize.height); + surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(), outputsize.width, outputsize.height); } break; case IMAGE: imageBuffer.allocate(outputsize.width, outputsize.height, OF_PIXELS_BGRA); imageBuffer.set(0); - surface = cairo_image_surface_create_for_data(imageBuffer.getData(),CAIRO_FORMAT_ARGB32,outputsize.width, outputsize.height,outputsize.width*4); + surface = cairo_image_surface_create_for_data(imageBuffer.getData(), CAIRO_FORMAT_ARGB32, outputsize.width, outputsize.height, outputsize.width * 4); break; case FROM_FILE_EXTENSION: ofLogFatalError("ofCairoRenderer") << "setup(): couldn't determine type from extension for filename: \"" << _filename << "\"!"; @@ -99,7 +98,7 @@ void ofCairoRenderer::setup(const of::filesystem::path & _filename, Type _type, } cr = cairo_create(surface); - cairo_set_antialias(cr,CAIRO_ANTIALIAS_SUBPIXEL); + cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); viewportRect = outputsize; originalViewport = outputsize; viewport(viewportRect); @@ -109,53 +108,52 @@ void ofCairoRenderer::setup(const of::filesystem::path & _filename, Type _type, setupGraphicDefaults(); } -void ofCairoRenderer::setupMemoryOnly(Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize){ - setup("",_type,multiPage_,b3D_,outputsize); +void ofCairoRenderer::setupMemoryOnly(Type _type, bool multiPage_, bool b3D_, ofRectangle outputsize) { + setup("", _type, multiPage_, b3D_, outputsize); } -void ofCairoRenderer::flush(){ - if(surface){ +void ofCairoRenderer::flush() { + if (surface) { cairo_surface_flush(surface); } } -void ofCairoRenderer::close(){ - if(surface){ +void ofCairoRenderer::close() { + if (surface) { cairo_surface_flush(surface); - if(type==IMAGE && filename!=""){ - ofSaveImage(imageBuffer,filename); + if (type == IMAGE && filename != "") { + ofSaveImage(imageBuffer, filename); } cairo_surface_finish(surface); cairo_surface_destroy(surface); surface = nullptr; } - if(cr){ + if (cr) { cairo_destroy(cr); cr = nullptr; } } - -void ofCairoRenderer::startRender(){ +void ofCairoRenderer::startRender() { setStyle(currentStyle); - if(page==0 || !multiPage){ - page=1; - }else{ + if (page == 0 || !multiPage) { + page = 1; + } else { page++; - if(getBackgroundAuto()){ + if (getBackgroundAuto()) { cairo_show_page(cr); clear(); - }else{ + } else { cairo_copy_page(cr); } } } -void ofCairoRenderer::finishRender(){ +void ofCairoRenderer::finishRender() { cairo_surface_flush(surface); } -void ofCairoRenderer::setStyle(const ofStyle & style){ +void ofCairoRenderer::setStyle(const ofStyle & style) { //color setColor(style.color.r, style.color.g, style.color.b, style.color.a); @@ -179,7 +177,7 @@ void ofCairoRenderer::setStyle(const ofStyle & style){ setPolyMode(style.polyMode); //fill - setFillMode(style.bFill?OF_FILLED:OF_OUTLINE); + setFillMode(style.bFill ? OF_FILLED : OF_OUTLINE); //smoothing //setSmoothingEnabled(style.smoothing); @@ -188,77 +186,78 @@ void ofCairoRenderer::setStyle(const ofStyle & style){ setBlendMode(style.blendingMode); //bitmap draw mode - //setDrawBitmapMode(style.drawBitmapMode); + //setBitmapMode(style.bitmapMode); currentStyle = style; } -void ofCairoRenderer::setCurveResolution(int resolution){ +void ofCairoRenderer::setCurveResolution(int resolution) { currentStyle.curveResolution = resolution; path.setCurveResolution(resolution); } -void ofCairoRenderer::draw(const ofPath & shape) const{ +void ofCairoRenderer::draw(const ofPath & shape) const { cairo_new_path(cr); const vector & commands = shape.getCommands(); - for(int i=0;i<(int)commands.size();i++){ + for (int i = 0; i < (int)commands.size(); i++) { draw(commands[i]); } cairo_fill_rule_t cairo_poly_mode; - if(shape.getWindingMode()==OF_POLY_WINDING_ODD) cairo_poly_mode=CAIRO_FILL_RULE_EVEN_ODD; - else cairo_poly_mode=CAIRO_FILL_RULE_WINDING; - - cairo_set_fill_rule(cr,cairo_poly_mode); + if (shape.getWindingMode() == OF_POLY_WINDING_ODD) + cairo_poly_mode = CAIRO_FILL_RULE_EVEN_ODD; + else + cairo_poly_mode = CAIRO_FILL_RULE_WINDING; + cairo_set_fill_rule(cr, cairo_poly_mode); ofFloatColor prevColor; - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { prevColor = currentStyle.color; } - if(shape.isFilled()){ - if(shape.getUseShapeColor()){ + if (shape.isFilled()) { + if (shape.getUseShapeColor()) { ofFloatColor c = shape.getFillColor(); c.a = shape.getFillColor().a; cairo_set_source_rgba(cr, c.r, c.g, c.b, c.a); } - if(shape.hasOutline()){ - cairo_fill_preserve( cr ); - }else{ + if (shape.hasOutline()) { + cairo_fill_preserve(cr); + } else { cairo_fill(cr); } } - if(shape.hasOutline()){ + if (shape.hasOutline()) { float lineWidth = currentStyle.lineWidth; - if(shape.getUseShapeColor()){ + if (shape.getUseShapeColor()) { ofFloatColor c = shape.getStrokeColor(); c.a = shape.getStrokeColor().a; cairo_set_source_rgba(cr, c.r, c.g, c.b, c.a); } - cairo_set_line_width( cr, shape.getStrokeWidth() ); - cairo_stroke( cr ); - cairo_set_line_width( cr, lineWidth ); + cairo_set_line_width(cr, shape.getStrokeWidth()); + cairo_stroke(cr); + cairo_set_line_width(cr, lineWidth); } - if(shape.getUseShapeColor()){ - const_cast(this)->setColor(prevColor); + if (shape.getUseShapeColor()) { + const_cast(this)->setColor(prevColor); } } -void ofCairoRenderer::draw(const ofPolyline & poly) const{ +void ofCairoRenderer::draw(const ofPolyline & poly) const { cairo_new_path(cr); - for(int i=0;i<(int)poly.size();i++){ - cairo_line_to(cr,poly.getVertices()[i].x,poly.getVertices()[i].y); + for (int i = 0; i < (int)poly.size(); i++) { + cairo_line_to(cr, poly.getVertices()[i].x, poly.getVertices()[i].y); } - if(poly.isClosed()) + if (poly.isClosed()) cairo_close_path(cr); - cairo_stroke( cr ); + cairo_stroke(cr); } -void ofCairoRenderer::draw(const vector & vertexData, ofPrimitiveMode drawMode) const{ - if(vertexData.size()==0) return; - ofCairoRenderer * mut_this = const_cast(this); +void ofCairoRenderer::draw(const vector & vertexData, ofPrimitiveMode drawMode) const { + if (vertexData.size() == 0) return; + ofCairoRenderer * mut_this = const_cast(this); mut_this->pushMatrix(); cairo_matrix_t matrix; @@ -266,41 +265,41 @@ void ofCairoRenderer::draw(const vector & vertexData, ofPrimitiveMode cairo_new_path(cr); //if(indices.getNumIndices()){ - int i = 1; - auto v = transform(vertexData[0]); - glm::vec3 v2; - cairo_move_to(cr,v.x,v.y); - if(drawMode==OF_PRIMITIVE_TRIANGLE_STRIP){ - v = transform(vertexData[1]); - cairo_line_to(cr,v.x,v.y); - v = transform(vertexData[2]); - cairo_line_to(cr,v.x,v.y); - i=2; - } - for(; i<(int)vertexData.size(); i++){ - v = transform(vertexData[i]); - switch(drawMode){ - case(OF_PRIMITIVE_TRIANGLES): - if((i+1)%3==0){ - cairo_line_to(cr,v.x,v.y); - v2 = transform(vertexData[i-2]); - cairo_line_to(cr,v2.x,v2.y); - cairo_move_to(cr,v.x,v.y); - }else if((i+3)%3==0){ - cairo_move_to(cr,v.x,v.y); - }else{ - cairo_line_to(cr,v.x,v.y); - } + int i = 1; + auto v = transform(vertexData[0]); + glm::vec3 v2; + cairo_move_to(cr, v.x, v.y); + if (drawMode == OF_PRIMITIVE_TRIANGLE_STRIP) { + v = transform(vertexData[1]); + cairo_line_to(cr, v.x, v.y); + v = transform(vertexData[2]); + cairo_line_to(cr, v.x, v.y); + i = 2; + } + for (; i < (int)vertexData.size(); i++) { + v = transform(vertexData[i]); + switch (drawMode) { + case (OF_PRIMITIVE_TRIANGLES): + if ((i + 1) % 3 == 0) { + cairo_line_to(cr, v.x, v.y); + v2 = transform(vertexData[i - 2]); + cairo_line_to(cr, v2.x, v2.y); + cairo_move_to(cr, v.x, v.y); + } else if ((i + 3) % 3 == 0) { + cairo_move_to(cr, v.x, v.y); + } else { + cairo_line_to(cr, v.x, v.y); + } break; - case(OF_PRIMITIVE_TRIANGLE_STRIP): - v2 = transform(vertexData[i-2]); - cairo_line_to(cr,v.x,v.y); - cairo_line_to(cr,v2.x,v2.y); - cairo_move_to(cr,v.x,v.y); + case (OF_PRIMITIVE_TRIANGLE_STRIP): + v2 = transform(vertexData[i - 2]); + cairo_line_to(cr, v.x, v.y); + cairo_line_to(cr, v2.x, v2.y); + cairo_move_to(cr, v.x, v.y); break; - case(OF_PRIMITIVE_TRIANGLE_FAN): - /*triangles.addIndex((GLuint)0); + case (OF_PRIMITIVE_TRIANGLE_FAN): + /*triangles.addIndex((GLuint)0); triangles.addIndex((GLuint)1); triangles.addIndex((GLuint)2); for(int i = 2; i < primitive.getNumVertices()-1;i++){ @@ -309,34 +308,34 @@ void ofCairoRenderer::draw(const vector & vertexData, ofPrimitiveMode triangles.addIndex((GLuint)i+1); }*/ break; - default:break; - } + default: + break; } + } - cairo_move_to(cr,vertexData[vertexData.size()-1].x,vertexData[vertexData.size()-1].y); - cairo_stroke( cr ); + cairo_move_to(cr, vertexData[vertexData.size() - 1].x, vertexData[vertexData.size() - 1].y); + cairo_stroke(cr); mut_this->popMatrix(); } - -glm::vec3 ofCairoRenderer::transform(glm::vec3 vec) const{ - if(!b3D) return vec; +glm::vec3 ofCairoRenderer::transform(glm::vec3 vec) const { + if (!b3D) return vec; auto vec4 = projection * modelView * glm::vec4(vec, 1.0); vec = glm::vec3(vec4) / vec4.w; //vec.set(vec.x/vec.z*viewportRect.width*0.5-ofGetWidth()*0.5-viewportRect.x,vec.y/vec.z*viewportRect.height*0.5-ofGetHeight()*0.5-viewportRect.y); - vec = {vec.x/vec.z*viewportRect.width*0.5, vec.y/vec.z*viewportRect.height*0.5, 0.f}; + vec = { vec.x / vec.z * viewportRect.width * 0.5, vec.y / vec.z * viewportRect.height * 0.5, 0.f }; return vec; } -void ofCairoRenderer::draw(const ofMesh & primitive, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const{ - if(useColors || useTextures || useNormals){ - ofLogWarning("ofCairoRenderer") << "draw(): cairo mesh rendering doesn't support colors, textures, or normals. drawing wireframe ..."; - } - if(primitive.getNumVertices() == 0){ +void ofCairoRenderer::draw(const ofMesh & primitive, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const { + if (useColors || useTextures || useNormals) { + ofLogWarning("ofCairoRenderer") << "draw(): cairo mesh rendering doesn't support colors, textures, or normals. drawing wireframe ..."; + } + if (primitive.getNumVertices() == 0) { return; } - if(primitive.getNumIndices() == 0){ + if (primitive.getNumIndices() == 0) { ofMesh indexedMesh = primitive; indexedMesh.setupIndicesAuto(); draw(indexedMesh, mode, useColors, useTextures, useNormals); @@ -351,38 +350,38 @@ void ofCairoRenderer::draw(const ofMesh & primitive, ofPolyRenderMode mode, bool std::size_t i = 1; auto v = transform(primitive.getVertex(primitive.getIndex(0))); glm::vec3 v2; - cairo_move_to(cr,v.x,v.y); - if(primitive.getMode()==OF_PRIMITIVE_TRIANGLE_STRIP){ + cairo_move_to(cr, v.x, v.y); + if (primitive.getMode() == OF_PRIMITIVE_TRIANGLE_STRIP) { v = transform(primitive.getVertex(primitive.getIndex(1))); - cairo_line_to(cr,v.x,v.y); + cairo_line_to(cr, v.x, v.y); v = transform(primitive.getVertex(primitive.getIndex(2))); - cairo_line_to(cr,v.x,v.y); - i=2; + cairo_line_to(cr, v.x, v.y); + i = 2; } - for(; i0){ + if (currentStyle.lineWidth > 0) { - cairo_stroke( cr ); + cairo_stroke(cr); } } //---------------------------------------------------------- -void ofCairoRenderer::draw( const of3dPrimitive& model, ofPolyRenderMode renderType ) const{ +void ofCairoRenderer::draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const { - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(model.getGlobalTransformMatrix()); - const ofMesh& mesh = model.getMesh(); - draw( mesh, renderType ); - - const_cast(this)->popMatrix(); + const ofMesh & mesh = model.getMesh(); + draw(mesh, renderType); + const_cast(this)->popMatrix(); } -void ofCairoRenderer::draw(const ofNode& node) const{ - const_cast(this)->pushMatrix(); - const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); +void ofCairoRenderer::draw(const ofNode & node) const { + const_cast(this)->pushMatrix(); + const_cast(this)->multMatrix(node.getGlobalTransformMatrix()); node.customDraw(this); - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } -void ofCairoRenderer::draw(const ofPath::Command & command) const{ - if(!surface || !cr) return; - ofCairoRenderer * mut_this = const_cast(this); - switch(command.type){ +void ofCairoRenderer::draw(const ofPath::Command & command) const { + if (!surface || !cr) return; + ofCairoRenderer * mut_this = const_cast(this); + switch (command.type) { case ofPath::Command::moveTo: curvePoints.clear(); - cairo_move_to(cr,command.to.x,command.to.y); + cairo_move_to(cr, command.to.x, command.to.y); break; case ofPath::Command::lineTo: curvePoints.clear(); - cairo_line_to(cr,command.to.x,command.to.y); + cairo_line_to(cr, command.to.x, command.to.y); break; - case ofPath::Command::curveTo: curvePoints.push_back(command.to); //code adapted from ofxVectorGraphics to convert catmull rom to bezier - if(curvePoints.size()==4){ - auto p1=curvePoints[0]; - auto p2=curvePoints[1]; - auto p3=curvePoints[2]; - auto p4=curvePoints[3]; + if (curvePoints.size() == 4) { + auto p1 = curvePoints[0]; + auto p2 = curvePoints[1]; + auto p3 = curvePoints[2]; + auto p4 = curvePoints[3]; //SUPER WEIRD MAGIC CONSTANT = 1/6 (this works 100% can someone explain it?) - auto cp1 = p2 + ( p3 - p1 ) * (1.0f/6.f); - auto cp2 = p3 + ( p2 - p4 ) * (1.0f/6.f); + auto cp1 = p2 + (p3 - p1) * (1.0f / 6.f); + auto cp2 = p3 + (p2 - p4) * (1.0f / 6.f); - cairo_curve_to( cr, cp1.x, cp1.y, cp2.x, cp2.y, p3.x, p3.y ); + cairo_curve_to(cr, cp1.x, cp1.y, cp2.x, cp2.y, p3.x, p3.y); curvePoints.pop_front(); } break; - case ofPath::Command::bezierTo: curvePoints.clear(); - cairo_curve_to(cr,command.cp1.x,command.cp1.y,command.cp2.x,command.cp2.y,command.to.x,command.to.y); + cairo_curve_to(cr, command.cp1.x, command.cp1.y, command.cp2.x, command.cp2.y, command.to.x, command.to.y); break; case ofPath::Command::quadBezierTo: curvePoints.clear(); - cairo_curve_to(cr,command.cp1.x,command.cp1.y,command.cp2.x,command.cp2.y,command.to.x,command.to.y); + cairo_curve_to(cr, command.cp1.x, command.cp1.y, command.cp2.x, command.cp2.y, command.to.x, command.to.y); break; - case ofPath::Command::arc: curvePoints.clear(); // elliptic arcs not directly supported in cairo, lets scale y - if(command.radiusX!=command.radiusY){ - float ellipse_ratio = command.radiusY/command.radiusX; + if (command.radiusX != command.radiusY) { + float ellipse_ratio = command.radiusY / command.radiusX; mut_this->pushMatrix(); - mut_this->translate(0,-command.to.y*ellipse_ratio); - mut_this->scale(1,ellipse_ratio); - mut_this->translate(0,command.to.y/ellipse_ratio); - cairo_arc(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); + mut_this->translate(0, -command.to.y * ellipse_ratio); + mut_this->scale(1, ellipse_ratio); + mut_this->translate(0, command.to.y / ellipse_ratio); + cairo_arc(cr, command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); //cairo_set_matrix(cr,&stored_matrix); mut_this->popMatrix(); - }else{ - cairo_arc(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); + } else { + cairo_arc(cr, command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); } break; case ofPath::Command::arcNegative: curvePoints.clear(); // elliptic arcs not directly supported in cairo, lets scale y - if(command.radiusX!=command.radiusY){ - float ellipse_ratio = command.radiusY/command.radiusX; + if (command.radiusX != command.radiusY) { + float ellipse_ratio = command.radiusY / command.radiusX; mut_this->pushMatrix(); - mut_this->translate(0,-command.to.y*ellipse_ratio); - mut_this->scale(1,ellipse_ratio); - mut_this->translate(0,command.to.y/ellipse_ratio); - cairo_arc_negative(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); + mut_this->translate(0, -command.to.y * ellipse_ratio); + mut_this->scale(1, ellipse_ratio); + mut_this->translate(0, command.to.y / ellipse_ratio); + cairo_arc_negative(cr, command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); //cairo_set_matrix(cr,&stored_matrix); mut_this->popMatrix(); - }else{ - cairo_arc_negative(cr,command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); + } else { + cairo_arc_negative(cr, command.to.x, command.to.y, command.radiusX, ofDegToRad(command.angleBegin), ofDegToRad(command.angleEnd)); } - break; + break; case ofPath::Command::close: cairo_close_path(cr); break; - } - - } //-------------------------------------------- -void ofCairoRenderer::draw(const ofPixels & raw, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ +void ofCairoRenderer::draw(const ofPixels & raw, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { bool shouldCrop = sx != 0 || sy != 0 || sw != w || sh != h; ofPixels cropped; - if(shouldCrop) { + if (shouldCrop) { cropped.allocate(sw, sh, raw.getPixelFormat()); raw.cropTo(cropped, sx, sy, sw, sh); } const ofPixels & pix = shouldCrop ? cropped : raw; - ofCairoRenderer * mut_this = const_cast(this); + ofCairoRenderer * mut_this = const_cast(this); mut_this->pushMatrix(); - mut_this->translate(x,y,z); - mut_this->scale(w/pix.getWidth(),h/pix.getHeight()); - cairo_surface_t *image; - int stride=0; - int picsize = pix.getWidth()* pix.getHeight(); - const unsigned char *imgPix = pix.getData(); + mut_this->translate(x, y, z); + mut_this->scale(w / pix.getWidth(), h / pix.getHeight()); + cairo_surface_t * image; + int stride = 0; + int picsize = pix.getWidth() * pix.getHeight(); + const unsigned char * imgPix = pix.getData(); vector swapPixels; - switch(pix.getImageType()){ + switch (pix.getImageType()) { case OF_IMAGE_COLOR: #ifdef TARGET_LITTLE_ENDIAN swapPixels.resize(picsize * 4); - for(int p= 0; ppopMatrix(); return; break; } - cairo_set_source_surface (cr, image, 0,0); - cairo_paint (cr); + cairo_set_source_surface(cr, image, 0, 0); + cairo_paint(cr); cairo_surface_flush(image); - cairo_surface_destroy (image); + cairo_surface_destroy(image); mut_this->popMatrix(); } //-------------------------------------------- -void ofCairoRenderer::draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - draw(img.getPixels(),x,y,z,w,h,sx,sy,sw,sh); +void ofCairoRenderer::draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + draw(img.getPixels(), x, y, z, w, h, sx, sy, sw, sh); } //-------------------------------------------- -void ofCairoRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ +void ofCairoRenderer::draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { ofPixels tmp = image.getPixels(); - draw(tmp,x,y,z,w,h,sx,sy,sw,sh); + draw(tmp, x, y, z, w, h, sx, sy, sw, sh); } //-------------------------------------------- -void ofCairoRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ +void ofCairoRenderer::draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { ofPixels tmp = image.getPixels(); - draw(tmp,x,y,z,w,h,sx,sy,sw,sh); + draw(tmp, x, y, z, w, h, sx, sy, sw, sh); } //-------------------------------------------- -void ofCairoRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{ - draw(video.getPixels(),x,y,0,w,h,x,y,w,h); +void ofCairoRenderer::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const { + draw(video.getPixels(), x, y, 0, w, h, x, y, w, h); } -ofPath & ofCairoRenderer::getPath(){ +ofPath & ofCairoRenderer::getPath() { return path; } //-------------------------------------------- -void ofCairoRenderer::setRectMode(ofRectMode mode){ +void ofCairoRenderer::setRectMode(ofRectMode mode) { currentStyle.rectMode = mode; } //-------------------------------------------- -ofRectMode ofCairoRenderer::getRectMode(){ +ofRectMode ofCairoRenderer::getRectMode() { return currentStyle.rectMode; } //-------------------------------------------- -void ofCairoRenderer::setFillMode(ofFillFlag fill){ +void ofCairoRenderer::setFillMode(ofFillFlag fill) { currentStyle.bFill = fill; - if(currentStyle.bFill){ + if (currentStyle.bFill) { path.setFilled(true); path.setStrokeWidth(0); - }else{ + } else { path.setFilled(false); path.setStrokeWidth(currentStyle.lineWidth); } } //-------------------------------------------- -ofFillFlag ofCairoRenderer::getFillMode(){ - if(currentStyle.bFill){ +ofFillFlag ofCairoRenderer::getFillMode() { + if (currentStyle.bFill) { return OF_FILLED; - }else{ + } else { return OF_OUTLINE; } } //-------------------------------------------- -void ofCairoRenderer::setLineWidth(float lineWidth){ +void ofCairoRenderer::setLineWidth(float lineWidth) { currentStyle.lineWidth = lineWidth; - if(!currentStyle.bFill){ + if (!currentStyle.bFill) { path.setStrokeWidth(lineWidth); } - cairo_set_line_width( cr, lineWidth ); + cairo_set_line_width(cr, lineWidth); } //---------------------------------------------------------- @@ -670,248 +663,245 @@ void ofCairoRenderer::setDepthTest(bool depthTest) { } //-------------------------------------------- -void ofCairoRenderer::setBlendMode(ofBlendMode blendMode){ - switch (blendMode){ - case OF_BLENDMODE_ALPHA:{ - cairo_set_operator(cr,CAIRO_OPERATOR_OVER); - break; - } +void ofCairoRenderer::setBlendMode(ofBlendMode blendMode) { + switch (blendMode) { + case OF_BLENDMODE_ALPHA: { + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + break; + } - case OF_BLENDMODE_ADD:{ - cairo_set_operator(cr,CAIRO_OPERATOR_ADD); - break; - } -#if (CAIRO_VERSION_MAJOR==1 && CAIRO_VERSION_MINOR>=10) || CAIRO_VERSION_MAJOR>1 - case OF_BLENDMODE_MULTIPLY:{ - cairo_set_operator(cr,CAIRO_OPERATOR_MULTIPLY); - break; - } + case OF_BLENDMODE_ADD: { + cairo_set_operator(cr, CAIRO_OPERATOR_ADD); + break; + } +#if (CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR >= 10) || CAIRO_VERSION_MAJOR > 1 + case OF_BLENDMODE_MULTIPLY: { + cairo_set_operator(cr, CAIRO_OPERATOR_MULTIPLY); + break; + } - case OF_BLENDMODE_SCREEN:{ - cairo_set_operator(cr,CAIRO_OPERATOR_SCREEN); - break; - } + case OF_BLENDMODE_SCREEN: { + cairo_set_operator(cr, CAIRO_OPERATOR_SCREEN); + break; + } - case OF_BLENDMODE_SUBTRACT:{ - cairo_set_operator(cr,CAIRO_OPERATOR_DIFFERENCE); - break; - } + case OF_BLENDMODE_SUBTRACT: { + cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); + break; + } #endif - default: - break; + default: + break; } } //-------------------------------------------- -void ofCairoRenderer::setLineSmoothing(bool smooth){ - +void ofCairoRenderer::setLineSmoothing(bool smooth) { } - // color options //-------------------------------------------- -void ofCairoRenderer::setColor(float r, float g, float b){ - setColor(r,g,b,1.f); +void ofCairoRenderer::setColor(float r, float g, float b) { + setColor(r, g, b, 1.f); }; //-------------------------------------------- -void ofCairoRenderer::setColor(float r, float g, float b, float a){ +void ofCairoRenderer::setColor(float r, float g, float b, float a) { cairo_set_source_rgba(cr, r, g, b, a); - currentStyle.color.set(r,g,b,a); + currentStyle.color.set(r, g, b, a); }; //-------------------------------------------- -void ofCairoRenderer::setColor(const ofFloatColor & c){ - setColor(c.r,c.g,c.b,c.a); +void ofCairoRenderer::setColor(const ofFloatColor & c) { + setColor(c.r, c.g, c.b, c.a); }; //-------------------------------------------- -void ofCairoRenderer::setColor(const ofFloatColor & c, float _a){ - setColor(c.r,c.g,c.b,_a); +void ofCairoRenderer::setColor(const ofFloatColor & c, float _a) { + setColor(c.r, c.g, c.b, _a); }; //-------------------------------------------- -void ofCairoRenderer::setColor(float gray){ - setColor(gray,gray,gray,1.f); +void ofCairoRenderer::setColor(float gray) { + setColor(gray, gray, gray, 1.f); }; //-------------------------------------------- -void ofCairoRenderer::setHexColor( int hexColor ){ +void ofCairoRenderer::setHexColor(int hexColor) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - setColor((float)r/255.f,(float)g/255.f,(float)b/255.f); + setColor((float)r / 255.f, (float)g / 255.f, (float)b / 255.f); }; //-------------------------------------------- // transformations //our openGL wrappers -glm::mat4 ofCairoRenderer::getCurrentMatrix(ofMatrixMode matrixMode_) const{ +glm::mat4 ofCairoRenderer::getCurrentMatrix(ofMatrixMode matrixMode_) const { ofLogWarning() << "getCurrentMatrix not yet implemented for Cairo Renderer."; return glm::mat4(1.0); } //---------------------------------------------------------- -void ofCairoRenderer::pushMatrix(){ - if(!surface || !cr) return; +void ofCairoRenderer::pushMatrix() { + if (!surface || !cr) return; cairo_matrix_t matrix; - cairo_get_matrix(cr,&matrix); + cairo_get_matrix(cr, &matrix); matrixStack.push(matrix); - if(!b3D) return; + if (!b3D) return; modelViewStack.push(modelView); } //---------------------------------------------------------- -void ofCairoRenderer::popMatrix(){ - if(!surface || !cr) return; - cairo_set_matrix(cr,&matrixStack.top()); +void ofCairoRenderer::popMatrix() { + if (!surface || !cr) return; + cairo_set_matrix(cr, &matrixStack.top()); matrixStack.pop(); - if(!b3D) return; + if (!b3D) return; modelView = modelViewStack.top(); modelViewStack.pop(); } //---------------------------------------------------------- -void ofCairoRenderer::translate(float x, float y, float z ){ - if(!surface || !cr) return; +void ofCairoRenderer::translate(float x, float y, float z) { + if (!surface || !cr) return; cairo_matrix_t matrix; - cairo_get_matrix(cr,&matrix); - cairo_matrix_translate(&matrix,x,y); - cairo_set_matrix(cr,&matrix); - - if(!b3D) return; - modelView = glm::translate(modelView, {x,y,z}); + cairo_get_matrix(cr, &matrix); + cairo_matrix_translate(&matrix, x, y); + cairo_set_matrix(cr, &matrix); + if (!b3D) return; + modelView = glm::translate(modelView, { x, y, z }); } //---------------------------------------------------------- -void ofCairoRenderer::translate(const glm::vec3 & p){ - translate(p.x,p.y,p.z); +void ofCairoRenderer::translate(const glm::vec3 & p) { + translate(p.x, p.y, p.z); } //---------------------------------------------------------- -void ofCairoRenderer::scale(float xAmnt, float yAmnt, float zAmnt ){ - if(!surface || !cr) return; +void ofCairoRenderer::scale(float xAmnt, float yAmnt, float zAmnt) { + if (!surface || !cr) return; // temporary fix for a issue where Cairo never recovers after setting scale = 0 if (xAmnt == 0) xAmnt = std::numeric_limits::epsilon(); if (yAmnt == 0) yAmnt = std::numeric_limits::epsilon(); cairo_matrix_t matrix; - cairo_get_matrix(cr,&matrix); - cairo_matrix_scale(&matrix,xAmnt,yAmnt); - cairo_set_matrix(cr,&matrix); + cairo_get_matrix(cr, &matrix); + cairo_matrix_scale(&matrix, xAmnt, yAmnt); + cairo_set_matrix(cr, &matrix); - if(!b3D) return; - modelView = glm::scale(modelView, {xAmnt,yAmnt,zAmnt}); + if (!b3D) return; + modelView = glm::scale(modelView, { xAmnt, yAmnt, zAmnt }); } //---------------------------------------------------------- -void ofCairoRenderer::matrixMode(ofMatrixMode mode){ +void ofCairoRenderer::matrixMode(ofMatrixMode mode) { currentMatrixMode = mode; } //---------------------------------------------------------- -void ofCairoRenderer::loadIdentityMatrix (void){ - if(!surface || !cr) return; - if(currentMatrixMode==OF_MATRIX_MODELVIEW){ +void ofCairoRenderer::loadIdentityMatrix(void) { + if (!surface || !cr) return; + if (currentMatrixMode == OF_MATRIX_MODELVIEW) { cairo_matrix_t matrix; cairo_matrix_init_identity(&matrix); - cairo_set_matrix(cr,&matrix); + cairo_set_matrix(cr, &matrix); } - if(!b3D) return; - if(currentMatrixMode==OF_MATRIX_MODELVIEW){ + if (!b3D) return; + if (currentMatrixMode == OF_MATRIX_MODELVIEW) { modelView = glm::mat4(1.0); - }else if(currentMatrixMode==OF_MATRIX_PROJECTION){ + } else if (currentMatrixMode == OF_MATRIX_PROJECTION) { projection = glm::mat4(1.0); } } //---------------------------------------------------------- -void ofCairoRenderer::loadMatrix (const glm::mat4 & m){ - if(!surface || !cr) return; - if(!b3D) return; - if(currentMatrixMode==OF_MATRIX_MODELVIEW){ +void ofCairoRenderer::loadMatrix(const glm::mat4 & m) { + if (!surface || !cr) return; + if (!b3D) return; + if (currentMatrixMode == OF_MATRIX_MODELVIEW) { modelView = m; - }else if(currentMatrixMode==OF_MATRIX_PROJECTION){ + } else if (currentMatrixMode == OF_MATRIX_PROJECTION) { projection = m; } } //---------------------------------------------------------- -void ofCairoRenderer::loadMatrix (const float * m){ +void ofCairoRenderer::loadMatrix(const float * m) { loadMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- -void ofCairoRenderer::multMatrix (const glm::mat4 & m){ - if(!surface || !cr) return; - if(!b3D) return; - if(currentMatrixMode==OF_MATRIX_MODELVIEW){ +void ofCairoRenderer::multMatrix(const glm::mat4 & m) { + if (!surface || !cr) return; + if (!b3D) return; + if (currentMatrixMode == OF_MATRIX_MODELVIEW) { modelView = m * modelView; - }else if(currentMatrixMode==OF_MATRIX_PROJECTION){ + } else if (currentMatrixMode == OF_MATRIX_PROJECTION) { projection = m * projection; } } //---------------------------------------------------------- -void ofCairoRenderer::multMatrix (const float * m){ +void ofCairoRenderer::multMatrix(const float * m) { multMatrix(glm::make_mat4(m)); } //---------------------------------------------------------- -void ofCairoRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ){ - if(!surface || !cr) return; +void ofCairoRenderer::rotateRad(float radians, float vecX, float vecY, float vecZ) { + if (!surface || !cr) return; - // we can only do Z-axis rotations via cairo_matrix_rotate. - if(vecZ == 1.0f) { - cairo_matrix_t matrix; - cairo_get_matrix(cr,&matrix); - cairo_matrix_rotate(&matrix,radians); - cairo_set_matrix(cr,&matrix); - } + // we can only do Z-axis rotations via cairo_matrix_rotate. + if (vecZ == 1.0f) { + cairo_matrix_t matrix; + cairo_get_matrix(cr, &matrix); + cairo_matrix_rotate(&matrix, radians); + cairo_set_matrix(cr, &matrix); + } - if(!b3D) return; - modelView = glm::rotate(modelView, radians, glm::vec3(vecX,vecY,vecZ)); + if (!b3D) return; + modelView = glm::rotate(modelView, radians, glm::vec3(vecX, vecY, vecZ)); } //---------------------------------------------------------- -void ofCairoRenderer::rotateXRad(float radians){ - rotateRad(radians,1,0,0); +void ofCairoRenderer::rotateXRad(float radians) { + rotateRad(radians, 1, 0, 0); } //---------------------------------------------------------- -void ofCairoRenderer::rotateYRad(float radians){ - rotateRad(radians,0,1,0); +void ofCairoRenderer::rotateYRad(float radians) { + rotateRad(radians, 0, 1, 0); } //---------------------------------------------------------- -void ofCairoRenderer::rotateZRad(float radians){ - rotateRad(radians,0,0,1); +void ofCairoRenderer::rotateZRad(float radians) { + rotateRad(radians, 0, 0, 1); } //---------------------------------------------------------- -void ofCairoRenderer::rotateRad(float radians){ +void ofCairoRenderer::rotateRad(float radians) { rotateZRad(radians); } //---------------------------------------------------------- -void ofCairoRenderer::setupScreen(){ - if(!surface || !cr) return; +void ofCairoRenderer::setupScreen() { + if (!surface || !cr) return; - setupScreenPerspective(); // assume defaults + setupScreenPerspective(); // assume defaults } //---------------------------------------------------------- // screen coordinate things / default gl values -void ofCairoRenderer::pushView(){ +void ofCairoRenderer::pushView() { viewportStack.push(viewportRect); } //---------------------------------------------------------- -void ofCairoRenderer::popView(){ +void ofCairoRenderer::popView() { viewportRect = viewportStack.top(); viewportStack.pop(); }; @@ -920,37 +910,36 @@ void ofCairoRenderer::popView(){ // setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) -void ofCairoRenderer::viewport(ofRectangle v){ - viewport(v.x,v.y,v.width,v.height); +void ofCairoRenderer::viewport(ofRectangle v) { + viewport(v.x, v.y, v.width, v.height); } //---------------------------------------------------------- -void ofCairoRenderer::viewport(float x, float y, float width, float height, bool invertY){ - if(width < 0) width = originalViewport.width; - if(height < 0) height = originalViewport.height; - ofLogVerbose("ofCairoRenderer::viewport") << "Setting viewport to: " << width << ", " << height; +void ofCairoRenderer::viewport(float x, float y, float width, float height, bool invertY) { + if (width < 0) width = originalViewport.width; + if (height < 0) height = originalViewport.height; + ofLogVerbose("ofCairoRenderer::viewport") << "Setting viewport to: " << width << ", " << height; - if (invertY){ + if (invertY) { y = -y; } - viewportRect.set(x, y, width, height); cairo_reset_clip(cr); cairo_new_path(cr); - cairo_move_to(cr,viewportRect.x,viewportRect.y); - cairo_line_to(cr,viewportRect.x+viewportRect.width,viewportRect.y); - cairo_line_to(cr,viewportRect.x+viewportRect.width,viewportRect.y+viewportRect.height); - cairo_line_to(cr,viewportRect.x,viewportRect.y+viewportRect.height); + cairo_move_to(cr, viewportRect.x, viewportRect.y); + cairo_line_to(cr, viewportRect.x + viewportRect.width, viewportRect.y); + cairo_line_to(cr, viewportRect.x + viewportRect.width, viewportRect.y + viewportRect.height); + cairo_line_to(cr, viewportRect.x, viewportRect.y + viewportRect.height); cairo_clip(cr); }; //---------------------------------------------------------- -void ofCairoRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){ - if(!b3D) return; - if(width < 0) width = originalViewport.width; - if(height < 0) height = originalViewport.height; +void ofCairoRenderer::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { + if (!b3D) return; + if (width < 0) width = originalViewport.width; + if (height < 0) height = originalViewport.height; ofOrientation orientation = ofGetOrientation(); float viewW = originalViewport.width; @@ -961,59 +950,58 @@ void ofCairoRenderer::setupScreenPerspective(float width, float height, float fo float halfFov = glm::pi() * fov / 360.0f; float theTan = tanf(halfFov); float dist = eyeY / theTan; - float aspect = (float) viewW / viewH; - - if(nearDist == 0) nearDist = dist / 10.0f; - if(farDist == 0) farDist = dist * 10.0f; - - projection = glm::perspective(ofDegToRad(fov),aspect,nearDist,farDist); - modelView = glm::lookAt(glm::vec3(eyeX,eyeY,dist),glm::vec3(eyeX,eyeY,0),glm::vec3(0,1,0)); - - - switch(orientation) { - case OF_ORIENTATION_180: - modelView = glm::rotate(modelView,-glm::pi(),glm::vec3(0,0,1)); - if(isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(-1,1,1)); - modelView = glm::translate(modelView, glm::vec3(width,0,0)); - }else{ - modelView = glm::translate(modelView, glm::vec3(width, -height, 0)); - } + float aspect = (float)viewW / viewH; + + if (nearDist == 0) nearDist = dist / 10.0f; + if (farDist == 0) farDist = dist * 10.0f; + + projection = glm::perspective(ofDegToRad(fov), aspect, nearDist, farDist); + modelView = glm::lookAt(glm::vec3(eyeX, eyeY, dist), glm::vec3(eyeX, eyeY, 0), glm::vec3(0, 1, 0)); + + switch (orientation) { + case OF_ORIENTATION_180: + modelView = glm::rotate(modelView, -glm::pi(), glm::vec3(0, 0, 1)); + if (isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(-1, 1, 1)); + modelView = glm::translate(modelView, glm::vec3(width, 0, 0)); + } else { + modelView = glm::translate(modelView, glm::vec3(width, -height, 0)); + } - break; + break; - case OF_ORIENTATION_90_RIGHT: - modelView = glm::rotate(modelView,-glm::half_pi(),glm::vec3(0,0,1)); - if(!isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(1,-1,1)); - modelView = glm::translate(modelView, glm::vec3(-width,-height,0)); - } - break; + case OF_ORIENTATION_90_RIGHT: + modelView = glm::rotate(modelView, -glm::half_pi(), glm::vec3(0, 0, 1)); + if (!isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(1, -1, 1)); + modelView = glm::translate(modelView, glm::vec3(-width, -height, 0)); + } + break; - case OF_ORIENTATION_90_LEFT: - modelView = glm::rotate(modelView,glm::half_pi(),glm::vec3(0,0,1)); - if(isVFlipped()){ - modelView = glm::translate(modelView, glm::vec3(0,-height,0)); - }else{ - modelView = glm::scale(modelView, glm::vec3(1,-1,1)); - } - break; + case OF_ORIENTATION_90_LEFT: + modelView = glm::rotate(modelView, glm::half_pi(), glm::vec3(0, 0, 1)); + if (isVFlipped()) { + modelView = glm::translate(modelView, glm::vec3(0, -height, 0)); + } else { + modelView = glm::scale(modelView, glm::vec3(1, -1, 1)); + } + break; - case OF_ORIENTATION_DEFAULT: - default: - if(isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(-1,-1,1)); - modelView = glm::translate(modelView, glm::vec3(-width,-height,0)); - } - break; + case OF_ORIENTATION_DEFAULT: + default: + if (isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(-1, -1, 1)); + modelView = glm::translate(modelView, glm::vec3(-width, -height, 0)); + } + break; } }; //---------------------------------------------------------- -void ofCairoRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist){ - if(!b3D) return; - if(width < 0) width = viewportRect.width; - if(height < 0) height = viewportRect.height; +void ofCairoRenderer::setupScreenOrtho(float width, float height, float nearDist, float farDist) { + if (!b3D) return; + if (width < 0) width = viewportRect.width; + if (height < 0) height = viewportRect.height; ofOrientation orientation = ofGetOrientation(); float viewW = viewportRect.width; @@ -1021,132 +1009,131 @@ void ofCairoRenderer::setupScreenOrtho(float width, float height, float nearDist ofSetCoordHandedness(OF_RIGHT_HANDED); - if(isVFlipped()) { + if (isVFlipped()) { ofSetCoordHandedness(OF_LEFT_HANDED); } projection = glm::ortho(0.f, viewW, 0.f, viewH, nearDist, farDist); modelView = glm::mat4(1.0f); - switch(orientation) { - case OF_ORIENTATION_180: - modelView = glm::rotate(modelView,-glm::pi(),glm::vec3(0,0,1)); - if(isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(-1,1,1)); - modelView = glm::translate(modelView, glm::vec3(width,0,0)); - }else{ - modelView = glm::translate(modelView, glm::vec3(width, -height, 0)); - } + switch (orientation) { + case OF_ORIENTATION_180: + modelView = glm::rotate(modelView, -glm::pi(), glm::vec3(0, 0, 1)); + if (isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(-1, 1, 1)); + modelView = glm::translate(modelView, glm::vec3(width, 0, 0)); + } else { + modelView = glm::translate(modelView, glm::vec3(width, -height, 0)); + } - break; + break; - case OF_ORIENTATION_90_RIGHT: - modelView = glm::rotate(modelView,-glm::half_pi(),glm::vec3(0,0,1)); - if(!isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(1,-1,1)); - modelView = glm::translate(modelView, glm::vec3(-width,-height,0)); - } - break; + case OF_ORIENTATION_90_RIGHT: + modelView = glm::rotate(modelView, -glm::half_pi(), glm::vec3(0, 0, 1)); + if (!isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(1, -1, 1)); + modelView = glm::translate(modelView, glm::vec3(-width, -height, 0)); + } + break; - case OF_ORIENTATION_90_LEFT: - modelView = glm::rotate(modelView,glm::half_pi(),glm::vec3(0,0,1)); - if(isVFlipped()){ - modelView = glm::translate(modelView, glm::vec3(0,-height,0)); - }else{ - modelView = glm::scale(modelView, glm::vec3(1,-1,1)); - } - break; + case OF_ORIENTATION_90_LEFT: + modelView = glm::rotate(modelView, glm::half_pi(), glm::vec3(0, 0, 1)); + if (isVFlipped()) { + modelView = glm::translate(modelView, glm::vec3(0, -height, 0)); + } else { + modelView = glm::scale(modelView, glm::vec3(1, -1, 1)); + } + break; - case OF_ORIENTATION_DEFAULT: - default: - if(isVFlipped()){ - modelView = glm::scale(modelView, glm::vec3(-1,-1,1)); - modelView = glm::translate(modelView, glm::vec3(-width,-height,0)); - } - break; + case OF_ORIENTATION_DEFAULT: + default: + if (isVFlipped()) { + modelView = glm::scale(modelView, glm::vec3(-1, -1, 1)); + modelView = glm::translate(modelView, glm::vec3(-width, -height, 0)); + } + break; } }; //---------------------------------------------------------- -ofRectangle ofCairoRenderer::getCurrentViewport() const{ +ofRectangle ofCairoRenderer::getCurrentViewport() const { return viewportRect; }; //---------------------------------------------------------- -ofRectangle ofCairoRenderer::getNativeViewport() const{ +ofRectangle ofCairoRenderer::getNativeViewport() const { return viewportRect; }; //---------------------------------------------------------- -int ofCairoRenderer::getViewportWidth() const{ +int ofCairoRenderer::getViewportWidth() const { return viewportRect.width; }; //---------------------------------------------------------- -int ofCairoRenderer::getViewportHeight() const{ +int ofCairoRenderer::getViewportHeight() const { return viewportRect.height; }; //---------------------------------------------------------- -void ofCairoRenderer::setOrientation(ofOrientation orientation, bool vFlip){ +void ofCairoRenderer::setOrientation(ofOrientation orientation, bool vFlip) { ofLogError("ofCairoRenderer") << "orientation not supported yet"; } //---------------------------------------------------------- -bool ofCairoRenderer::isVFlipped() const{ +bool ofCairoRenderer::isVFlipped() const { return true; } //---------------------------------------------------------- -void ofCairoRenderer::loadViewMatrix(const glm::mat4 & m){ +void ofCairoRenderer::loadViewMatrix(const glm::mat4 & m) { ofLogError("ofCairoRenderer") << "view matrix not supported yet"; } //---------------------------------------------------------- -void ofCairoRenderer::multViewMatrix(const glm::mat4 & m){ +void ofCairoRenderer::multViewMatrix(const glm::mat4 & m) { ofLogError("ofCairoRenderer") << "view matrix not supported yet"; } //---------------------------------------------------------- -glm::mat4 ofCairoRenderer::getCurrentViewMatrix() const{ +glm::mat4 ofCairoRenderer::getCurrentViewMatrix() const { ofLogError("ofCairoRenderer") << "view matrix not supported yet"; return glm::mat4(1.0); } //---------------------------------------------------------- -glm::mat4 ofCairoRenderer::getCurrentNormalMatrix() const{ +glm::mat4 ofCairoRenderer::getCurrentNormalMatrix() const { ofLogError("ofCairoRenderer") << "normal matrix not supported yet"; return glm::mat4(1.0); } //---------------------------------------------------------- -glm::mat4 ofCairoRenderer::getCurrentOrientationMatrix() const{ +glm::mat4 ofCairoRenderer::getCurrentOrientationMatrix() const { ofLogError("ofCairoRenderer") << "orientation matrix not supported yet"; return glm::mat4(1.0); } //---------------------------------------------------------- -void ofCairoRenderer::setCircleResolution(int){ - +void ofCairoRenderer::setCircleResolution(int) { } -void ofCairoRenderer::setPolyMode(ofPolyWindingMode mode){ +void ofCairoRenderer::setPolyMode(ofPolyWindingMode mode) { currentStyle.polyMode = mode; path.setPolyWindingMode(mode); } //---------------------------------------------------------- -void ofCairoRenderer::setCoordHandedness(ofHandednessType handedness){ +void ofCairoRenderer::setCoordHandedness(ofHandednessType handedness) { }; //---------------------------------------------------------- -ofHandednessType ofCairoRenderer::getCoordHandedness() const{ +ofHandednessType ofCairoRenderer::getCoordHandedness() const { return OF_LEFT_HANDED; }; //---------------------------------------------------------- -void ofCairoRenderer::setupGraphicDefaults(){ +void ofCairoRenderer::setupGraphicDefaults() { setStyle(ofStyle()); path.setMode(ofPath::COMMANDS); path.setUseShapeColor(false); @@ -1155,24 +1142,23 @@ void ofCairoRenderer::setupGraphicDefaults(){ cairo_matrix_t matrix; cairo_matrix_init_scale(&matrix, 1.0, 1.0); cairo_matrix_init_translate(&matrix, 0.0, 0.0); - cairo_set_matrix(cr,&matrix); + cairo_set_matrix(cr, &matrix); }; //---------------------------------------------------------- -void ofCairoRenderer::clear(){ - if(!surface || ! cr) return; - cairo_set_source_rgba(cr,currentStyle.bgColor.r, currentStyle.bgColor.g, currentStyle.bgColor.b, currentStyle.bgColor.a); +void ofCairoRenderer::clear() { + if (!surface || !cr) return; + cairo_set_source_rgba(cr, currentStyle.bgColor.r, currentStyle.bgColor.g, currentStyle.bgColor.b, currentStyle.bgColor.a); cairo_paint(cr); setColor(currentStyle.color); } //---------------------------------------------------------- void ofCairoRenderer::clear(float r, float g, float b, float a) { - if(!surface || ! cr) return; - cairo_set_source_rgba(cr,r, g, b, a); + if (!surface || !cr) return; + cairo_set_source_rgba(cr, r, g, b, a); cairo_paint(cr); setColor(currentStyle.color); - } //---------------------------------------------------------- @@ -1184,56 +1170,55 @@ void ofCairoRenderer::clear(float brightness, float a) { void ofCairoRenderer::clearAlpha() { } - -void ofCairoRenderer::setBitmapTextMode(ofDrawBitmapMode mode){ - currentStyle.drawBitmapMode = mode; +void ofCairoRenderer::setBitmapTextMode(ofBitmapMode mode) { + currentStyle.bitmapMode = mode; } -ofStyle ofCairoRenderer::getStyle() const{ +ofStyle ofCairoRenderer::getStyle() const { return currentStyle; } -void ofCairoRenderer::pushStyle(){ +void ofCairoRenderer::pushStyle() { styleHistory.push_back(currentStyle); //if we are over the max number of styles we have set, then delete the oldest styles. - if( styleHistory.size() > OF_MAX_STYLE_HISTORY ){ + if (styleHistory.size() > OF_MAX_STYLE_HISTORY) { styleHistory.pop_front(); //should we warn here? ofLogWarning("ofGraphics") << "ofPushStyle(): maximum number of style pushes << " << OF_MAX_STYLE_HISTORY << " reached, did you forget to pop somewhere?"; } } -void ofCairoRenderer::popStyle(){ - if( styleHistory.size() ){ +void ofCairoRenderer::popStyle() { + if (styleHistory.size()) { setStyle(styleHistory.back()); styleHistory.pop_back(); } } //---------------------------------------------------------- -void ofCairoRenderer::setBackgroundAuto(bool bAuto){ +void ofCairoRenderer::setBackgroundAuto(bool bAuto) { bBackgroundAuto = bAuto; } //---------------------------------------------------------- -bool ofCairoRenderer::getBackgroundAuto(){ +bool ofCairoRenderer::getBackgroundAuto() { return bBackgroundAuto; } //---------------------------------------------------------- -void ofCairoRenderer::setBackgroundColor(const ofFloatColor & c){ +void ofCairoRenderer::setBackgroundColor(const ofFloatColor & c) { currentStyle.bgColor = c; } //---------------------------------------------------------- -ofFloatColor ofCairoRenderer::getBackgroundColor(){ +ofFloatColor ofCairoRenderer::getBackgroundColor() { return currentStyle.bgColor; } //---------------------------------------------------------- -void ofCairoRenderer::background(const ofFloatColor & c){ +void ofCairoRenderer::background(const ofFloatColor & c) { setBackgroundColor(c); - clear(c.r,c.g,c.b,c.a); + clear(c.r, c.g, c.b, c.a); } //---------------------------------------------------------- @@ -1242,159 +1227,156 @@ void ofCairoRenderer::background(float brightness) { } //---------------------------------------------------------- -void ofCairoRenderer::background(int hexColor, int _a){ +void ofCairoRenderer::background(int hexColor, int _a) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - background ( (float)r/255.f, (float)g/255.f, (float)b/255.f, _a/255.f); -// background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a); + background((float)r / 255.f, (float)g / 255.f, (float)b / 255.f, _a / 255.f); + // background ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, _a); } //---------------------------------------------------------- -void ofCairoRenderer::background(float r, float g, float b, float a){ - background(ofFloatColor(r,g,b,a)); +void ofCairoRenderer::background(float r, float g, float b, float a) { + background(ofFloatColor(r, g, b, a)); } - //---------------------------------------------------------- -void ofCairoRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{ +void ofCairoRenderer::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const { cairo_new_path(cr); - cairo_move_to(cr,x1,y1); - cairo_line_to(cr,x2,y2); + cairo_move_to(cr, x1, y1); + cairo_line_to(cr, x2, y2); - cairo_stroke( cr ); + cairo_stroke(cr); } //---------------------------------------------------------- -void ofCairoRenderer::drawRectangle(float x, float y, float z, float w, float h) const{ +void ofCairoRenderer::drawRectangle(float x, float y, float z, float w, float h) const { cairo_new_path(cr); - if (currentStyle.rectMode == OF_RECTMODE_CORNER){ - cairo_move_to(cr,x,y); - cairo_line_to(cr,x+w, y); - cairo_line_to(cr,x+w, y+h); - cairo_line_to(cr,x, y+h); - }else{ - cairo_move_to(cr,x-w/2.0f, y-h/2.0f); - cairo_line_to(cr,x+w/2.0f, y-h/2.0f); - cairo_line_to(cr,x+w/2.0f, y+h/2.0f); - cairo_line_to(cr,x-w/2.0f, y+h/2.0f); + if (currentStyle.rectMode == OF_RECTMODE_CORNER) { + cairo_move_to(cr, x, y); + cairo_line_to(cr, x + w, y); + cairo_line_to(cr, x + w, y + h); + cairo_line_to(cr, x, y + h); + } else { + cairo_move_to(cr, x - w / 2.0f, y - h / 2.0f); + cairo_line_to(cr, x + w / 2.0f, y - h / 2.0f); + cairo_line_to(cr, x + w / 2.0f, y + h / 2.0f); + cairo_line_to(cr, x - w / 2.0f, y + h / 2.0f); } cairo_close_path(cr); - if(currentStyle.bFill==OF_FILLED){ - cairo_fill( cr ); - }else{ - cairo_stroke( cr ); + if (currentStyle.bFill == OF_FILLED) { + cairo_fill(cr); + } else { + cairo_stroke(cr); } } //---------------------------------------------------------- -void ofCairoRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{ +void ofCairoRenderer::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const { cairo_new_path(cr); cairo_move_to(cr, x1, y1); cairo_line_to(cr, x2, y2); cairo_line_to(cr, x3, y3); - cairo_close_path(cr); - if(currentStyle.bFill==OF_FILLED){ - cairo_fill( cr ); - }else{ - cairo_stroke( cr ); + if (currentStyle.bFill == OF_FILLED) { + cairo_fill(cr); + } else { + cairo_stroke(cr); } } //---------------------------------------------------------- -void ofCairoRenderer::drawCircle(float x, float y, float z, float radius) const{ +void ofCairoRenderer::drawCircle(float x, float y, float z, float radius) const { cairo_new_path(cr); cairo_arc(cr, x, y, radius, 0, glm::two_pi()); cairo_close_path(cr); - if(currentStyle.bFill==OF_FILLED){ - cairo_fill( cr ); - }else{ - cairo_stroke( cr ); + if (currentStyle.bFill == OF_FILLED) { + cairo_fill(cr); + } else { + cairo_stroke(cr); } } //---------------------------------------------------------- -void ofCairoRenderer::enableAntiAliasing(){ - cairo_set_antialias(cr,CAIRO_ANTIALIAS_SUBPIXEL); +void ofCairoRenderer::enableAntiAliasing() { + cairo_set_antialias(cr, CAIRO_ANTIALIAS_SUBPIXEL); } //---------------------------------------------------------- -void ofCairoRenderer::disableAntiAliasing(){ - cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE); +void ofCairoRenderer::disableAntiAliasing() { + cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); } //---------------------------------------------------------- -void ofCairoRenderer::drawEllipse(float x, float y, float z, float width, float height) const{ - ofCairoRenderer * mutThis = const_cast(this); +void ofCairoRenderer::drawEllipse(float x, float y, float z, float width, float height) const { + ofCairoRenderer * mutThis = const_cast(this); cairo_new_path(cr); - float ellipse_ratio = height/width; + float ellipse_ratio = height / width; mutThis->pushMatrix(); - mutThis->translate(0,-y*ellipse_ratio); - mutThis->scale(1,ellipse_ratio); - mutThis->translate(0,y/ellipse_ratio); - cairo_arc(cr, x, y, width*0.5, 0, glm::two_pi()); + mutThis->translate(0, -y * ellipse_ratio); + mutThis->scale(1, ellipse_ratio); + mutThis->translate(0, y / ellipse_ratio); + cairo_arc(cr, x, y, width * 0.5, 0, glm::two_pi()); mutThis->popMatrix(); cairo_close_path(cr); - - if(currentStyle.bFill==OF_FILLED){ - cairo_fill( cr ); - }else{ - cairo_stroke( cr ); + if (currentStyle.bFill == OF_FILLED) { + cairo_fill(cr); + } else { + cairo_stroke(cr); } } -void ofCairoRenderer::drawString(string text, float x, float y, float z) const{ - cairo_select_font_face (cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (cr, 10); +void ofCairoRenderer::drawString(string text, float x, float y, float z) const { + cairo_select_font_face(cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cr, 10); vector lines = ofSplitString(text, "\n"); - for(int i=0;i<(int)lines.size();i++){ - cairo_move_to (cr, x, y+i*14.3); - cairo_show_text (cr, lines[i].c_str() ); + for (int i = 0; i < (int)lines.size(); i++) { + cairo_move_to(cr, x, y + i * 14.3); + cairo_show_text(cr, lines[i].c_str()); } } -void ofCairoRenderer::drawString(const ofTrueTypeFont & font, string text, float x, float y) const{ - font.drawStringAsShapes(text,x,y); +void ofCairoRenderer::drawString(const ofTrueTypeFont & font, string text, float x, float y) const { + font.drawStringAsShapes(text, x, y); } -cairo_t * ofCairoRenderer::getCairoContext(){ +cairo_t * ofCairoRenderer::getCairoContext() { return cr; } -cairo_surface_t * ofCairoRenderer::getCairoSurface(){ +cairo_surface_t * ofCairoRenderer::getCairoSurface() { return surface; } -ofPixels & ofCairoRenderer::getImageSurfacePixels(){ - if(type!=IMAGE){ +ofPixels & ofCairoRenderer::getImageSurfacePixels() { + if (type != IMAGE) { ofLogError("ofCairoRenderer") << "getImageSurfacePixels(): can only get pixels from image surface"; } return imageBuffer; } -ofBuffer & ofCairoRenderer::getContentBuffer(){ - if(filename!="" || (type!=SVG && type!=PDF)){ +ofBuffer & ofCairoRenderer::getContentBuffer() { + if (filename != "" || (type != SVG && type != PDF)) { ofLogError("ofCairoRenderer") << "getContentBuffer(): can only get buffer from memory allocated renderer for svg or pdf"; } return streamBuffer; } -const of3dGraphics & ofCairoRenderer::get3dGraphics() const{ +const of3dGraphics & ofCairoRenderer::get3dGraphics() const { return graphics3d; } -of3dGraphics & ofCairoRenderer::get3dGraphics(){ +of3dGraphics & ofCairoRenderer::get3dGraphics() { return graphics3d; } diff --git a/libs/openFrameworks/graphics/ofCairoRenderer.h b/libs/openFrameworks/graphics/ofCairoRenderer.h index 1836e5d4a7e..05e54aca2c3 100644 --- a/libs/openFrameworks/graphics/ofCairoRenderer.h +++ b/libs/openFrameworks/graphics/ofCairoRenderer.h @@ -1,31 +1,30 @@ #pragma once #include "cairo.h" +#include "of3dGraphics.h" #include "ofGraphicsBaseTypes.h" #include "ofPath.h" -#include "of3dGraphics.h" - #include "ofPixels.h" #include #include -class ofCairoRenderer: public ofBaseRenderer{ +class ofCairoRenderer : public ofBaseRenderer { public: ofCairoRenderer(); ~ofCairoRenderer(); static const std::string TYPE; - const std::string & getType(){ return TYPE; } + const std::string & getType() { return TYPE; } - enum Type{ + enum Type { PDF, SVG, IMAGE, FROM_FILE_EXTENSION }; - void setup(const of::filesystem::path & filename, Type type=ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage=true, bool b3D=false, ofRectangle outputsize = ofRectangle(0,0,0,0)); - void setupMemoryOnly(Type _type, bool multiPage=true, bool b3D=false, ofRectangle viewport = ofRectangle(0,0,0,0)); + void setup(const of::filesystem::path & filename, Type type = ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage = true, bool b3D = false, ofRectangle outputsize = ofRectangle(0, 0, 0, 0)); + void setupMemoryOnly(Type _type, bool multiPage = true, bool b3D = false, ofRectangle viewport = ofRectangle(0, 0, 0, 0)); void close(); void flush(); @@ -37,8 +36,8 @@ class ofCairoRenderer: public ofBaseRenderer{ void draw(const ofPath::Command & path) const; void draw(const ofPolyline & poly) const; void draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const; - void draw(const of3dPrimitive& model, ofPolyRenderMode renderType ) const; - void draw(const ofNode& node) const; + void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const; + void draw(const ofNode & node) const; void draw(const std::vector & vertexData, ofPrimitiveMode drawMode) const; void draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; @@ -72,7 +71,6 @@ class ofCairoRenderer: public ofBaseRenderer{ glm::mat4 getCurrentOrientationMatrix() const; void setCircleResolution(int); - void setCoordHandedness(ofHandednessType handedness); ofHandednessType getCoordHandedness() const; @@ -101,11 +99,11 @@ class ofCairoRenderer: public ofBaseRenderer{ void rotateZRad(float radians); void rotateRad(float radians); void matrixMode(ofMatrixMode mode); - void loadIdentityMatrix (void); - void loadMatrix (const glm::mat4 & m); - void loadMatrix (const float * m); - void multMatrix (const glm::mat4 & m); - void multMatrix (const float * m); + void loadIdentityMatrix(void); + void loadMatrix(const glm::mat4 & m); + void loadMatrix(const float * m); + void multMatrix(const glm::mat4 & m); + void multMatrix(const float * m); // screen coordinate things / default gl values void setupGraphicDefaults(); @@ -117,25 +115,25 @@ class ofCairoRenderer: public ofBaseRenderer{ void setColor(const ofFloatColor & color); void setColor(const ofFloatColor & color, float _a); void setColor(float gray); // new set a color as grayscale with one argument - void setHexColor( int hexColor ); // hex, like web 0xFF0033; + void setHexColor(int hexColor); // hex, like web 0xFF0033; // bg color void setBackgroundColor(const ofFloatColor & c); ofFloatColor getBackgroundColor(); void background(const ofFloatColor & c); void background(float brightness); - void background(int hexColor, int _a=255); - void background(float r, float g, float b, float a=1.f); + void background(int hexColor, int _a = 255); + void background(float r, float g, float b, float a = 1.f); - void setBackgroundAuto(bool bManual); // default is true + void setBackgroundAuto(bool bManual); // default is true bool getBackgroundAuto(); void clear(); - void clear(float r, float g, float b, float a=0); - void clear(float brightness, float a=0); + void clear(float r, float g, float b, float a = 0); + void clear(float brightness, float a = 0); void clearAlpha(); - void setBitmapTextMode(ofDrawBitmapMode mode); + void setBitmapTextMode(ofBitmapMode mode); ofStyle getStyle() const; void pushStyle(); @@ -159,16 +157,15 @@ class ofCairoRenderer: public ofBaseRenderer{ ofPixels & getImageSurfacePixels(); ofBuffer & getContentBuffer(); - - virtual void bind(const ofCamera & camera, const ofRectangle & viewport){} - virtual void unbind(const ofCamera & camera){} + virtual void bind(const ofCamera & camera, const ofRectangle & viewport) { } + virtual void unbind(const ofCamera & camera) { } const of3dGraphics & get3dGraphics() const; of3dGraphics & get3dGraphics(); private: glm::vec3 transform(glm::vec3 vec) const; - static _cairo_status stream_function(void *closure,const unsigned char *data, unsigned int length); + static _cairo_status stream_function(void * closure, const unsigned char * data, unsigned int length); void draw(const ofPixels & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; mutable std::deque curvePoints; @@ -193,7 +190,7 @@ class ofCairoRenderer: public ofBaseRenderer{ std::stack projectionStack; std::stack modelViewStack; std::stack viewportStack; - + ofMatrixMode currentMatrixMode; std::vector sphereVerts; @@ -204,6 +201,6 @@ class ofCairoRenderer: public ofBaseRenderer{ ofPixels imageBuffer; ofStyle currentStyle; - std::deque styleHistory; + std::deque styleHistory; ofPath path; }; diff --git a/libs/openFrameworks/graphics/ofGraphics.cpp b/libs/openFrameworks/graphics/ofGraphics.cpp index d40f4e40744..d2a390a28f3 100644 --- a/libs/openFrameworks/graphics/ofGraphics.cpp +++ b/libs/openFrameworks/graphics/ofGraphics.cpp @@ -1,20 +1,20 @@ +#include "ofGLRenderer.h" #include "ofGraphics.h" #include "ofRendererCollection.h" -#include "ofGLRenderer.h" #ifndef TARGET_WIN32 - #define CALLBACK + #define CALLBACK #endif using std::shared_ptr; -using std::vector; using std::string; +using std::vector; //style stuff - new in 006 static ofVboMesh gradientMesh; -void ofSetCurrentRenderer(shared_ptr renderer,bool setDefaults){ - if(setDefaults){ +void ofSetCurrentRenderer(shared_ptr renderer, bool setDefaults) { + if (setDefaults) { ofStyle style = ofGetCurrentRenderer()->getStyle(); renderer->setupGraphicDefaults(); renderer->setStyle(style); @@ -26,48 +26,48 @@ void ofSetCurrentRenderer(shared_ptr renderer,bool setDefaults){ // transformation matrix related functions //---------------------------------------------------------- -void ofPushView(){ +void ofPushView() { ofGetCurrentRenderer()->pushView(); } //---------------------------------------------------------- -void ofPopView(){ +void ofPopView() { ofGetCurrentRenderer()->popView(); } //---------------------------------------------------------- -void ofViewport(ofRectangle viewport){ +void ofViewport(ofRectangle viewport) { ofGetCurrentRenderer()->viewport(viewport.x, viewport.y, viewport.width, viewport.height); } //---------------------------------------------------------- -void ofViewport(float x, float y, float width, float height, bool invertY){ - ofGetCurrentRenderer()->viewport(x,y,width,height,invertY); +void ofViewport(float x, float y, float width, float height, bool invertY) { + ofGetCurrentRenderer()->viewport(x, y, width, height, invertY); } //---------------------------------------------------------- -ofRectangle ofGetCurrentViewport(){ +ofRectangle ofGetCurrentViewport() { return ofGetCurrentRenderer()->getCurrentViewport(); } //---------------------------------------------------------- -ofRectangle ofGetNativeViewport(){ +ofRectangle ofGetNativeViewport() { return ofGetCurrentRenderer()->getNativeViewport(); } //---------------------------------------------------------- -int ofGetViewportWidth(){ +int ofGetViewportWidth() { return ofGetCurrentRenderer()->getViewportWidth(); } //---------------------------------------------------------- -int ofGetViewportHeight(){ +int ofGetViewportHeight() { return ofGetCurrentRenderer()->getViewportHeight(); } //---------------------------------------------------------- -int ofOrientationToDegrees(ofOrientation orientation){ - switch(orientation){ +int ofOrientationToDegrees(ofOrientation orientation) { + switch (orientation) { case OF_ORIENTATION_DEFAULT: return 0; case OF_ORIENTATION_180: @@ -82,51 +82,49 @@ int ofOrientationToDegrees(ofOrientation orientation){ } //---------------------------------------------------------- -bool ofIsVFlipped(){ +bool ofIsVFlipped() { return ofGetCurrentRenderer()->isVFlipped(); } //---------------------------------------------------------- -void ofSetCoordHandedness(ofHandednessType handedness){ +void ofSetCoordHandedness(ofHandednessType handedness) { ofGetCurrentRenderer()->setCoordHandedness(handedness); } //---------------------------------------------------------- -ofHandednessType ofGetCoordHandedness(){ +ofHandednessType ofGetCoordHandedness() { return ofGetCurrentRenderer()->getCoordHandedness(); } //---------------------------------------------------------- -void ofSetupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){ - ofGetCurrentRenderer()->setupScreenPerspective(width,height, fov,nearDist,farDist); +void ofSetupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { + ofGetCurrentRenderer()->setupScreenPerspective(width, height, fov, nearDist, farDist); } //---------------------------------------------------------- -void ofSetupScreenOrtho(float width, float height, float nearDist, float farDist){ - ofGetCurrentRenderer()->setupScreenOrtho(width,height,nearDist,farDist); +void ofSetupScreenOrtho(float width, float height, float nearDist, float farDist) { + ofGetCurrentRenderer()->setupScreenOrtho(width, height, nearDist, farDist); } //---------------------------------------------------------- //Resets openGL parameters back to OF defaults -void ofSetupGraphicDefaults(){ +void ofSetupGraphicDefaults() { ofGetCurrentRenderer()->setupGraphicDefaults(); } //---------------------------------------------------------- -void ofSetupScreen(){ - ofGetCurrentRenderer()->setupScreen(); // assume defaults +void ofSetupScreen() { + ofGetCurrentRenderer()->setupScreen(); // assume defaults } - - //our openGL wrappers //---------------------------------------------------------- -void ofPushMatrix(){ +void ofPushMatrix() { ofGetCurrentRenderer()->pushMatrix(); } //---------------------------------------------------------- -void ofPopMatrix(){ +void ofPopMatrix() { ofGetCurrentRenderer()->popMatrix(); } @@ -143,214 +141,212 @@ void ofPopMatrix(){ * * @param matrixMode_ Which matrix mode to query */ -glm::mat4 ofGetCurrentMatrix(ofMatrixMode matrixMode_){ +glm::mat4 ofGetCurrentMatrix(ofMatrixMode matrixMode_) { return ofGetCurrentRenderer()->getCurrentMatrix(matrixMode_); } //---------------------------------------------------------- -glm::mat4 ofGetCurrentOrientationMatrix(){ +glm::mat4 ofGetCurrentOrientationMatrix() { return ofGetCurrentRenderer()->getCurrentOrientationMatrix(); } //---------------------------------------------------------- -glm::mat4 ofGetCurrentNormalMatrix(){ +glm::mat4 ofGetCurrentNormalMatrix() { return ofGetCurrentRenderer()->getCurrentNormalMatrix(); } //---------------------------------------------------------- -void ofTranslate(const glm::vec3& p){ +void ofTranslate(const glm::vec3 & p) { ofGetCurrentRenderer()->translate(p); } //---------------------------------------------------------- -void ofTranslate(const glm::vec2& p){ +void ofTranslate(const glm::vec2 & p) { ofGetCurrentRenderer()->translate(glm::vec3(p, 0.0)); } //---------------------------------------------------------- -void ofTranslate(float x, float y, float z){ +void ofTranslate(float x, float y, float z) { ofGetCurrentRenderer()->translate(x, y, z); } //---------------------------------------------------------- -void ofScale(float xAmnt, float yAmnt, float zAmnt){ +void ofScale(float xAmnt, float yAmnt, float zAmnt) { ofGetCurrentRenderer()->scale(xAmnt, yAmnt, zAmnt); } -void ofScale(float amount){ +void ofScale(float amount) { ofScale(amount, amount, amount); } void ofScale(const glm::vec3 & p) { - ofScale(p.x, p.y, p.z); + ofScale(p.x, p.y, p.z); } - //same as ofRotateZ //---------------------------------------------------------- -void ofRotate(float degrees){ +void ofRotate(float degrees) { ofGetCurrentRenderer()->rotateDeg(degrees); } //---------------------------------------------------------- -void ofRotate(float degrees, float vecX, float vecY, float vecZ){ +void ofRotate(float degrees, float vecX, float vecY, float vecZ) { ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ); } //---------------------------------------------------------- -void ofRotateX(float degrees){ +void ofRotateX(float degrees) { ofGetCurrentRenderer()->rotateXDeg(degrees); } //---------------------------------------------------------- -void ofRotateY(float degrees){ +void ofRotateY(float degrees) { ofGetCurrentRenderer()->rotateYDeg(degrees); } //---------------------------------------------------------- -void ofRotateZ(float degrees){ +void ofRotateZ(float degrees) { ofGetCurrentRenderer()->rotateZDeg(degrees); } //same as ofRotateZ //---------------------------------------------------------- -void ofRotateDeg(float degrees){ +void ofRotateDeg(float degrees) { ofGetCurrentRenderer()->rotateDeg(degrees); } //---------------------------------------------------------- -void ofRotateDeg(float degrees, float vecX, float vecY, float vecZ){ +void ofRotateDeg(float degrees, float vecX, float vecY, float vecZ) { ofGetCurrentRenderer()->rotateDeg(degrees, vecX, vecY, vecZ); } //---------------------------------------------------------- -void ofRotateXDeg(float degrees){ +void ofRotateXDeg(float degrees) { ofGetCurrentRenderer()->rotateXDeg(degrees); } //---------------------------------------------------------- -void ofRotateYDeg(float degrees){ +void ofRotateYDeg(float degrees) { ofGetCurrentRenderer()->rotateYDeg(degrees); } //---------------------------------------------------------- -void ofRotateZDeg(float degrees){ +void ofRotateZDeg(float degrees) { ofGetCurrentRenderer()->rotateZDeg(degrees); } //same as ofRotateZ //---------------------------------------------------------- -void ofRotateRad(float radians){ +void ofRotateRad(float radians) { ofGetCurrentRenderer()->rotateRad(radians); } //---------------------------------------------------------- -void ofRotateRad(float radians, float vecX, float vecY, float vecZ){ +void ofRotateRad(float radians, float vecX, float vecY, float vecZ) { ofGetCurrentRenderer()->rotateRad(radians, vecX, vecY, vecZ); } //---------------------------------------------------------- -void ofRotateXRad(float radians){ +void ofRotateXRad(float radians) { ofGetCurrentRenderer()->rotateXRad(radians); } //---------------------------------------------------------- -void ofRotateYRad(float radians){ +void ofRotateYRad(float radians) { ofGetCurrentRenderer()->rotateYRad(radians); } //---------------------------------------------------------- -void ofRotateZRad(float radians){ +void ofRotateZRad(float radians) { ofGetCurrentRenderer()->rotateZRad(radians); } //---------------------------------------------------------- -void ofLoadIdentityMatrix (void){ +void ofLoadIdentityMatrix(void) { ofGetCurrentRenderer()->loadIdentityMatrix(); } //---------------------------------------------------------- -void ofLoadMatrix (const glm::mat4 & m){ +void ofLoadMatrix(const glm::mat4 & m) { ofGetCurrentRenderer()->loadMatrix(m); } //---------------------------------------------------------- -void ofLoadMatrix (const float *m){ +void ofLoadMatrix(const float * m) { ofGetCurrentRenderer()->loadMatrix(m); } //---------------------------------------------------------- -void ofMultMatrix (const glm::mat4 & m){ +void ofMultMatrix(const glm::mat4 & m) { ofGetCurrentRenderer()->multMatrix(m); } //---------------------------------------------------------- -void ofMultMatrix (const float *m){ +void ofMultMatrix(const float * m) { ofGetCurrentRenderer()->multMatrix(m); } //---------------------------------------------------------- -void ofSetMatrixMode(ofMatrixMode matrixMode){ +void ofSetMatrixMode(ofMatrixMode matrixMode) { ofGetCurrentRenderer()->matrixMode(matrixMode); } -void ofLoadViewMatrix(const glm::mat4 & m){ +void ofLoadViewMatrix(const glm::mat4 & m) { ofGetCurrentRenderer()->loadViewMatrix(m); } -void ofMultViewMatrix(const glm::mat4 & m){ +void ofMultViewMatrix(const glm::mat4 & m) { ofGetCurrentRenderer()->multViewMatrix(m); } -glm::mat4 ofGetCurrentViewMatrix(){ +glm::mat4 ofGetCurrentViewMatrix() { return ofGetCurrentRenderer()->getCurrentViewMatrix(); } // end transformation matrix related functions //---------------------------------------------------------- - //---------------------------------------------------------- // background functions //---------------------------------------------------------- -void ofClear(float r, float g, float b, float a){ - ofGetCurrentRenderer()->clear(r/255.f,g/255.f,b/255.f,a/255.f); +void ofClear(float r, float g, float b, float a) { + ofGetCurrentRenderer()->clear(r / 255.f, g / 255.f, b / 255.f, a / 255.f); } //---------------------------------------------------------- -void ofClear(float r, float g, float b){ - ofClear( r, g, b, 255.f ); +void ofClear(float r, float g, float b) { + ofClear(r, g, b, 255.f); } //---------------------------------------------------------- -void ofClear(float brightness, float a){ +void ofClear(float brightness, float a) { ofClear(brightness, brightness, brightness, a); } //---------------------------------------------------------- -void ofClear(float brightness){ +void ofClear(float brightness) { ofClear(brightness, brightness, brightness, 0.f); } //---------------------------------------------------------- -void ofClear(const ofColor & c){ - ofClear( c.r, c.g, c.b, c.a ); +void ofClear(const ofColor & c) { + ofClear(c.r, c.g, c.b, c.a); } //---------------------------------------------------------- -void ofClear(const ofFloatColor & c){ - ofClearFloat(c.r,c.g,c.b,c.a); +void ofClear(const ofFloatColor & c) { + ofClearFloat(c.r, c.g, c.b, c.a); } //---------------------------------------------------------- -void ofClearFloat(float r, float g, float b){ - ofClearFloat(r,g,b,1.f); +void ofClearFloat(float r, float g, float b) { + ofClearFloat(r, g, b, 1.f); } //---------------------------------------------------------- -void ofClearFloat(float r, float g, float b, float a){ - ofGetCurrentRenderer()->clear(r,g,b,a); +void ofClearFloat(float r, float g, float b, float a) { + ofGetCurrentRenderer()->clear(r, g, b, a); } //---------------------------------------------------------- @@ -359,73 +355,72 @@ void ofClearFloat(float brightness, float a) { } //---------------------------------------------------------- -void ofClearFloat(const ofFloatColor & c){ +void ofClearFloat(const ofFloatColor & c) { ofClearFloat(c.r, c.g, c.b, c.a); } //---------------------------------------------------------- -void ofClearAlpha(){ +void ofClearAlpha() { ofGetCurrentRenderer()->clearAlpha(); -} +} //---------------------------------------------------------- -void ofSetBackgroundAuto(bool bAuto){ +void ofSetBackgroundAuto(bool bAuto) { ofGetCurrentRenderer()->setBackgroundAuto(bAuto); } - -bool ofGetBackgroundAuto(){ +bool ofGetBackgroundAuto() { return ofGetCurrentRenderer()->getBackgroundAuto(); } //---------------------------------------------------------- -bool ofbClearBg(){ +bool ofbClearBg() { return ofGetBackgroundAuto(); } //---------------------------------------------------------- -ofFloatColor ofGetBackground(){ +ofFloatColor ofGetBackground() { return ofGetCurrentRenderer()->getBackgroundColor(); } //---------------------------------------------------------- -ofFloatColor ofGetBackgroundColor(){ +ofFloatColor ofGetBackgroundColor() { return ofGetCurrentRenderer()->getBackgroundColor(); } //---------------------------------------------------------- -void ofBackground(int brightness, int alpha){ +void ofBackground(int brightness, int alpha) { ofBackground(brightness, brightness, brightness, alpha); } //---------------------------------------------------------- -void ofBackground(int r, int g, int b, int a){ - ofGetCurrentRenderer()->background( r/255.f, g/255.f, b/255.f, a/255.f); +void ofBackground(int r, int g, int b, int a) { + ofGetCurrentRenderer()->background(r / 255.f, g / 255.f, b / 255.f, a / 255.f); } //---------------------------------------------------------- -void ofBackground(const ofColor & c){ - ofBackground( c.r, c.g, c.b, c.a); +void ofBackground(const ofColor & c) { + ofBackground(c.r, c.g, c.b, c.a); } //---------------------------------------------------------- -void ofBackgroundHex(int hexColor, int alpha){ - ofBackground ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha); +void ofBackgroundHex(int hexColor, int alpha) { + ofBackground((hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha); } //---------------------------------------------------------- -void ofBackgroundGradient(const ofFloatColor& start, const ofFloatColor& end, ofGradientMode mode) { +void ofBackgroundGradient(const ofFloatColor & start, const ofFloatColor & end, ofGradientMode mode) { float w = ofGetViewportWidth(), h = ofGetViewportHeight(); gradientMesh.clear(); gradientMesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); #ifndef TARGET_EMSCRIPTEN #ifdef TARGET_OPENGLES - if(ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW); + if (ofIsGLProgrammableRenderer()) gradientMesh.setUsage(GL_STREAM_DRAW); #else - gradientMesh.setUsage(GL_STREAM_DRAW); + gradientMesh.setUsage(GL_STREAM_DRAW); #endif #endif - if(mode == OF_GRADIENT_CIRCULAR) { + if (mode == OF_GRADIENT_CIRCULAR) { // this could be optimized by building a single mesh once, then copying // it and just adding the colors whenever the function is called. ///TODO: revert to glm::vec2!! @@ -436,29 +431,29 @@ void ofBackgroundGradient(const ofFloatColor& start, const ofFloatColor& end, of float angleBisector = glm::two_pi() / (n * 2.0); float smallRadius = ofDist(0, 0, w / 2, h / 2); float bigRadius = smallRadius / cos(angleBisector); - for(int i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { float theta = i * glm::two_pi() / n; gradientMesh.addVertex(glm::vec3(center + glm::vec2(sin(theta), cos(theta)) * bigRadius, 0)); gradientMesh.addColor(end); } - } else if(mode == OF_GRADIENT_LINEAR) { - gradientMesh.addVertex({0.f, 0.f, 0.f}); - gradientMesh.addVertex({w, 0.f, 0.f}); - gradientMesh.addVertex({w, h, 0.f}); - gradientMesh.addVertex({0.f, h, 0.f}); + } else if (mode == OF_GRADIENT_LINEAR) { + gradientMesh.addVertex({ 0.f, 0.f, 0.f }); + gradientMesh.addVertex({ w, 0.f, 0.f }); + gradientMesh.addVertex({ w, h, 0.f }); + gradientMesh.addVertex({ 0.f, h, 0.f }); gradientMesh.addColor(start); gradientMesh.addColor(start); gradientMesh.addColor(end); gradientMesh.addColor(end); - } else if(mode == OF_GRADIENT_BAR) { - gradientMesh.addVertex({w / 2.f, h / 2.f, 0.f}); - gradientMesh.addVertex({0.f, h / 2.f, 0.f}); - gradientMesh.addVertex({0.f, 0.f, 0.f}); - gradientMesh.addVertex({w, 0.f, 0.f}); - gradientMesh.addVertex({w, h / 2.f, 0.f}); - gradientMesh.addVertex({w, h, 0.f}); - gradientMesh.addVertex({0.f, h, 0.f}); - gradientMesh.addVertex({0.f, h / 2, 0.f}); + } else if (mode == OF_GRADIENT_BAR) { + gradientMesh.addVertex({ w / 2.f, h / 2.f, 0.f }); + gradientMesh.addVertex({ 0.f, h / 2.f, 0.f }); + gradientMesh.addVertex({ 0.f, 0.f, 0.f }); + gradientMesh.addVertex({ w, 0.f, 0.f }); + gradientMesh.addVertex({ w, h / 2.f, 0.f }); + gradientMesh.addVertex({ w, h, 0.f }); + gradientMesh.addVertex({ 0.f, h, 0.f }); + gradientMesh.addVertex({ 0.f, h / 2, 0.f }); gradientMesh.addColor(start); gradientMesh.addColor(start); gradientMesh.addColor(end); @@ -469,797 +464,786 @@ void ofBackgroundGradient(const ofFloatColor& start, const ofFloatColor& end, of gradientMesh.addColor(start); } GLboolean depthMaskEnabled; - glGetBooleanv(GL_DEPTH_WRITEMASK,&depthMaskEnabled); + glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMaskEnabled); glDepthMask(GL_FALSE); gradientMesh.draw(); - if(depthMaskEnabled){ + if (depthMaskEnabled) { glDepthMask(GL_TRUE); } } //---------------------------------------------------------- -void ofSetBackgroundColor(int brightness, int alpha){ +void ofSetBackgroundColor(int brightness, int alpha) { ofSetBackgroundColor(brightness, brightness, brightness, alpha); } //---------------------------------------------------------- -void ofSetBackgroundColorHex(int hexColor, int alpha){ - ofSetBackgroundColor ( (hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha); +void ofSetBackgroundColorHex(int hexColor, int alpha) { + ofSetBackgroundColor((hexColor >> 16) & 0xff, (hexColor >> 8) & 0xff, (hexColor >> 0) & 0xff, alpha); } //---------------------------------------------------------- -void ofSetBackgroundColor(int r, int g, int b, int a){ - ofSetBackgroundColor(ofFloatColor(r/255.f,g/255.f,b/255.f,a/255.f)); +void ofSetBackgroundColor(int r, int g, int b, int a) { + ofSetBackgroundColor(ofFloatColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f)); } //---------------------------------------------------------- -void ofSetBackgroundColor(const ofFloatColor & c){ +void ofSetBackgroundColor(const ofFloatColor & c) { ofGetCurrentRenderer()->setBackgroundColor(c); } // end background functions //---------------------------------------------------------- - - - //--------------------------------------------------------------------------- // drawing modes //---------------------------------------------------------- -void ofSetRectMode(ofRectMode mode){ +void ofSetRectMode(ofRectMode mode) { ofGetCurrentRenderer()->setRectMode(mode); } //---------------------------------------------------------- -ofRectMode ofGetRectMode(){ - return ofGetCurrentRenderer()->getRectMode(); +ofRectMode ofGetRectMode() { + return ofGetCurrentRenderer()->getRectMode(); } //---------------------------------------------------------- -void ofNoFill(){ +void ofNoFill() { ofGetCurrentRenderer()->setFillMode(OF_OUTLINE); } //---------------------------------------------------------- -void ofFill(){ +void ofFill() { ofGetCurrentRenderer()->setFillMode(OF_FILLED); } // Returns OF_FILLED or OF_OUTLINE //---------------------------------------------------------- -ofFillFlag ofGetFill(){ - return ofGetCurrentRenderer()->getFillMode(); +ofFillFlag ofGetFill() { + return ofGetCurrentRenderer()->getFillMode(); } //---------------------------------------------------------- -void ofSetLineWidth(float lineWidth){ +void ofSetLineWidth(float lineWidth) { ofGetCurrentRenderer()->setLineWidth(lineWidth); } //---------------------------------------------------------- -void ofSetDepthTest(bool depthTest){ +void ofSetDepthTest(bool depthTest) { ofGetCurrentRenderer()->setDepthTest(depthTest); } //---------------------------------------------------------- -void ofEnableDepthTest(){ +void ofEnableDepthTest() { ofSetDepthTest(true); } //---------------------------------------------------------- -void ofDisableDepthTest(){ +void ofDisableDepthTest() { ofSetDepthTest(false); } //---------------------------------------- -void ofSetCurveResolution(int res){ +void ofSetCurveResolution(int res) { ofGetCurrentRenderer()->setCurveResolution(res); } //---------------------------------------------------------- -void ofSetCircleResolution(int res){ +void ofSetCircleResolution(int res) { ofGetCurrentRenderer()->setCircleResolution(res); } //---------------------------------------------------------- -void ofSetColor(int r, int g, int b){ - ofSetColor(r,g,b,255); +void ofSetColor(int r, int g, int b) { + ofSetColor(r, g, b, 255); } //---------------------------------------------------------- -void ofSetColor(int r, int g, int b, int a){ - ofGetCurrentRenderer()->setColor(r/255.f, g/255.f, b/255.f, a/255.f ); +void ofSetColor(int r, int g, int b, int a) { + ofGetCurrentRenderer()->setColor(r / 255.f, g / 255.f, b / 255.f, a / 255.f); } //---------------------------------------------------------- -void ofSetColor(int gray){ - if( gray > 255 ){ +void ofSetColor(int gray) { + if (gray > 255) { ofLogWarning("ofGraphics") << "ofSetColor(): gray value > 255, perhaps you want ofSetHexColor(int hexColor) instead?"; } ofSetColor(gray, gray, gray); } //---------------------------------------------------------- -void ofSetColor(const ofColor& acolor, int a){ - ofSetFloatColor( acolor.r/255.f, acolor.g/255.f, acolor.b/255.f, a/255.f ); +void ofSetColor(const ofColor & acolor, int a) { + ofSetFloatColor(acolor.r / 255.f, acolor.g / 255.f, acolor.b / 255.f, a / 255.f); } //---------------------------------------------------------- -void ofSetFloatColor(float r, float g, float b){ - ofSetFloatColor( r, g, b, 1.f); +void ofSetFloatColor(float r, float g, float b) { + ofSetFloatColor(r, g, b, 1.f); } //---------------------------------------------------------- -void ofSetFloatColor(float r, float g, float b, float a){ - ofGetCurrentRenderer()->setColor(r,g,b,a); +void ofSetFloatColor(float r, float g, float b, float a) { + ofGetCurrentRenderer()->setColor(r, g, b, a); } //---------------------------------------------------------- -void ofSetFloatColor(float gray){ - ofSetFloatColor( gray, gray, gray, 1.f); +void ofSetFloatColor(float gray) { + ofSetFloatColor(gray, gray, gray, 1.f); } //---------------------------------------------------------- -void ofSetFloatColor(const ofFloatColor& acolor, float a){ - ofSetFloatColor( acolor.r, acolor.g, acolor.b, a); +void ofSetFloatColor(const ofFloatColor & acolor, float a) { + ofSetFloatColor(acolor.r, acolor.g, acolor.b, a); } //---------------------------------------------------------- -void ofSetFloatColor(const ofFloatColor& acolor){ - ofSetFloatColor( acolor.r, acolor.g, acolor.b, acolor.a); +void ofSetFloatColor(const ofFloatColor & acolor) { + ofSetFloatColor(acolor.r, acolor.g, acolor.b, acolor.a); } //---------------------------------------------------------- -void ofSetHexColor(int hexColor){ +void ofSetHexColor(int hexColor) { int r = (hexColor >> 16) & 0xff; int g = (hexColor >> 8) & 0xff; int b = (hexColor >> 0) & 0xff; - ofSetColor(r,g,b); + ofSetColor(r, g, b); } //---------------------------------------------------------- -void ofEnableBlendMode(ofBlendMode blendMode){ +void ofEnableBlendMode(ofBlendMode blendMode) { ofGetCurrentRenderer()->setBlendMode(blendMode); } //---------------------------------------------------------- -void ofEnablePointSprites(){ - if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){ - static_cast(ofGetCurrentRenderer().get())->enablePointSprites(); +void ofEnablePointSprites() { + if (ofGetCurrentRenderer()->getType() == "GL" || ofGetCurrentRenderer()->getType() == "ProgrammableGL") { + static_cast(ofGetCurrentRenderer().get())->enablePointSprites(); } } //---------------------------------------------------------- -void ofDisablePointSprites(){ - if(ofGetCurrentRenderer()->getType()=="GL" || ofGetCurrentRenderer()->getType()=="ProgrammableGL"){ - static_cast(ofGetCurrentRenderer().get())->disablePointSprites(); +void ofDisablePointSprites() { + if (ofGetCurrentRenderer()->getType() == "GL" || ofGetCurrentRenderer()->getType() == "ProgrammableGL") { + static_cast(ofGetCurrentRenderer().get())->disablePointSprites(); } } //---------------------------------------------------------- -void ofDisableBlendMode(){ - ofEnableBlendMode(OF_BLENDMODE_DISABLED); +void ofDisableBlendMode() { + ofEnableBlendMode(OF_BLENDMODE_DISABLED); } //---------------------------------------------------------- -void ofEnableAlphaBlending(){ +void ofEnableAlphaBlending() { ofEnableBlendMode(OF_BLENDMODE_ALPHA); } //---------------------------------------------------------- -void ofDisableAlphaBlending(){ - ofDisableBlendMode(); +void ofDisableAlphaBlending() { + ofDisableBlendMode(); } //---------------------------------------------------------- -void ofEnableSmoothing(){ +void ofEnableSmoothing() { // please see: // http://www.opengl.org/resources/faq/technical/rasterization.htm ofGetCurrentRenderer()->setLineSmoothing(true); } //---------------------------------------------------------- -void ofDisableSmoothing(){ +void ofDisableSmoothing() { ofGetCurrentRenderer()->setLineSmoothing(false); } //---------------------------------------------------------- -void ofSetPolyMode(ofPolyWindingMode mode){ +void ofSetPolyMode(ofPolyWindingMode mode) { ofGetCurrentRenderer()->setPolyMode(mode); } //---------------------------------------- -void ofEnableAntiAliasing(){ +void ofEnableAntiAliasing() { ofGetCurrentRenderer()->enableAntiAliasing(); } //---------------------------------------- -void ofDisableAntiAliasing(){ +void ofDisableAntiAliasing() { ofGetCurrentRenderer()->disableAntiAliasing(); } //---------------------------------------- -void ofSetDrawBitmapMode(ofDrawBitmapMode mode){ +void ofSetBitmapMode(ofBitmapMode mode) { ofGetCurrentRenderer()->setBitmapTextMode(mode); } +//---------------------------------------- +void ofSetDrawBitmapMode(ofBitmapMode mode) { + ofSetBitmapMode(mode); +} + //---------------------------------------------------------- -void ofSetStyle(ofStyle style){ +void ofSetStyle(ofStyle style) { ofGetCurrentRenderer()->setStyle(style); } //---------------------------------------------------------- -ofStyle ofGetStyle(){ +ofStyle ofGetStyle() { return ofGetCurrentRenderer()->getStyle(); } //---------------------------------------------------------- -void ofPushStyle(){ +void ofPushStyle() { ofGetCurrentRenderer()->pushStyle(); } //---------------------------------------------------------- -void ofPopStyle(){ +void ofPopStyle() { ofGetCurrentRenderer()->popStyle(); } - - // end drawing modes //--------------------------------------------------------------------------- - - - //---------------------------------------------------------- // primitives //---------------------------------------------------------- -void ofDrawTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){ +void ofDrawTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3) { ofDrawTriangle(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z); } //---------------------------------------------------------- -void ofDrawTriangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){ +void ofDrawTriangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3) { ofDrawTriangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); } //---------------------------------------------------------- -void ofDrawTriangle(float x1,float y1,float x2,float y2,float x3, float y3){ +void ofDrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { ofDrawTriangle(x1, y1, 0.0f, x2, y2, 0.0f, x3, y3, 0.0f); } //---------------------------------------------------------- -void ofDrawTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){ - ofGetCurrentRenderer()->drawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3); +void ofDrawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) { + ofGetCurrentRenderer()->drawTriangle(x1, y1, z1, x2, y2, z2, x3, y3, z3); } //---------------------------------------------------------- -void ofDrawCircle(const glm::vec3 & p, float radius){ +void ofDrawCircle(const glm::vec3 & p, float radius) { ofDrawCircle(p.x, p.y, p.z, radius); } //---------------------------------------------------------- -void ofDrawCircle(const glm::vec2 & p, float radius){ +void ofDrawCircle(const glm::vec2 & p, float radius) { ofDrawCircle(p.x, p.y, 0.0, radius); } //---------------------------------------------------------- -void ofDrawCircle(float x, float y, float radius){ - ofDrawCircle(x,y,0,radius); +void ofDrawCircle(float x, float y, float radius) { + ofDrawCircle(x, y, 0, radius); } //---------------------------------------------------------- -void ofDrawCircle(float x, float y, float z, float radius){ - ofGetCurrentRenderer()->drawCircle(x,y,z,radius); +void ofDrawCircle(float x, float y, float z, float radius) { + ofGetCurrentRenderer()->drawCircle(x, y, z, radius); } //---------------------------------------------------------- -void ofDrawEllipse(const glm::vec3 & p, float width, float height){ +void ofDrawEllipse(const glm::vec3 & p, float width, float height) { ofDrawEllipse(p.x, p.y, p.z, width, height); } //---------------------------------------------------------- -void ofDrawEllipse(const glm::vec2 & p, float width, float height){ +void ofDrawEllipse(const glm::vec2 & p, float width, float height) { ofDrawEllipse(p.x, p.y, width, height); } //---------------------------------------------------------- -void ofDrawEllipse(float x, float y, float width, float height){ - ofDrawEllipse(x,y,0,width,height); +void ofDrawEllipse(float x, float y, float width, float height) { + ofDrawEllipse(x, y, 0, width, height); } //---------------------------------------------------------- -void ofDrawEllipse(float x, float y, float z, float width, float height){ - ofGetCurrentRenderer()->drawEllipse(x,y,z,width,height); +void ofDrawEllipse(float x, float y, float z, float width, float height) { + ofGetCurrentRenderer()->drawEllipse(x, y, z, width, height); } //---------------------------------------------------------- -void ofDrawLine(const glm::vec3 & p1, const glm::vec3 & p2){ +void ofDrawLine(const glm::vec3 & p1, const glm::vec3 & p2) { ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); } //---------------------------------------------------------- -void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2){ +void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2) { ofDrawLine(p1.x, p1.y, p2.x, p2.y); } //---------------------------------------------------------- -void ofDrawLine(float x1,float y1,float x2,float y2){ +void ofDrawLine(float x1, float y1, float x2, float y2) { ofDrawLine(x1, y1, 0.0f, x2, y2, 0.0f); } //---------------------------------------------------------- -void ofDrawLine(float x1,float y1,float z1,float x2,float y2,float z2){ - ofGetCurrentRenderer()->drawLine(x1,y1,z1,x2,y2,z2); +void ofDrawLine(float x1, float y1, float z1, float x2, float y2, float z2) { + ofGetCurrentRenderer()->drawLine(x1, y1, z1, x2, y2, z2); } //---------------------------------------------------------- -void ofDrawRectangle(const ofRectangle & r){ - ofDrawRectangle(r.x,r.y,0.0f,r.width, r.height); +void ofDrawRectangle(const ofRectangle & r) { + ofDrawRectangle(r.x, r.y, 0.0f, r.width, r.height); } //---------------------------------------------------------- -void ofDrawRectangle(const glm::vec3 & p,float w,float h){ +void ofDrawRectangle(const glm::vec3 & p, float w, float h) { ofDrawRectangle(p.x, p.y, p.z, w, h); } //---------------------------------------------------------- -void ofDrawRectangle(const glm::vec2 & p,float w,float h){ +void ofDrawRectangle(const glm::vec2 & p, float w, float h) { ofDrawRectangle(p.x, p.y, w, h); } //---------------------------------------------------------- -void ofDrawRectangle(float x,float y,float w,float h){ +void ofDrawRectangle(float x, float y, float w, float h) { ofDrawRectangle(x, y, 0.0f, w, h); } //---------------------------------------------------------- -void ofDrawRectangle(float x,float y,float z,float w,float h){ - ofGetCurrentRenderer()->drawRectangle(x,y,z,w,h); +void ofDrawRectangle(float x, float y, float z, float w, float h) { + ofGetCurrentRenderer()->drawRectangle(x, y, z, w, h); } //---------------------------------------------------------- -void ofDrawRectRounded(const ofRectangle & b, float r){ - ofDrawRectRounded(b,r,r,r,r); +void ofDrawRectRounded(const ofRectangle & b, float r) { + ofDrawRectRounded(b, r, r, r, r); } //---------------------------------------------------------- -void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float r){ - ofDrawRectRounded(p.x, p.y, p.z, w, h, r,r,r,r); +void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float r) { + ofDrawRectRounded(p.x, p.y, p.z, w, h, r, r, r, r); } //---------------------------------------------------------- -void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r){ - ofDrawRectRounded(p.x, p.y, 0.0, w, h, r,r,r,r); +void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r) { + ofDrawRectRounded(p.x, p.y, 0.0, w, h, r, r, r, r); } //---------------------------------------------------------- -void ofDrawRectRounded(float x, float y, float w, float h, float r){ - ofDrawRectRounded(x,y,0.0f,w,h,r,r,r,r); +void ofDrawRectRounded(float x, float y, float w, float h, float r) { + ofDrawRectRounded(x, y, 0.0f, w, h, r, r, r, r); } //---------------------------------------------------------- -void ofDrawRectRounded(float x, float y, float z, float w, float h, float r){ - ofDrawRectRounded(x,y,z,w,h,r,r,r,r); +void ofDrawRectRounded(float x, float y, float z, float w, float h, float r) { + ofDrawRectRounded(x, y, z, w, h, r, r, r, r); } //---------------------------------------------------------- void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius){ - ofDrawRectRounded(p.x,p.y,p.z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { + ofDrawRectRounded(p.x, p.y, p.z, w, h, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } //---------------------------------------------------------- void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius){ - ofDrawRectRounded(p.x,p.y,0.0,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { + ofDrawRectRounded(p.x, p.y, 0.0, w, h, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } //---------------------------------------------------------- void ofDrawRectRounded(const ofRectangle & b, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius) { + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { // if the parameter is an ofRectangle we don't do rectMode - ofDrawRectRounded(b.x,b.y,0.0f,b.width,b.height,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + ofDrawRectRounded(b.x, b.y, 0.0f, b.width, b.height, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } - //---------------------------------------------------------- void ofDrawRectRounded(float x, float y, float z, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius) { + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { // respect the current rectmode switch (ofGetRectMode()) { - case OF_RECTMODE_CENTER: - x -= w / 2.0f; - y -= h / 2.0f; - break; - default: - break; + case OF_RECTMODE_CENTER: + x -= w / 2.0f; + y -= h / 2.0f; + break; + default: + break; } ofGetCurrentRenderer()->getPath().clear(); - ofGetCurrentRenderer()->getPath().rectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); - + ofGetCurrentRenderer()->getPath().rectRounded(x, y, z, w, h, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } //---------------------------------------------------------- -void ofDrawCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){ +void ofDrawCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { ofGetCurrentRenderer()->getPath().clear(); - ofGetCurrentRenderer()->getPath().curveTo(x0,y0); - ofGetCurrentRenderer()->getPath().curveTo(x1,y1); - ofGetCurrentRenderer()->getPath().curveTo(x2,y2); - ofGetCurrentRenderer()->getPath().curveTo(x3,y3); - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); + ofGetCurrentRenderer()->getPath().curveTo(x0, y0); + ofGetCurrentRenderer()->getPath().curveTo(x1, y1); + ofGetCurrentRenderer()->getPath().curveTo(x2, y2); + ofGetCurrentRenderer()->getPath().curveTo(x3, y3); + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } //---------------------------------------------------------- -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){ +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) { ofGetCurrentRenderer()->getPath().clear(); - ofGetCurrentRenderer()->getPath().curveTo(x0,y0,z0); - ofGetCurrentRenderer()->getPath().curveTo(x1,y1,z1); - ofGetCurrentRenderer()->getPath().curveTo(x2,y2,z2); - ofGetCurrentRenderer()->getPath().curveTo(x3,y3,z3); - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); + ofGetCurrentRenderer()->getPath().curveTo(x0, y0, z0); + ofGetCurrentRenderer()->getPath().curveTo(x1, y1, z1); + ofGetCurrentRenderer()->getPath().curveTo(x2, y2, z2); + ofGetCurrentRenderer()->getPath().curveTo(x3, y3, z3); + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } - //---------------------------------------------------------- -void ofDrawBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){ +void ofDrawBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { ofGetCurrentRenderer()->getPath().clear(); - ofGetCurrentRenderer()->getPath().moveTo(x0,y0); - ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3); - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); + ofGetCurrentRenderer()->getPath().moveTo(x0, y0); + ofGetCurrentRenderer()->getPath().bezierTo(x1, y1, x2, y2, x3, y3); + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } //---------------------------------------------------------- -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){ +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) { ofGetCurrentRenderer()->getPath().clear(); - ofGetCurrentRenderer()->getPath().moveTo(x0,y0,z0); - ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3); - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); + ofGetCurrentRenderer()->getPath().moveTo(x0, y0, z0); + ofGetCurrentRenderer()->getPath().bezierTo(x1, y1, z1, x2, y2, z2, x3, y3, z3); + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } //---------------------------------------------------------- -void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){ - ofDrawTriangle(p1,p2,p3); +void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3) { + ofDrawTriangle(p1, p2, p3); } //---------------------------------------------------------- -void ofTriangle(float x1,float y1,float x2,float y2,float x3, float y3){ +void ofTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { ofDrawTriangle(x1, y1, x2, y2, x3, y3); } //---------------------------------------------------------- -void ofTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3){ - ofDrawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3); +void ofTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) { + ofDrawTriangle(x1, y1, z1, x2, y2, z2, x3, y3, z3); } //---------------------------------------------------------- -void ofCircle(const glm::vec3 & p, float radius){ +void ofCircle(const glm::vec3 & p, float radius) { ofDrawCircle(p, radius); } //---------------------------------------------------------- -void ofCircle(float x, float y, float radius){ - ofDrawCircle(x,y,radius); +void ofCircle(float x, float y, float radius) { + ofDrawCircle(x, y, radius); } //---------------------------------------------------------- -void ofCircle(float x, float y, float z, float radius){ - ofDrawCircle(x,y,z,radius); +void ofCircle(float x, float y, float z, float radius) { + ofDrawCircle(x, y, z, radius); } //---------------------------------------------------------- -void ofEllipse(const glm::vec3 & p, float width, float height){ +void ofEllipse(const glm::vec3 & p, float width, float height) { ofDrawEllipse(p, width, height); } //---------------------------------------------------------- -void ofEllipse(float x, float y, float width, float height){ - ofDrawEllipse(x,y,width,height); +void ofEllipse(float x, float y, float width, float height) { + ofDrawEllipse(x, y, width, height); } //---------------------------------------------------------- -void ofEllipse(float x, float y, float z, float width, float height){ - ofDrawEllipse(x,y,z,width,height); +void ofEllipse(float x, float y, float z, float width, float height) { + ofDrawEllipse(x, y, z, width, height); } //---------------------------------------------------------- -void ofLine(const glm::vec3 & p1, const glm::vec3 & p2){ +void ofLine(const glm::vec3 & p1, const glm::vec3 & p2) { ofDrawLine(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z); } //---------------------------------------------------------- -void ofLine(float x1,float y1,float x2,float y2){ +void ofLine(float x1, float y1, float x2, float y2) { ofDrawLine(x1, y1, x2, y2); } //---------------------------------------------------------- -void ofLine(float x1,float y1,float z1,float x2,float y2,float z2){ - ofDrawLine(x1,y1,z1,x2,y2,z2); +void ofLine(float x1, float y1, float z1, float x2, float y2, float z2) { + ofDrawLine(x1, y1, z1, x2, y2, z2); } //---------------------------------------------------------- -void ofRect(const ofRectangle & r){ - ofDrawRectangle(r.x,r.y,r.width, r.height); +void ofRect(const ofRectangle & r) { + ofDrawRectangle(r.x, r.y, r.width, r.height); } //---------------------------------------------------------- -void ofRect(const glm::vec3 & p,float w,float h){ +void ofRect(const glm::vec3 & p, float w, float h) { ofDrawRectangle(p, w, h); } //---------------------------------------------------------- -void ofRect(float x,float y,float w,float h){ +void ofRect(float x, float y, float w, float h) { ofDrawRectangle(x, y, w, h); } //---------------------------------------------------------- -void ofRect(float x,float y,float z,float w,float h){ - ofDrawRectangle(x,y,z,w,h); +void ofRect(float x, float y, float z, float w, float h) { + ofDrawRectangle(x, y, z, w, h); } //---------------------------------------------------------- -void ofRectRounded(const ofRectangle & b, float r){ - ofDrawRectRounded(b,r); +void ofRectRounded(const ofRectangle & b, float r) { + ofDrawRectRounded(b, r); } //---------------------------------------------------------- -void ofRectRounded(const glm::vec3 & p, float w, float h, float r){ +void ofRectRounded(const glm::vec3 & p, float w, float h, float r) { ofDrawRectRounded(p, w, h, r); } //---------------------------------------------------------- -void ofRectRounded(float x, float y, float w, float h, float r){ +void ofRectRounded(float x, float y, float w, float h, float r) { ofDrawRectRounded(x, y, w, h, r); } //---------------------------------------------------------- -void ofRectRounded(float x, float y, float z, float w, float h, float r){ - ofDrawRectRounded(x,y,z,w,h,r,r,r,r); +void ofRectRounded(float x, float y, float z, float w, float h, float r) { + ofDrawRectRounded(x, y, z, w, h, r, r, r, r); } //---------------------------------------------------------- void ofRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius){ - ofDrawRectRounded(p,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { + ofDrawRectRounded(p, w, h, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } //---------------------------------------------------------- void ofRectRounded(const ofRectangle & b, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius) { + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { // if the parameter is an ofRectangle we don't do rectMode - ofDrawRectRounded(b,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + ofDrawRectRounded(b, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } - //---------------------------------------------------------- void ofRectRounded(float x, float y, float z, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius) { - - ofDrawRectRounded(x,y,z,w,h,topLeftRadius,topRightRadius,bottomRightRadius,bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius) { + ofDrawRectRounded(x, y, z, w, h, topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius); } //---------------------------------------------------------- -void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){ - ofDrawCurve(x0, y0, x1, y1, x2, y2, x3, y3); +void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { + ofDrawCurve(x0, y0, x1, y1, x2, y2, x3, y3); } //---------------------------------------------------------- -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){ +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) { ofDrawCurve(x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3); } - //---------------------------------------------------------- -void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3){ - ofDrawBezier(x0,y0,x1,y1,x2,y2,x3,y3); +void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { + ofDrawBezier(x0, y0, x1, y1, x2, y2, x3, y3); } //---------------------------------------------------------- -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){ - ofDrawBezier(x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3); +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) { + ofDrawBezier(x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3); } //---------------------------------------------------------- -void ofBeginShape(){ +void ofBeginShape() { ofGetCurrentRenderer()->getPath().clear(); } //---------------------------------------------------------- -void ofVertex(float x, float y){ - ofGetCurrentRenderer()->getPath().lineTo(x,y); +void ofVertex(float x, float y) { + ofGetCurrentRenderer()->getPath().lineTo(x, y); } //---------------------------------------------------------- -void ofVertex(float x, float y, float z){ - ofGetCurrentRenderer()->getPath().lineTo(x,y,z); +void ofVertex(float x, float y, float z) { + ofGetCurrentRenderer()->getPath().lineTo(x, y, z); } //--------------------------------------------------- -void ofVertex(const glm::vec3 & p){ +void ofVertex(const glm::vec3 & p) { ofGetCurrentRenderer()->getPath().lineTo(p); } //--------------------------------------------------- -void ofVertex(const glm::vec2 & p){ +void ofVertex(const glm::vec2 & p) { ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0)); } //---------------------------------------------------------- -void ofVertices( const vector & polyPoints ){ - for( const auto & p: polyPoints ){ +void ofVertices(const vector & polyPoints) { + for (const auto & p : polyPoints) { ofGetCurrentRenderer()->getPath().lineTo(p); } } //---------------------------------------------------------- -void ofVertices( const vector & polyPoints ){ - for( const auto & p: polyPoints ){ +void ofVertices(const vector & polyPoints) { + for (const auto & p : polyPoints) { ofGetCurrentRenderer()->getPath().lineTo(glm::vec3(p, 0.0)); } } //---------------------------------------------------------- -void ofVertices( const vector & polyPoints ){ - for( const auto & p: polyPoints ){ +void ofVertices(const vector & polyPoints) { + for (const auto & p : polyPoints) { ofGetCurrentRenderer()->getPath().lineTo(p); } } //---------------------------------------------------------- -void ofVertices( const vector & polyPoints ){ - for( const auto & p: polyPoints ){ +void ofVertices(const vector & polyPoints) { + for (const auto & p : polyPoints) { ofGetCurrentRenderer()->getPath().lineTo(p); } } //--------------------------------------------------- -void ofCurveVertex(float x, float y){ - ofGetCurrentRenderer()->getPath().curveTo(x,y); +void ofCurveVertex(float x, float y) { + ofGetCurrentRenderer()->getPath().curveTo(x, y); } //--------------------------------------------------- -void ofCurveVertex(float x, float y, float z){ - ofGetCurrentRenderer()->getPath().curveTo(x,y,z); +void ofCurveVertex(float x, float y, float z) { + ofGetCurrentRenderer()->getPath().curveTo(x, y, z); } //---------------------------------------------------------- -void ofCurveVertices( const vector & curvePoints){ - for( const auto & p: curvePoints ){ +void ofCurveVertices(const vector & curvePoints) { + for (const auto & p : curvePoints) { ofGetCurrentRenderer()->getPath().curveTo(p); } } //---------------------------------------------------------- -void ofCurveVertices( const vector & curvePoints){ - for( const auto & p: curvePoints ){ +void ofCurveVertices(const vector & curvePoints) { + for (const auto & p : curvePoints) { ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0)); } } //---------------------------------------------------------- -void ofCurveVertices( const vector & curvePoints){ - for( const auto & p: curvePoints ){ +void ofCurveVertices(const vector & curvePoints) { + for (const auto & p : curvePoints) { ofGetCurrentRenderer()->getPath().curveTo(p); } } //---------------------------------------------------------- -void ofCurveVertices( const vector & curvePoints){ - for( const auto & p: curvePoints ){ +void ofCurveVertices(const vector & curvePoints) { + for (const auto & p : curvePoints) { ofGetCurrentRenderer()->getPath().curveTo(p); } } //--------------------------------------------------- -void ofCurveVertex(const glm::vec3 & p){ +void ofCurveVertex(const glm::vec3 & p) { ofGetCurrentRenderer()->getPath().curveTo(p); } //--------------------------------------------------- -void ofCurveVertex(const glm::vec2 & p){ +void ofCurveVertex(const glm::vec2 & p) { ofGetCurrentRenderer()->getPath().curveTo(glm::vec3(p, 0.0)); } //--------------------------------------------------- -void ofBezierVertex(float x1, float y1, float x2, float y2, float x3, float y3){ - ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,x2,y2,x3,y3); +void ofBezierVertex(float x1, float y1, float x2, float y2, float x3, float y3) { + ofGetCurrentRenderer()->getPath().bezierTo(x1, y1, x2, y2, x3, y3); } //--------------------------------------------------- -void ofBezierVertex(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3){ +void ofBezierVertex(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3) { ofGetCurrentRenderer()->getPath().bezierTo(p1, p2, p3); } //--------------------------------------------------- -void ofBezierVertex(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3){ - ofGetCurrentRenderer()->getPath().bezierTo(glm::vec3(p1, 0.0), glm::vec3(p2,0.0), glm::vec3(p3,0.0)); +void ofBezierVertex(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3) { + ofGetCurrentRenderer()->getPath().bezierTo(glm::vec3(p1, 0.0), glm::vec3(p2, 0.0), glm::vec3(p3, 0.0)); } //--------------------------------------------------- -void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3){ - ofGetCurrentRenderer()->getPath().bezierTo(x1,y1,z1,x2,y2,z2,x3,y3,z3); +void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) { + ofGetCurrentRenderer()->getPath().bezierTo(x1, y1, z1, x2, y2, z2, x3, y3, z3); } //---------------------------------------------------------- -void ofNextContour(bool bClose){ - if (bClose){ +void ofNextContour(bool bClose) { + if (bClose) { ofGetCurrentRenderer()->getPath().close(); } ofGetCurrentRenderer()->getPath().newSubPath(); } - //---------------------------------------------------------- -void ofEndShape(bool bClose){ +void ofEndShape(bool bClose) { // (close -> add the first point to the end) // ----------------------------------------------- - if (bClose){ + if (bClose) { ofGetCurrentRenderer()->getPath().close(); } - ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath());//.draw(); - + ofGetCurrentRenderer()->draw(ofGetCurrentRenderer()->getPath()); //.draw(); } //-------------------------------------------------- // text //-------------------------------------------------- -template<> -void ofDrawBitmapString(const string & textString, float x, float y, float z){ - ofGetCurrentRenderer()->drawString(textString,x,y,z); +template <> +void ofDrawBitmapString(const string & textString, float x, float y, float z) { + ofGetCurrentRenderer()->drawString(textString, x, y, z); } -template<> -void ofDrawBitmapString(const std::string & textString, const glm::vec3 & p){ +template <> +void ofDrawBitmapString(const std::string & textString, const glm::vec3 & p) { ofGetCurrentRenderer()->drawString(textString, p.x, p.y, p.z); } -template<> -void ofDrawBitmapString(const std::string & textString, const glm::vec2 & p){ +template <> +void ofDrawBitmapString(const std::string & textString, const glm::vec2 & p) { ofGetCurrentRenderer()->drawString(textString, p.x, p.y, 0.f); } //-------------------------------------------------- -void ofDrawBitmapStringHighlight(string text, const glm::vec3& position, const ofColor& background, const ofColor& foreground) { +void ofDrawBitmapStringHighlight(string text, const glm::vec3 & position, const ofColor & background, const ofColor & foreground) { ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground); } //-------------------------------------------------- -void ofDrawBitmapStringHighlight(string text, const glm::vec2& position, const ofColor& background, const ofColor& foreground) { +void ofDrawBitmapStringHighlight(string text, const glm::vec2 & position, const ofColor & background, const ofColor & foreground) { ofDrawBitmapStringHighlight(text, position.x, position.y, background, foreground); } //-------------------------------------------------- -void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& background, const ofColor& foreground) { +void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor & background, const ofColor & foreground) { vector lines = ofSplitString(text, "\n"); int maxLineLength = 0; - for(int i = 0; i < (int)lines.size(); i++) { + for (int i = 0; i < (int)lines.size(); i++) { // tabs are not rendered const string & line(lines[i]); int currentLineLength = 0; - for(int j = 0; j < (int)line.size(); j++) { + for (int j = 0; j < (int)line.size(); j++) { if (line[j] == '\t') { currentLineLength += 8 - (currentLineLength % 8); } else { @@ -1268,28 +1252,27 @@ void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& backg } maxLineLength = std::max(maxLineLength, currentLineLength); } - + int padding = 4; int fontSize = 8; float leading = 1.7; int height = lines.size() * fontSize * leading - 1; int width = maxLineLength * fontSize; - + ofPushStyle(); glDepthMask(false); ofSetColor(background); ofFill(); ofPushMatrix(); - - if(ofGetStyle().drawBitmapMode == OF_BITMAPMODE_MODEL) { - ofTranslate(x,y,0); - ofScale(1,-1,0); - ofTranslate(-(padding), + padding - fontSize - 2,0); + + if (ofGetStyle().bitmapMode == OF_BITMAPMODE_MODEL) { + ofTranslate(x, y, 0); + ofScale(1, -1, 0); + ofTranslate(-(padding), +padding - fontSize - 2, 0); } else { - ofTranslate(x-(padding), y-(padding + fontSize + 2), 0); - + ofTranslate(x - (padding), y - (padding + fontSize + 2), 0); } - + ofDrawRectangle(0, 0, width + 2 * padding, height + 2 * padding); ofPopMatrix(); ofSetColor(foreground); @@ -1299,6 +1282,5 @@ void ofDrawBitmapStringHighlight(string text, int x, int y, const ofColor& backg ofPopStyle(); } - // end text //-------------------------------------------------- diff --git a/libs/openFrameworks/graphics/ofGraphics.h b/libs/openFrameworks/graphics/ofGraphics.h index adf4f6d49ea..1b38540ee65 100644 --- a/libs/openFrameworks/graphics/ofGraphics.h +++ b/libs/openFrameworks/graphics/ofGraphics.h @@ -1,25 +1,26 @@ #pragma once -#include "ofGraphicsBaseTypes.h" -#include "ofRectangle.h" #include "ofConstants.h" + #include "glm/fwd.hpp" +#include "ofGraphicsBaseTypes.h" +#include "ofRectangle.h" class ofVec3f; class ofVec2f; -template +template class ofColor_; typedef ofColor_ ofColor; typedef ofColor_ ofFloatColor; typedef ofColor_ ofShortColor; -template -std::string ofToString(const T&); +template +std::string ofToString(const T &); /// \cond INTERNAL -#define CIRC_RESOLUTION 22 +#define CIRC_RESOLUTION 22 /// \endcond /// \name Color @@ -54,7 +55,7 @@ void ofSetColor(int r, int g, int b); /// ~~~~ void ofSetColor(int r, int g, int b, int a); void ofSetColor(int gray); -void ofSetColor(const ofColor& acolor, int a); +void ofSetColor(const ofColor & acolor, int a); /// \brief Sets the draw color with r,g,b,a 0-1. /// @@ -64,13 +65,13 @@ void ofSetColor(const ofColor& acolor, int a); void ofSetFloatColor(float r, float g, float b); void ofSetFloatColor(float r, float g, float b, float a); void ofSetFloatColor(float gray); -void ofSetFloatColor(const ofFloatColor& acolor, float a); -void ofSetFloatColor(const ofFloatColor& acolor); +void ofSetFloatColor(const ofFloatColor & acolor, float a); +void ofSetFloatColor(const ofFloatColor & acolor); -template -void ofSetColor( const ofColor_& acolor ) { +template +void ofSetColor(const ofColor_ & acolor) { float limit = ofColor_::limit(); - ofSetFloatColor( acolor.r / limit, acolor.g / limit, acolor.b/limit, acolor.a / limit ); + ofSetFloatColor(acolor.r / limit, acolor.g / limit, acolor.b / limit, acolor.a / limit); } /// Sets the draw color with r,g,b, passed in as a hex. Hex is a conventient @@ -83,7 +84,7 @@ void ofSetColor( const ofColor_& acolor ) { /// ofSetColor(0x00ff00); // green (0,255,0); /// } /// ~~~~ -void ofSetHexColor( int hexColor ); +void ofSetHexColor(int hexColor); /// \brief Draw shapes as outlines with the current draw color. /// ~~~~{.cpp} @@ -112,8 +113,7 @@ ofFillFlag ofGetFill(); /// \brief Returns the current background color as an ofColor. ofFloatColor ofGetBackgroundColor(); -OF_DEPRECATED_MSG("Use ofGetBackgroundColor instead",ofFloatColor ofGetBackground()); - +OF_DEPRECATED_MSG("Use ofGetBackgroundColor instead", ofFloatColor ofGetBackground()); /// \brief Sets the background color. /// @@ -128,7 +128,7 @@ OF_DEPRECATED_MSG("Use ofGetBackgroundColor instead",ofFloatColor ofGetBackgroun /// ofBackground(255,0,0); // Sets the background color to red /// } /// ~~~~ -void ofBackground(int r, int g, int b, int a=255); +void ofBackground(int r, int g, int b, int a = 255); void ofBackground(int brightness, int alpha = 255); void ofBackground(const ofColor & c); @@ -140,7 +140,6 @@ void ofBackground(const ofColor & c); /// ~~~~ void ofBackgroundHex(int hexColor, int alpha = 255); - /// \brief Sets the background color to a gradient. /// /// It takes as input 2 ofColor() objects and a Gradient Mode. @@ -190,7 +189,7 @@ void ofBackgroundHex(int hexColor, int alpha = 255); /// // Sets the background to a bar gradient /// } /// ~~~~ -void ofBackgroundGradient(const ofFloatColor& start, const ofFloatColor& end, ofGradientMode mode = OF_GRADIENT_CIRCULAR); +void ofBackgroundGradient(const ofFloatColor & start, const ofFloatColor & end, ofGradientMode mode = OF_GRADIENT_CIRCULAR); /// \brief Sets the background color. It takes as input r,g,b (0-255). The /// background is cleared automatically, just before the draw() command, so @@ -203,7 +202,7 @@ void ofBackgroundGradient(const ofFloatColor& start, const ofFloatColor& end, of /// ofSetBackgroundColor(255,0,0); // Sets the background color to red /// } /// ~~~~ -void ofSetBackgroundColor(int r, int g, int b, int a=255); +void ofSetBackgroundColor(int r, int g, int b, int a = 255); void ofSetBackgroundColor(int brightness, int alpha = 255); void ofSetBackgroundColor(const ofFloatColor & c); @@ -230,7 +229,7 @@ void ofSetBackgroundColorHex(int hexColor, int alpha = 255); /// } /// } /// ~~~~ -void ofSetBackgroundAuto(bool bManual); // default is true +void ofSetBackgroundAuto(bool bManual); // default is true bool ofGetBackgroundAuto(); /// \brief Clears the color and depth bits of current renderer and replaces it with @@ -280,7 +279,7 @@ void ofClear(float r, float g, float b); /// } /// ~~~~ void ofClear(float brightness, float a); -OF_DEPRECATED_MSG("Use ofClear(brightness, alpha) instead",void ofClear(float brightness)); +OF_DEPRECATED_MSG("Use ofClear(brightness, alpha) instead", void ofClear(float brightness)); /// \brief Clears the color and depth bits of current renderer and replaces it with /// an ofColor. @@ -301,9 +300,8 @@ void ofClearFloat(float r, float g, float b, float a); void ofClearFloat(float brightness, float a); void ofClearFloat(const ofFloatColor & c); - // OF's access to settings (bgAuto, origin, corner mode): -OF_DEPRECATED_MSG("Use ofGetBackgroundAuto instead",bool ofbClearBg()); +OF_DEPRECATED_MSG("Use ofGetBackgroundAuto instead", bool ofbClearBg()); /// \} /// \name 2D Primitives Drawing @@ -315,8 +313,8 @@ OF_DEPRECATED_MSG("Use ofGetBackgroundAuto instead",bool ofbClearBg()); /// ofDrawTriangle(50,10,10,40,90,40); /// } /// ~~~~ -void ofDrawTriangle(float x1,float y1,float x2,float y2,float x3, float y3); -void ofDrawTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3); +void ofDrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3); +void ofDrawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3); void ofDrawTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3); void ofDrawTriangle(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3); @@ -353,8 +351,8 @@ void ofDrawEllipse(const glm::vec2 & p, float width, float height); /// ofDrawLine(10,10,100,100); /// } /// ~~~~ -void ofDrawLine(float x1,float y1,float x2,float y2); -void ofDrawLine(float x1,float y1,float z1,float x2,float y2,float z2); +void ofDrawLine(float x1, float y1, float x2, float y2); +void ofDrawLine(float x1, float y1, float z1, float x2, float y2, float z2); void ofDrawLine(const glm::vec3 & p1, const glm::vec3 & p2); void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2); @@ -364,8 +362,7 @@ void ofDrawLine(const glm::vec2 & p1, const glm::vec2 & p2); /// ofDrawRect(10,10,100,100); /// } /// ~~~~ -void ofDrawRectangle(float x1,float y1,float w,float h); - +void ofDrawRectangle(float x1, float y1, float w, float h); /// \brief Draws an rectangle from the given rectangle. /// ~~~~{.cpp} @@ -381,7 +378,6 @@ void ofDrawRectangle(float x1,float y1,float w,float h); /// ~~~~ void ofDrawRectangle(const ofRectangle & r); - /// \brief Draws an rectangle from point p, with a given width and height. /// ~~~~{.cpp} /// void ofApp::draw(){ @@ -392,9 +388,8 @@ void ofDrawRectangle(const ofRectangle & r); /// ofDrawRectangle(p, 80, 80); // Draw the rectangle /// } /// ~~~~ -void ofDrawRectangle(const glm::vec3 & p,float w,float h); -void ofDrawRectangle(const glm::vec2 & p,float w,float h); - +void ofDrawRectangle(const glm::vec3 & p, float w, float h); +void ofDrawRectangle(const glm::vec2 & p, float w, float h); /// Draws an rectangle from point X, Y at depth Z with a given width and height. /// ~~~~{.cpp} @@ -402,7 +397,7 @@ void ofDrawRectangle(const glm::vec2 & p,float w,float h); /// ofDrawRectangle(10,10,-100, 80, 80); // Draw a rectangle at 100 pixels in depth /// } /// ~~~~ -void ofDrawRectangle(float x,float y,float z,float w,float h); +void ofDrawRectangle(float x, float y, float z, float w, float h); /// \brief Draws a rounded rectangle from the given rectangle using given /// radius. @@ -433,7 +428,6 @@ void ofDrawRectRounded(const ofRectangle & b, float r); void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float r); void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r); - /// \brief Draws a rectangle from point X, Y with a given width, height and radius of /// rounded corners. /// @@ -444,7 +438,6 @@ void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float r); /// ~~~~ void ofDrawRectRounded(float x, float y, float w, float h, float r); - /// \brief Draws a rectangle from point X, Y, at depth Z with a given width, height and /// radius of rounded corners. /// @@ -455,7 +448,6 @@ void ofDrawRectRounded(float x, float y, float w, float h, float r); /// ~~~~ void ofDrawRectRounded(float x, float y, float z, float w, float h, float r); - /// \brief Draws a rounded rectangle from point X, Y, at depth Z with a given width, /// height and radius of rounded corners. /// @@ -465,14 +457,13 @@ void ofDrawRectRounded(float x, float y, float z, float w, float h, float r); /// } /// ~~~~ void ofDrawRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius); void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius); - + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius); /// \brief Draws a rounded rectangle from the given rectangle using different given /// radius for each of the corners. @@ -489,9 +480,9 @@ void ofDrawRectRounded(const glm::vec2 & p, float w, float h, float topLeftRadiu /// } /// ~~~~ void ofDrawRectRounded(const ofRectangle & b, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius); /// \brief Draws a rounded rectangle from point X, Y, at depth Z with a given width, /// height and different radius for each rounded corner. @@ -502,9 +493,9 @@ void ofDrawRectRounded(const ofRectangle & b, float topLeftRadius, /// } /// ~~~~ void ofDrawRectRounded(float x, float y, float z, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius); + float topRightRadius, + float bottomRightRadius, + float bottomLeftRadius); /// \brief Draws a curve from point (x1, y1) to point (x2, y2). The curve is shaped by /// the two control points (x0,y0) and (x3,y3). @@ -516,53 +507,43 @@ void ofDrawCurve(float x0, float y0, float z0, float x1, float y1, float z1, flo void ofDrawBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3); 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); -OF_DEPRECATED_MSG("Use ofDrawTriangle instead",void ofTriangle(float x1,float y1,float x2,float y2,float x3, float y3)); -OF_DEPRECATED_MSG("Use ofDrawTriangle instead",void ofTriangle(float x1,float y1,float z1,float x2,float y2,float z2,float x3, float y3,float z3)); -OF_DEPRECATED_MSG("Use ofDrawTriangle instead",void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3)); +OF_DEPRECATED_MSG("Use ofDrawTriangle instead", void ofTriangle(float x1, float y1, float x2, float y2, float x3, float y3)); +OF_DEPRECATED_MSG("Use ofDrawTriangle instead", void ofTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)); +OF_DEPRECATED_MSG("Use ofDrawTriangle instead", void ofTriangle(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 & p3)); -OF_DEPRECATED_MSG("Use ofDrawCircle instead",void ofCircle(float x, float y, float radius)); -OF_DEPRECATED_MSG("Use ofDrawCircle instead",void ofCircle(float x, float y, float z, float radius)); -OF_DEPRECATED_MSG("Use ofDrawCircle instead",void ofCircle(const glm::vec3 & p, float radius)); +OF_DEPRECATED_MSG("Use ofDrawCircle instead", void ofCircle(float x, float y, float radius)); +OF_DEPRECATED_MSG("Use ofDrawCircle instead", void ofCircle(float x, float y, float z, float radius)); +OF_DEPRECATED_MSG("Use ofDrawCircle instead", void ofCircle(const glm::vec3 & p, float radius)); -OF_DEPRECATED_MSG("Use ofDrawEllipse instead",void ofEllipse(float x, float y, float width, float height)); -OF_DEPRECATED_MSG("Use ofDrawEllipse instead",void ofEllipse(float x, float y, float z, float width, float height)); -OF_DEPRECATED_MSG("Use ofDrawEllipse instead",void ofEllipse(const glm::vec3 & p, float width, float height)); +OF_DEPRECATED_MSG("Use ofDrawEllipse instead", void ofEllipse(float x, float y, float width, float height)); +OF_DEPRECATED_MSG("Use ofDrawEllipse instead", void ofEllipse(float x, float y, float z, float width, float height)); +OF_DEPRECATED_MSG("Use ofDrawEllipse instead", void ofEllipse(const glm::vec3 & p, float width, float height)); -OF_DEPRECATED_MSG("Use ofDrawLine instead",void ofLine(float x1,float y1,float x2,float y2)); -OF_DEPRECATED_MSG("Use ofDrawLine instead",void ofLine(float x1,float y1,float z1,float x2,float y2,float z2)); -OF_DEPRECATED_MSG("Use ofDrawLine instead",void ofLine(const glm::vec3 & p1, const glm::vec3 & p2)); +OF_DEPRECATED_MSG("Use ofDrawLine instead", void ofLine(float x1, float y1, float x2, float y2)); +OF_DEPRECATED_MSG("Use ofDrawLine instead", void ofLine(float x1, float y1, float z1, float x2, float y2, float z2)); +OF_DEPRECATED_MSG("Use ofDrawLine instead", void ofLine(const glm::vec3 & p1, const glm::vec3 & p2)); -OF_DEPRECATED_MSG("Use ofDrawRectangle instead",void ofRect(float x1,float y1,float w,float h)); -OF_DEPRECATED_MSG("Use ofDrawRectangle instead",void ofRect(const ofRectangle & r)); -OF_DEPRECATED_MSG("Use ofDrawRectangle instead",void ofRect(const glm::vec3 & p,float w,float h)); -OF_DEPRECATED_MSG("Use ofDrawRectangle instead",void ofRect(float x,float y,float z,float w,float h)); +OF_DEPRECATED_MSG("Use ofDrawRectangle instead", void ofRect(float x1, float y1, float w, float h)); +OF_DEPRECATED_MSG("Use ofDrawRectangle instead", void ofRect(const ofRectangle & r)); +OF_DEPRECATED_MSG("Use ofDrawRectangle instead", void ofRect(const glm::vec3 & p, float w, float h)); +OF_DEPRECATED_MSG("Use ofDrawRectangle instead", void ofRect(float x, float y, float z, float w, float h)); -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(const ofRectangle & b, float r)); -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(const glm::vec3 & p, float w, float h, float r)); -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(float x, float y, float w, float h, float r)); -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(float x, float y, float z, float w, float h, float r)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(const ofRectangle & b, float r)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(const glm::vec3 & p, float w, float h, float r)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(float x, float y, float w, float h, float r)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(float x, float y, float z, float w, float h, float r)); //---------------------------------------------------------- -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius)); - -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(const ofRectangle & b, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(const glm::vec3 & p, float w, float h, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius)); -OF_DEPRECATED_MSG("Use ofDrawRectRounded instead",void ofRectRounded(float x, float y, float z, float w, float h, float topLeftRadius, - float topRightRadius, - float bottomRightRadius, - float bottomLeftRadius)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(const ofRectangle & b, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius)); -OF_DEPRECATED_MSG("Use ofDrawCurve instead",void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)); -OF_DEPRECATED_MSG("Use ofDrawCurve instead",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)); -OF_DEPRECATED_MSG("Use ofDrawBezier instead",void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)); -OF_DEPRECATED_MSG("Use ofDrawBezier instead",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)); +OF_DEPRECATED_MSG("Use ofDrawRectRounded instead", void ofRectRounded(float x, float y, float z, float w, float h, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius)); +OF_DEPRECATED_MSG("Use ofDrawCurve instead", void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)); +OF_DEPRECATED_MSG("Use ofDrawCurve instead", 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)); +OF_DEPRECATED_MSG("Use ofDrawBezier instead", void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)); +OF_DEPRECATED_MSG("Use ofDrawBezier instead", 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)); /// \} /// \name Custom Shapes Drawing @@ -592,10 +573,10 @@ void ofVertex(float x, float y); void ofVertex(float x, float y, float z); void ofVertex(const glm::vec3 & p); void ofVertex(const glm::vec2 & p); -void ofVertices(const std::vector & polyPoints); -void ofVertices(const std::vector & polyPoints); -void ofVertices(const std::vector & polyPoints); -void ofVertices(const std::vector & polyPoints); +void ofVertices(const std::vector & polyPoints); +void ofVertices(const std::vector & polyPoints); +void ofVertices(const std::vector & polyPoints); +void ofVertices(const std::vector & polyPoints); /// \brief Specifies a single point of a shape. The difference from ofVertex is that /// the line describing the edge of the shape between two points will be a @@ -610,10 +591,10 @@ void ofCurveVertex(const glm::vec2 & p); /// \brief Draws a curve through a series of vertices stored as a vector of /// ofPoints. Should be called between ofBeginShape() and ofEndShape(). -void ofCurveVertices(const std::vector & curvePoints); -void ofCurveVertices(const std::vector & curvePoints); -void ofCurveVertices(const std::vector & curvePoints); -void ofCurveVertices(const std::vector & curvePoints); +void ofCurveVertices(const std::vector & curvePoints); +void ofCurveVertices(const std::vector & curvePoints); +void ofCurveVertices(const std::vector & curvePoints); +void ofCurveVertices(const std::vector & curvePoints); /// \brief Describes a bezier curve through three points of a shape. To be called /// between ofBeginShape() and ofEndShape(). @@ -622,8 +603,7 @@ void ofBezierVertex(const glm::vec3 & p1, const glm::vec3 & p2, const glm::vec3 void ofBezierVertex(const glm::vec2 & p1, const glm::vec2 & p2, const glm::vec2 & p3); void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3); - -enum ofCloseShape{ +enum ofCloseShape { OF_OPEN = 0, OF_CLOSE = 1, }; @@ -643,14 +623,12 @@ void ofEndShape(bool bClose = false); /// /// \param bClose If set to true then the previous contour will be /// automatically closed. Default false -void ofNextContour(bool bClose = false); // for multi contour shapes! - +void ofNextContour(bool bClose = false); // for multi contour shapes! /// \} /// \name Text Drawing /// \{ - /// \brief Set the bitmap drawing mode /// /// Valid modes: @@ -668,7 +646,8 @@ void ofNextContour(bool bClose = false); // for multi contour shapes! /// OF_BITMAPMODE_SIMPLE: only does 2d and the z coordinate is just disacarded, so if z is not 0 /// the position in which it'll be drawn will be wrong. /// -void ofSetDrawBitmapMode(ofDrawBitmapMode mode); +void ofSetBitmapMode(ofBitmapMode mode); +[[deprecated("use ofSetBitmapMode")]] void ofSetDrawBitmapMode(ofBitmapMode mode); /// \brief Draws a bitmapped string, on screen, at point (x,y). /// @@ -699,24 +678,23 @@ void ofSetDrawBitmapMode(ofDrawBitmapMode mode); /// with a small typeface, non-anti-aliased, as a suitable alternative. /// /// \sa ofTrueTypeFont -template +template void ofDrawBitmapString(const T & textString, float x, float y); -template +template void ofDrawBitmapString(const T & textString, const glm::vec3 & p); -template +template void ofDrawBitmapString(const T & textString, const glm::vec2 & p); -template +template void ofDrawBitmapString(const T & textString, float x, float y, float z); -template<> +template <> void ofDrawBitmapString(const std::string & textString, const glm::vec3 & p); -template<> +template <> void ofDrawBitmapString(const std::string & textString, const glm::vec2 & p); -template<> +template <> void ofDrawBitmapString(const std::string & textString, float x, float y, float z); -void ofDrawBitmapStringHighlight(std::string text, const glm::vec3& position, const ofColor& background = ofColor::black, const ofColor& foreground = ofColor::white); -void ofDrawBitmapStringHighlight(std::string text, const glm::vec2& position, const ofColor& background = ofColor::black, const ofColor& foreground = ofColor::white); -void ofDrawBitmapStringHighlight(std::string text, int x, int y, const ofColor& background = ofColor::black, const ofColor& foreground = ofColor::white); - +void ofDrawBitmapStringHighlight(std::string text, const glm::vec3 & position, const ofColor & background = ofColor::black, const ofColor & foreground = ofColor::white); +void ofDrawBitmapStringHighlight(std::string text, const glm::vec2 & position, const ofColor & background = ofColor::black, const ofColor & foreground = ofColor::white); +void ofDrawBitmapStringHighlight(std::string text, int x, int y, const ofColor & background = ofColor::black, const ofColor & foreground = ofColor::white); /// \} /// \name Rendering Settings @@ -743,7 +721,7 @@ void ofSetupScreen(); /// } /// ~~~~ /// \sa ofSetRectMode() -ofRectMode ofGetRectMode(); +ofRectMode ofGetRectMode(); /// \brief Sets the resolution for the ofDrawCircle command. By default, the circle is 22 /// points, but if you need to draw larger circles, you can adjust the @@ -758,10 +736,9 @@ ofRectMode ofGetRectMode(); /// ofDrawCircle(450,150,100); //draws a fine circle /// } /// ~~~~ -void ofSetCircleResolution(int res); // if there 22 is a problem, you can change it here +void ofSetCircleResolution(int res); // if there 22 is a problem, you can change it here void ofSetCurveResolution(int res); - /// \brief Sets the width of the ofDrawLine() called after. /// ~~~~{.cpp} /// void ofApp::draw(){ @@ -777,7 +754,6 @@ void ofSetLineWidth(float lineWidth); /// or draw order (`false`). void ofSetDepthTest(bool depthTest); - /// \brief Turns on depth testing so rendering happens according to z-depth rather /// than draw order. /// @@ -854,7 +830,7 @@ void ofDisablePointSprites(); /// ofDrawRectangle(120,20,100,100); // draws the rect without alpha /// } /// ~~~~ -void ofEnableAlphaBlending(); // this just turns on and off opengl blending, the common mode +void ofEnableAlphaBlending(); // this just turns on and off opengl blending, the common mode /// \brief Turn off alpha blending. /// ~~~~{.cpp} @@ -1176,17 +1152,16 @@ void ofRotateZRad(float radians); /// \name Matrix Transformation /// \{ -void ofLoadIdentityMatrix (void); -void ofLoadMatrix (const glm::mat4 & m); // Andreas: I've included both a mat and a float* version here, -void ofLoadMatrix (const float *m); // ideally we would always use mat4, but in a lot of temporary -void ofMultMatrix (const glm::mat4 & m); // mat objects when interacting with non-OF code -void ofMultMatrix (const float *m); +void ofLoadIdentityMatrix(void); +void ofLoadMatrix(const glm::mat4 & m); // Andreas: I've included both a mat and a float* version here, +void ofLoadMatrix(const float * m); // ideally we would always use mat4, but in a lot of temporary +void ofMultMatrix(const glm::mat4 & m); // mat objects when interacting with non-OF code +void ofMultMatrix(const float * m); void ofSetMatrixMode(ofMatrixMode matrixMode); void ofLoadViewMatrix(const glm::mat4 & m); void ofMultViewMatrix(const glm::mat4 & m); glm::mat4 ofGetCurrentViewMatrix(); - /// \} /// \name Viewport Setup /// \{ @@ -1211,7 +1186,7 @@ void ofViewport(ofRectangle viewport); /// \param y The y position of the viewport /// \param width The width of the viewport, defaults to ofGetWidth() /// \param height The height of the viewport, defaults to ofGetHeight() -void ofViewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=ofIsVFlipped()); +void ofViewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = ofIsVFlipped()); /// \brief Get the position and size of the current viewport /// \returns A rectangle describing the viewport @@ -1229,44 +1204,40 @@ int ofGetViewportWidth(); /// \returns A height in pixels int ofGetViewportHeight(); - // if nearDist or farDist are 0 assume defaults (calculated based on width / height) void ofSetupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0); void ofSetupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1); OF_DEPRECATED_MSG("ofSetupScreenPerspective() doesn't accept orientation and vflip parameters anymore, use ofSetOrientation() to specify them", - void ofSetupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip = ofIsVFlipped(), float fov = 60, float nearDist = 0, float farDist = 0) - ); + void ofSetupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip = ofIsVFlipped(), float fov = 60, float nearDist = 0, float farDist = 0)); OF_DEPRECATED_MSG("ofSetupScreenOrtho() doesn't accept orientation and vflip parameters anymore, use ofSetOrientation() to specify them", - void ofSetupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip = ofIsVFlipped(), float nearDist = -1, float farDist = 1) - ); + void ofSetupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip = ofIsVFlipped(), float nearDist = -1, float farDist = 1)); int ofOrientationToDegrees(ofOrientation orientation); void ofSetCoordHandedness(ofHandednessType handedness); ofHandednessType ofGetCoordHandedness(); - //-------------------------------------------------- -template -void ofDrawBitmapString(const T & textString, const glm::vec3 & p){ +template +void ofDrawBitmapString(const T & textString, const glm::vec3 & p) { ofDrawBitmapString(ofToString(textString), p); } //-------------------------------------------------- -template -void ofDrawBitmapString(const T & textString, const glm::vec2 & p){ +template +void ofDrawBitmapString(const T & textString, const glm::vec2 & p) { ofDrawBitmapString(ofToString(textString), p); } //-------------------------------------------------- -template -void ofDrawBitmapString(const T & textString, float x, float y){ +template +void ofDrawBitmapString(const T & textString, float x, float y) { ofDrawBitmapString(ofToString(textString), x, y, 0.f); } //-------------------------------------------------- -template -void ofDrawBitmapString(const T & textString, float x, float y, float z){ +template +void ofDrawBitmapString(const T & textString, float x, float y, float z) { ofDrawBitmapString(ofToString(textString), x, y, z); } diff --git a/libs/openFrameworks/graphics/ofGraphicsBaseTypes.h b/libs/openFrameworks/graphics/ofGraphicsBaseTypes.h index 9af791e6acd..167b7ee4bf1 100644 --- a/libs/openFrameworks/graphics/ofGraphicsBaseTypes.h +++ b/libs/openFrameworks/graphics/ofGraphicsBaseTypes.h @@ -1,9 +1,10 @@ #pragma once -#include "ofGraphicsConstants.h" #include "ofConstants.h" + #include "glm/fwd.hpp" #include "ofColor.h" +#include "ofGraphicsConstants.h" class ofRectangle; class ofPath; @@ -21,125 +22,125 @@ class ofSoundBuffer; class ofFbo; class ofBaseVideoDraws; -template +template class ofPixels_; typedef ofPixels_ ofPixels; typedef ofPixels_ ofFloatPixels; typedef ofPixels_ ofShortPixels; -typedef ofPixels& ofPixelsRef; +typedef ofPixels & ofPixelsRef; -template +template class ofImage_; typedef ofImage_ ofImage; typedef ofImage_ ofFloatImage; typedef ofImage_ ofShortImage; -template +template class ofPolyline_; using ofPolyline = ofPolyline_; -template +template class ofMesh_; using ofMesh = ofMesh_; -enum ofFboMode: short; -enum ofLoopType: short; -enum ofOrientation: short; +enum ofFboMode : short; +enum ofLoopType : short; +enum ofOrientation : short; /// \brief Contains general information about the style of ofGraphics /// elements such as color, line width and others. -class ofStyle{ - public: - /// \brief Create a default ofStyle. - ofStyle(){ - bFill = true; - blendingMode = OF_BLENDMODE_ALPHA; - smoothing = false; - circleResolution = 20; - sphereResolution = 20; - curveResolution = 20; - lineWidth = 1.0; - polyMode = OF_POLY_WINDING_ODD; - rectMode = OF_RECTMODE_CORNER; - #ifdef TARGET_OPENGLES - drawBitmapMode = OF_BITMAPMODE_SIMPLE; - #else - drawBitmapMode = OF_BITMAPMODE_MODEL_BILLBOARD; - #endif - bgColor.set(60.f/255.f, 60.f/255.f, 60.f/255.f); - //depthTest = false; - } - - /// \brief Destroy the ofStyle. - virtual ~ofStyle(){} - - /// \brief The color used when rendering. - /// - /// This style depends on the state of the ofStyle::bFill. - ofFloatColor color; - - /// \brief The background color used when rendering. - ofFloatColor bgColor; - - /// \brief The current rendering mode for polygons. - /// - /// ofPolyWindingMode determines how ovelapping parts of the same - /// polygon are rendered. - /// - /// \sa ofPolyWindingMode - ofPolyWindingMode polyMode; - - /// \brief Determine how some shapes are anchored (e.g. ofDrawEllipse). - /// - /// The rectMode applies to several shapes, including ofDrawRectangle - /// and ofDrawEllipse. If the current rectMode is `OF_RECTMODE_CENTER`, - /// the rendered shape will be drawn with x, y in the center of the - /// shape. If the current rectMode is `OF_RECTMODE_CORNER`, the - /// rendered shape will be drawn with the x, y in the upper-left-hand - /// corner of the shape. - ofRectMode rectMode; - - /// \brief True if the renderer should fill a rendered shape. - /// - /// If true, the renderer will fill the rendered shape. If false, the - /// renderer will draw the outline of the rendered shape. - bool bFill; - - /// \brief The render mode for bitmaps (e.g. ofDrawBitmapString). - /// - /// \sa ofDrawBitmapString(const T& textString, float x, float y) - ofDrawBitmapMode drawBitmapMode; - - /// \brief The blending mode. - ofBlendMode blendingMode; - - /// \brief True if anti-aliasing is enabled. - bool smoothing; - - // \brief The resolution of rendered circles and arcs (e.g. ofCircle). - int circleResolution; - - // \brief The resolution of rendered spheres (e.g. ofSphere). - int sphereResolution; - - // \brief The resolution of rendered curves. - int curveResolution; - - /// \brief The width of rendered lines. - /// \warning This is not currently implemented in modern OF renderers. - float lineWidth; - - //bool depthTest; removed since it'll break old projects setting depth test through glEnable +class ofStyle { +public: + /// \brief Create a default ofStyle. + ofStyle() { + bFill = true; + blendingMode = OF_BLENDMODE_ALPHA; + smoothing = false; + circleResolution = 20; + sphereResolution = 20; + curveResolution = 20; + lineWidth = 1.0; + polyMode = OF_POLY_WINDING_ODD; + rectMode = OF_RECTMODE_CORNER; +#ifdef TARGET_OPENGLES + bitmapMode = OF_BITMAPMODE_SIMPLE; +#else + bitmapMode = OF_BITMAPMODE_MODEL_BILLBOARD; +#endif + bgColor.set(60.f / 255.f, 60.f / 255.f, 60.f / 255.f); + //depthTest = false; + } + + /// \brief Destroy the ofStyle. + virtual ~ofStyle() { } + + /// \brief The color used when rendering. + /// + /// This style depends on the state of the ofStyle::bFill. + ofFloatColor color; + + /// \brief The background color used when rendering. + ofFloatColor bgColor; + + /// \brief The current rendering mode for polygons. + /// + /// ofPolyWindingMode determines how ovelapping parts of the same + /// polygon are rendered. + /// + /// \sa ofPolyWindingMode + ofPolyWindingMode polyMode; + + /// \brief Determine how some shapes are anchored (e.g. ofDrawEllipse). + /// + /// The rectMode applies to several shapes, including ofDrawRectangle + /// and ofDrawEllipse. If the current rectMode is `OF_RECTMODE_CENTER`, + /// the rendered shape will be drawn with x, y in the center of the + /// shape. If the current rectMode is `OF_RECTMODE_CORNER`, the + /// rendered shape will be drawn with the x, y in the upper-left-hand + /// corner of the shape. + ofRectMode rectMode; + + /// \brief True if the renderer should fill a rendered shape. + /// + /// If true, the renderer will fill the rendered shape. If false, the + /// renderer will draw the outline of the rendered shape. + bool bFill; + + /// \brief The render mode for bitmaps (e.g. ofDrawBitmapString). + /// + /// \sa ofDrawBitmapString(const T& textString, float x, float y) + ofBitmapMode bitmapMode; + + /// \brief The blending mode. + ofBlendMode blendingMode; + + /// \brief True if anti-aliasing is enabled. + bool smoothing; + + // \brief The resolution of rendered circles and arcs (e.g. ofCircle). + int circleResolution; + + // \brief The resolution of rendered spheres (e.g. ofSphere). + int sphereResolution; + + // \brief The resolution of rendered curves. + int curveResolution; + + /// \brief The width of rendered lines. + /// \warning This is not currently implemented in modern OF renderers. + float lineWidth; + + //bool depthTest; removed since it'll break old projects setting depth test through glEnable }; //---------------------------------------------------------- // ofBaseDraws //---------------------------------------------------------- -class ofBaseDraws{ +class ofBaseDraws { public: /// \brief Destroy the abstract object. - virtual ~ofBaseDraws(){} + virtual ~ofBaseDraws() { } /// \brief Draw at a position at the native size. /// @@ -193,7 +194,7 @@ class ofBaseDraws{ /// /// \param xPct Horizontal position as a percentage (0 - 1). /// \param yPct Vertical position as a percentage (0 - 1). - virtual void setAnchorPercent(float xPct, float yPct){}; + virtual void setAnchorPercent(float xPct, float yPct) {}; /// \brief Set the anchor point the item is drawn around in pixels. /// @@ -202,21 +203,20 @@ class ofBaseDraws{ /// /// \param x Horizontal texture position in pixels. /// \param y Vertical texture position in pixels. - virtual void setAnchorPoint(float x, float y){}; + virtual void setAnchorPoint(float x, float y) {}; /// \brief Reset the anchor point to (0, 0). - virtual void resetAnchor(){}; - + virtual void resetAnchor() {}; }; /// \brief An abstract class representing an object that can be updated. -class ofBaseUpdates{ +class ofBaseUpdates { public: /// \brief Destroy the ofBaseUpdates. - virtual ~ofBaseUpdates(){} + virtual ~ofBaseUpdates() { } /// \brief Update the object's state. - virtual void update()=0; + virtual void update() = 0; }; /// \brief An abstract class representing an object that has pixels. @@ -241,28 +241,27 @@ class ofBaseUpdates{ /// pixelProviders.push_back(&shortPixels); /// /// \endcode -class ofAbstractHasPixels{ +class ofAbstractHasPixels { public: /// \brief Destroy the ofAbstractHasPixels. - virtual ~ofAbstractHasPixels(){} + virtual ~ofAbstractHasPixels() { } }; - /// \brief A base class represeting an object that has pixels. /// \tparam T The pixel data type. -template -class ofBaseHasPixels_: public ofAbstractHasPixels{ +template +class ofBaseHasPixels_ : public ofAbstractHasPixels { public: /// \brief Destroy the ofAbstractHasPixels. - virtual ~ofBaseHasPixels_(){} + virtual ~ofBaseHasPixels_() { } /// \brief Get a reference to the underlying ofPixels. /// \returns a reference the underlying ofPixels. - virtual ofPixels_ & getPixels()=0; + virtual ofPixels_ & getPixels() = 0; /// \brief Get a const reference to the underlying ofPixels. /// \returns a const reference the underlying ofPixels. - virtual const ofPixels_ & getPixels() const=0; + virtual const ofPixels_ & getPixels() const = 0; }; /// \brief A typedef for an unsigned char ofBaseHasPixels_. @@ -274,11 +273,10 @@ typedef ofBaseHasPixels_ ofBaseHasFloatPixels; /// \brief A typedef for an unsigned short ofBaseHasPixels_. typedef ofBaseHasPixels_ ofBaseHasShortPixels; - /// \brief The base renderer interface. -class ofBaseRenderer{ +class ofBaseRenderer { public: - virtual ~ofBaseRenderer(){} + virtual ~ofBaseRenderer() { } /// \brief Get the string representation of the renderer type. /// @@ -286,7 +284,7 @@ class ofBaseRenderer{ /// type depending on the renderer being used. /// /// \returns The string representation of the renderer type. - virtual const std::string & getType()=0; + virtual const std::string & getType() = 0; /// \brief Starts using this renderer as the rendering surface. virtual void startRender() = 0; @@ -295,19 +293,19 @@ class ofBaseRenderer{ /// \brief Draw a polyline with this renderer. /// \param poly The polyline to draw with this renderer. - virtual void draw(const ofPolyline & poly) const=0; + virtual void draw(const ofPolyline & poly) const = 0; /// \brief Draw a path with this renderer. /// \param shape The path to draw with this renderer. - virtual void draw(const ofPath & shape) const=0; + virtual void draw(const ofPath & shape) const = 0; /// \brief Draw a path with this renderer at \p x and \p y. /// \param shape The path to draw with this renderer. /// \param x The x coordinate to use to draw \p shape. /// \param y The y coordinate to use to draw \p shape. - virtual void draw(const ofPath & shape, float x, float y) const{ - const_cast(this)->pushMatrix(); - const_cast(this)->translate(x,y); + virtual void draw(const ofPath & shape, float x, float y) const { + const_cast(this)->pushMatrix(); + const_cast(this)->translate(x, y); draw(shape); - const_cast(this)->popMatrix(); + const_cast(this)->popMatrix(); } /// \brief Draw a \p mesh with this renderer using the \p renderType. /// @@ -338,7 +336,7 @@ class ofBaseRenderer{ /// vertexData. /// \param useNormals True to use normals to draw the \p vertexData. /// \sa ofPolyRenderMode - virtual void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const=0; + virtual void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const = 0; /// \brief Draw a \p model with this renderer using the \p renderType. /// @@ -351,12 +349,12 @@ class ofBaseRenderer{ /// \param renderType The render mode to use when drawing the \p model /// with this renderer. /// \sa ofPolyRenderMode - virtual void draw(const of3dPrimitive& model, ofPolyRenderMode renderType) const=0; + virtual void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const = 0; /// \brief Draw a node with this renderer using ofNode::customDraw(). /// \param model The node to draw with this renderer. /// \sa ofNode::customDraw() - virtual void draw(const ofNode& model) const=0; + virtual void draw(const ofNode & model) const = 0; /// \brief Draw an \p image with this renderer. /// \param image The image to draw with this renderer. @@ -370,7 +368,7 @@ class ofBaseRenderer{ /// \param sy The subsection y axis offset within the image texture. /// \param sw The subsection width offset within the image texture. /// \param sh The subsection height offset within the image texture. - virtual void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const=0; + virtual void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const = 0; /// \brief Draw an \p image with this renderer. /// \param image The image to draw with this renderer. @@ -383,7 +381,7 @@ class ofBaseRenderer{ /// \param sy The subsection y axis offset within the image texture. /// \param sw The subsection width offset within the image texture. /// \param sh The subsection height offset within the image texture. - virtual void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const=0; + virtual void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const = 0; /// \brief Draw an \p image with this renderer. /// \param image The image to draw with this renderer. @@ -396,7 +394,7 @@ class ofBaseRenderer{ /// \param sy The subsection y axis offset within the image texture. /// \param sw The subsection width offset within the image texture. /// \param sh The subsection height offset within the image texture. - virtual void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const=0; + virtual void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const = 0; /// \brief Draw a \p video with this renderer. /// \param video The video with draw with this renderer. @@ -404,7 +402,7 @@ class ofBaseRenderer{ /// \param y The y coordinate to use to draw \p video with this renderer. /// \param w The width to use to draw the video with this renderer. /// \param h The height to use to draw the video with this renderer. - virtual void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const=0; + virtual void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const = 0; //-------------------------------------------- // transformations @@ -415,7 +413,7 @@ class ofBaseRenderer{ /// viewport created by this method. Should be paired with popView. /// /// \sa viewport() - virtual void pushView()=0; + virtual void pushView() = 0; /// \brief Pop the current viewport from the renderer's view stack. /// @@ -423,14 +421,14 @@ class ofBaseRenderer{ /// saved with with a call to pushView(). /// /// \sa viewport() - virtual void popView()=0; + virtual void popView() = 0; /// \brief Set this renderer's viewport using a rectangle. /// /// This method uses the ofGetWidth() and ofGetHeight() to set the width and /// height of the viewport. It also automatically creates near and far /// clipping planes based on this width and height. - virtual void viewport(ofRectangle viewport)=0; + virtual void viewport(ofRectangle viewport) = 0; /// \brief Set this renderer's viewport manually using x, y, width, and /// height. @@ -440,7 +438,7 @@ class ofBaseRenderer{ /// according to the rendering surface's width. /// \param h The height of the viewport. Defaults to -1 setting its height /// according to the rendering surface's height. - virtual void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=true)=0; + virtual void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = true) = 0; /// \brief Setup the renderer to use a perspective matrix. /// \param width The width of the desired perspective matrix. Defaults to -1 @@ -456,7 +454,7 @@ class ofBaseRenderer{ /// \param farDist The far clipping distance to use with the perspective /// matrix. Setting this value to 0 uses the default near distance. Defaults /// to 0. - virtual void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0)=0; + virtual void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0) = 0; /// \brief Setup the renderer to use an orthographic matrix. /// \param width The width of the desired orthographic matrix. Defaults to @@ -469,7 +467,7 @@ class ofBaseRenderer{ /// \param farDist The far clipping distance to use with the orthographic /// matrix. Setting this value to 0 uses the defualt near distance. Defaults /// to 0. - virtual void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1)=0; + virtual void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1) = 0; /// \brief set this renderer's orientation. /// @@ -483,7 +481,7 @@ class ofBaseRenderer{ /// \param orientation The orientation to use with this renderer. /// \param vFlip True if the orientation should be vertically flipped. /// \sa ofOrientation - virtual void setOrientation(ofOrientation orientation, bool vFlip)=0; + virtual void setOrientation(ofOrientation orientation, bool vFlip) = 0; /// \brief Get this renderer's current viewport. /// @@ -492,7 +490,7 @@ class ofBaseRenderer{ /// /// \returns This renderer's viewport as a rectangle. /// \sa getNativeViewport() - virtual ofRectangle getCurrentViewport() const=0; + virtual ofRectangle getCurrentViewport() const = 0; /// \brief Get this renderer's current native viewport. /// @@ -501,20 +499,20 @@ class ofBaseRenderer{ /// /// \returns This renderer's native viewport as a rectangle. /// \sa getViewport() - virtual ofRectangle getNativeViewport() const=0; + virtual ofRectangle getNativeViewport() const = 0; /// \brief Get the renderer's current viewport width. /// \returns The renderer's current viewport width. - virtual int getViewportWidth() const=0; + virtual int getViewportWidth() const = 0; /// \brief Get the renderer's current viewport width. /// \returns The renderer's current viewport width. - virtual int getViewportHeight() const=0; + virtual int getViewportHeight() const = 0; /// \brief Returns true if the renderer's current viewport is vertically /// flipped. /// \returns True if the renderer's current viewport is vertically flipped. - virtual bool isVFlipped() const=0; + virtual bool isVFlipped() const = 0; /// \brief Set the coordinate handidness of this renderer. /// @@ -528,7 +526,7 @@ class ofBaseRenderer{ /// \param handedness The handedness to set this renderer to use. /// \sa http://seanmiddleditch.com/matrices-handedness-pre-and-post-multiplication-row-vs-column-major-and-notations/ /// \sa https://www.evl.uic.edu/ralph/508S98/coordinates.html - virtual void setCoordHandedness(ofHandednessType handedness)=0; + virtual void setCoordHandedness(ofHandednessType handedness) = 0; /// \brief Get the coordinate handidness of this renderer. /// @@ -542,7 +540,7 @@ class ofBaseRenderer{ /// \returns The handedness this renderer is using. /// \sa http://seanmiddleditch.com/matrices-handedness-pre-and-post-multiplication-row-vs-column-major-and-notations/ /// \sa https://www.evl.uic.edu/ralph/508S98/coordinates.html - virtual ofHandednessType getCoordHandedness() const=0; + virtual ofHandednessType getCoordHandedness() const = 0; //our openGL wrappers @@ -552,13 +550,13 @@ class ofBaseRenderer{ /// transformations and scales to effect only the new matrix created by /// this method. Should be paired with a call to popMatrix(). /// - virtual void pushMatrix()=0; + virtual void pushMatrix() = 0; /// \brief Pops this renderer's current matrix stack. /// /// popMatrix() restores the renderer's matrix to the state it was last /// saved with with a call to pushMatrix(). /// - virtual void popMatrix()=0; + virtual void popMatrix() = 0; /// \brief Get this renderer's current matrix for particular a matrix mode. /// @@ -570,11 +568,11 @@ class ofBaseRenderer{ /// \param matrixMode_ The matrix mode to get the current matrix of. /// \returns The current matrix specified by \p matrixMode_ /// \sa ofMatrixMode - virtual glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const=0; + virtual glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const = 0; /// \brief Get this renderer's current orientation matrix. /// \returns This renderer's current orientation matrix. - virtual glm::mat4 getCurrentOrientationMatrix() const=0; + virtual glm::mat4 getCurrentOrientationMatrix() const = 0; /// \brief Translate this renderer's current matrix by x, y, and z. /// \param x The x coordinate to translate this renderer's current matrix @@ -583,11 +581,11 @@ class ofBaseRenderer{ /// by. /// \param z The z coordinate to translate this renderer's current matrix /// by. Defaults to 0. - virtual void translate(float x, float y, float z = 0)=0; + virtual void translate(float x, float y, float z = 0) = 0; /// \brief Translate this renderer's current matrix by a point. /// \param p The 3D point to translate this renderer's current matrix by. - virtual void translate(const glm::vec3 & p)=0; + virtual void translate(const glm::vec3 & p) = 0; /// \brief Scale this renderer's current matrix by xAmnt, yAmnt, and zAmnt. /// \param xAmnt The amount to scale this renderer's current matrix's x @@ -596,7 +594,7 @@ class ofBaseRenderer{ /// axis by. /// \param zAmnt The amount to scale this renderer's current matrix's z /// axis by. Defaults to 1. - virtual void scale(float xAmnt, float yAmnt, float zAmnt = 1)=0; + virtual void scale(float xAmnt, float yAmnt, float zAmnt = 1) = 0; /// \brief Rotate this renderer's current matrix by \p degrees about a euler. /// \param degrees Degrees to rotate about vecX, vecY, and vecZ. @@ -634,22 +632,22 @@ class ofBaseRenderer{ /// \param vecX The x axis to rotate about. /// \param vecY The y axis to rotate about. /// \param vecZ The z axis to rotate about. - virtual void rotateRad(float degrees, float vecX, float vecY, float vecZ)=0; + virtual void rotateRad(float degrees, float vecX, float vecY, float vecZ) = 0; /// \brief Rotate this renderer's current matrix by \p degrees about the x /// axis. /// \param degrees Degrees to rotate about the x axis. - virtual void rotateXRad(float degrees)=0; + virtual void rotateXRad(float degrees) = 0; /// \brief Rotate this renderer's current matrix by \p degrees about the y /// axis. /// \param degrees Degrees to rotate about the y axis. - virtual void rotateYRad(float degrees)=0; + virtual void rotateYRad(float degrees) = 0; /// \brief Rotate this renderer's current matrix by \p degrees about the z /// axis. /// \param degrees Degrees to rotate about the z axis. - virtual void rotateZRad(float degrees)=0; + virtual void rotateZRad(float degrees) = 0; /// \brief Rotate this renderer's current matrix by \p degrees about the z /// axis. @@ -658,7 +656,7 @@ class ofBaseRenderer{ /// /// \param degrees Degrees to rotate about the z axis. /// \sa rotateZ() - virtual void rotateRad(float degrees)=0; + virtual void rotateRad(float degrees) = 0; /// \brief Sets this renderer's current matrix mode. /// @@ -668,7 +666,7 @@ class ofBaseRenderer{ /// OF_MATRIX_TEXTURE /// /// \param mode The matrix mode this renderer's matrix should use. - virtual void matrixMode(ofMatrixMode mode)=0; + virtual void matrixMode(ofMatrixMode mode) = 0; /// \brief Load this renderer's identity matrix. /// @@ -683,22 +681,22 @@ class ofBaseRenderer{ /// /// Matrix multiplications using this matrix as the multiplier will yield no /// change in the multiplicand matrix. - virtual void loadIdentityMatrix (void)=0; + virtual void loadIdentityMatrix(void) = 0; /// \brief Load a matrix as this renderer's current matrix. /// \param m The matrix to load into this renderer. - virtual void loadMatrix (const glm::mat4 & m)=0; + virtual void loadMatrix(const glm::mat4 & m) = 0; /// \brief Load m as this renderer's current matrix. /// /// \p m can be passed to loadMatrix() in this way from raw data /// /// \param m Float pointer to an 4x4 matrix. - virtual void loadMatrix (const float *m)=0; + virtual void loadMatrix(const float * m) = 0; /// \brief Multiply this renderer's current matrix by \p m. /// \param m The matrix to multiply this renderer's current matrix by. - virtual void multMatrix (const glm::mat4 & m)=0; + virtual void multMatrix(const glm::mat4 & m) = 0; /// \brief Multiply this renderer's current matrix by \p m. /// @@ -706,24 +704,23 @@ class ofBaseRenderer{ /// /// \param m Float pointer to an mat4 to multiply this renderer's /// current matrix by. - virtual void multMatrix (const float *m)=0; + virtual void multMatrix(const float * m) = 0; /// \brief Load \p m into this renderer's matrix stack as a view matrix. /// \param m The view matrix to load into this renderer's matrix stack. - virtual void loadViewMatrix(const glm::mat4 & m)=0; + virtual void loadViewMatrix(const glm::mat4 & m) = 0; /// \brief Multiply this renderer's view matrix by \p m. /// \param m The matrix to multiply this renderer's view matrix by. - virtual void multViewMatrix(const glm::mat4 & m)=0; + virtual void multViewMatrix(const glm::mat4 & m) = 0; /// \brief Get this renderer's current view matrix. /// \returns This renderer's current view matrix. - virtual glm::mat4 getCurrentViewMatrix() const=0; + virtual glm::mat4 getCurrentViewMatrix() const = 0; /// \brief Get this renderer's current normal matrix. /// \returns This renderer's current normal matrix. - virtual glm::mat4 getCurrentNormalMatrix() const=0; - + virtual glm::mat4 getCurrentNormalMatrix() const = 0; /// \brief Bind \p camera's matrices to this renderer's matrix stack. /// @@ -734,16 +731,15 @@ class ofBaseRenderer{ /// \param camera The camera to bind to this renderer. /// \param viewport The viewport to use when binding \p camera to this /// renderer. - virtual void bind(const ofCamera & camera, const ofRectangle & viewport)=0; + virtual void bind(const ofCamera & camera, const ofRectangle & viewport) = 0; /// \brief Unbind the camera from this renderer. /// \param camera The camera to unbind from this renderer. - virtual void unbind(const ofCamera & camera)=0; - + virtual void unbind(const ofCamera & camera) = 0; /// \brief setup the default graphics settings for this renderer. - virtual void setupGraphicDefaults()=0; + virtual void setupGraphicDefaults() = 0; /// \brief setup the default screen settings for this renderer. - virtual void setupScreen()=0; + virtual void setupScreen() = 0; // drawing modes /// \brief Set this renderer's rect mode. @@ -752,31 +748,31 @@ class ofBaseRenderer{ /// /// \param mode The rect mode to request this renderer to use. /// \sa ofRectMode - virtual void setRectMode(ofRectMode mode)=0; + virtual void setRectMode(ofRectMode mode) = 0; /// \brief Get this renderer's current rect mode. /// /// Possible rect modes include OF_RECTMODE_CORNER and OF_RECTMODE_CENTER. /// /// \returns The renderer's current rect mode. /// \sa ofRectMode - virtual ofRectMode getRectMode()=0; + virtual ofRectMode getRectMode() = 0; /// \brief set this renderer's fill flag. /// /// Possible fill flags include OF_OUTLINE and OF_FILLED. /// /// \param fill The fill flag to request this renderer to use. /// \sa ofFillFlag - virtual void setFillMode(ofFillFlag fill)=0; + virtual void setFillMode(ofFillFlag fill) = 0; /// \brief Get this renderer's current fill flag. /// /// Possible fill flags include OF_OUTLINE and OF_FILLED. /// /// \returns The fill flag this render is currently using. /// \sa ofFillFlag - virtual ofFillFlag getFillMode()=0; + virtual ofFillFlag getFillMode() = 0; /// \brief Set the line width this renderer should use when drawing lines. /// \param lineWidth The line width to request this renderer to use. - virtual void setLineWidth(float lineWidth)=0; + virtual void setLineWidth(float lineWidth) = 0; /// \brief Enable/disable depth testing with this renderer. /// /// When depth testing is enabled the order shapes are drawn with the @@ -785,7 +781,7 @@ class ofBaseRenderer{ /// expecting normal behavior when drawing 3D scenes. /// /// \param depthTest True to enable depth testing. - virtual void setDepthTest(bool depthTest)=0; + virtual void setDepthTest(bool depthTest) = 0; /// \brief Set this renderer's current blend mode. /// /// Possible blend modes include: @@ -806,20 +802,20 @@ class ofBaseRenderer{ /// \param blendMode The blend mode to request this renderer to use. /// \sa ofBlendMode /// \sa https://helpx.adobe.com/photoshop/using/blending-modes.html - virtual void setBlendMode(ofBlendMode blendMode)=0; + virtual void setBlendMode(ofBlendMode blendMode) = 0; /// \brief Enable/disable line smoothing for this renderer if it's supported. /// \param smooth True to enable line smoothing for this renderer if it's /// supported. - virtual void setLineSmoothing(bool smooth)=0; + virtual void setLineSmoothing(bool smooth) = 0; /// \brief Set the resolution to use when drawing ellipses with this /// renderer. /// \param res The number of points to use when drawing circles and ellipses /// with this renderer. - virtual void setCircleResolution(int res)=0; + virtual void setCircleResolution(int res) = 0; /// \brief Enable this renderer to use anti-aliasing if it is supported. - virtual void enableAntiAliasing()=0; + virtual void enableAntiAliasing() = 0; /// \brief Disable this renderer from using anti-aliasing. - virtual void disableAntiAliasing()=0; + virtual void disableAntiAliasing() = 0; /// \brief Set the global color this renderer will use when drawing. /// @@ -829,7 +825,7 @@ class ofBaseRenderer{ /// \param r The red value between 0 and 1 to use when drawing. /// \param g The green value between 0 and 1 to use when drawing. /// \param b The blue value between 0 and 1 to use when drawing. - virtual void setColor(float r, float g, float b)=0; + virtual void setColor(float r, float g, float b) = 0; /// \brief Set the global color this renderer will use when drawing. /// /// The renderer will continue using a color set by setColor() until another @@ -839,14 +835,14 @@ class ofBaseRenderer{ /// \param g The green value between 0 and 1 to use when drawing. /// \param b The blue value between 0 and 1 to use when drawing. /// \param a The alpha value between 0 and 1 to use when drawing. - virtual void setColor(float r, float g, float b, float a)=0; + virtual void setColor(float r, float g, float b, float a) = 0; /// \brief Set the global color this renderer will use when drawing. /// /// The renderer will continue using a color set by setColor() until another /// call to setColor() changes the drawing color. /// /// \param color The color to use when drawing. - virtual void setColor(const ofFloatColor & color)=0; + virtual void setColor(const ofFloatColor & color) = 0; /// \brief Set the global color this renderer will use when drawing. /// /// The renderer will continue using a color set by setColor() until another @@ -854,14 +850,14 @@ class ofBaseRenderer{ /// /// \param color The color to use when drawing. /// \param _a The alpha value between 0 and 1 to use when drawing. - virtual void setColor(const ofFloatColor & color, float _a)=0; + virtual void setColor(const ofFloatColor & color, float _a) = 0; /// \brief Set the global color this renderer will use when drawing. /// /// The renderer will continue using a color set by setColor() until another /// call to setColor() changes the drawing color. /// /// \param gray The grayscale value from 0 and 1 to use when drawing. - virtual void setColor(float gray)=0; + virtual void setColor(float gray) = 0; /// \brief Set the global color this renderer will use when drawing. /// /// The renderer will continue using a color set by setColor() until another @@ -869,7 +865,7 @@ class ofBaseRenderer{ /// /// \param hexColor The hexidecimal representation of the color to use when /// drawing. - virtual void setHexColor( int hexColor )=0; + virtual void setHexColor(int hexColor) = 0; /// \brief Set this renderer's bitmap text mode. /// @@ -881,15 +877,15 @@ class ofBaseRenderer{ /// OF_BITMAPMODE_MODEL_BILLBOARD /// /// \param mode The bitmap mode to request this renderer to use. - /// \sa ofDrawBitmapMode - virtual void setBitmapTextMode(ofDrawBitmapMode mode)=0; + /// \sa ofBitmapMode + virtual void setBitmapTextMode(ofBitmapMode mode) = 0; /// \brief Get this renderer's current background color. /// \returns This renderer's current background color. - virtual ofFloatColor getBackgroundColor()=0; + virtual ofFloatColor getBackgroundColor() = 0; /// \brief Set this renderer's background color. /// \param c The color to request this renderer to use. - virtual void setBackgroundColor(const ofFloatColor & c)=0; + virtual void setBackgroundColor(const ofFloatColor & c) = 0; /// \brief Immediately paint a background color to the screen. /// @@ -898,7 +894,7 @@ class ofBaseRenderer{ /// this color each frame. /// /// \param c The color to paint the background with. - virtual void background(const ofFloatColor & c)=0; + virtual void background(const ofFloatColor & c) = 0; /// \brief Immediately paint a grayscale background color to the screen. /// /// If automatic background drawing is enabled (which it is by default) this @@ -907,7 +903,7 @@ class ofBaseRenderer{ /// /// \param brightness The grayscale value between 0 and 1 to paint the /// background with. - virtual void background(float brightness)=0; + virtual void background(float brightness) = 0; /// \brief Immediately paint a grayscale background color to the screen. /// /// If automatic background drawing is enabled (which it is by default) this @@ -918,28 +914,28 @@ class ofBaseRenderer{ /// background with. /// \param _a The alpha value between 0 and 255 to apply to \p hexColor when /// when painting the background. - virtual void background(int hexColor, int _a=255)=0; + virtual void background(int hexColor, int _a = 255) = 0; /// \brief Immediately paint a background color to the screen. /// /// \param r The red value between 0 and 1 to use for the background. /// \param g The green value between 0 and 1 to use for the background. /// \param b The blue value between 0 and 1 to use for the background. /// \param a The alpha value between 0 and 1 to use for the background. - virtual void background(float r, float g, float b, float a=1.f)=0; + virtual void background(float r, float g, float b, float a = 1.f) = 0; /// \brief Enable/disable automatic redrawing of the background each frame. /// \param bManual False to disable automatic background redrawing. - virtual void setBackgroundAuto(bool bManual)=0; + virtual void setBackgroundAuto(bool bManual) = 0; /// \brief Get the current auto redraw background setting for this renderer. /// \returns True if this renderer is set to redraw the background each /// frame. - virtual bool getBackgroundAuto()=0; + virtual bool getBackgroundAuto() = 0; /// \brief Clear this renderer's current color and bit depths. /// /// clear() will clear the screen entirely. /// - virtual void clear()=0; + virtual void clear() = 0; /// \brief Clear this renderer's color and bit depths and replace them. /// /// clear() will clear the screen entirely. @@ -951,7 +947,7 @@ class ofBaseRenderer{ /// \param b The blue value between 0 and 1 use when clearing the screen. /// \param a The alpha value between 0 and 1 use when clearing the screen. /// Defaults to 0. - virtual void clear(float r, float g, float b, float a=0)=0; + virtual void clear(float r, float g, float b, float a = 0) = 0; /// \brief Clear this renderer's color and bit depths replacing them. /// /// clear() will clear the screen entirely. @@ -960,9 +956,9 @@ class ofBaseRenderer{ /// clearing the screen. /// \param a The alpha value between 0 and 1 to use when clearing the /// screen. Defaults to 0. - virtual void clear(float brightness, float a=0)=0; + virtual void clear(float brightness, float a = 0) = 0; /// \brief Restore the alpha color to its full opacity value. - virtual void clearAlpha()=0; + virtual void clearAlpha() = 0; /// \brief Draw a line between two 3D points. /// \param x1 The x coordinate of the first point. @@ -971,7 +967,7 @@ class ofBaseRenderer{ /// \param x2 The x coordinate of the second point. /// \param y2 The y coordinate of the second point. /// \param z2 The z coordinate of the second point. - virtual void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const=0; + virtual void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const = 0; /// \brief Draw a rectangle using a 3D point and a width and height. /// \param x The x coordinate of the rectangle. /// \param y The y coordinate of the rectangle. @@ -979,7 +975,7 @@ class ofBaseRenderer{ /// \param w The width of the rectangle. /// \param h The height of the rectangle. /// \sa ofRectMode - virtual void drawRectangle(float x, float y, float z, float w, float h) const=0; + virtual void drawRectangle(float x, float y, float z, float w, float h) const = 0; /// \brief Draw a triangle using three 3D points. /// \param x1 The x coordinate of the first point. /// \param y1 The y coordinate of the first point. @@ -990,20 +986,20 @@ class ofBaseRenderer{ /// \param x3 The x coordinate of the third point. /// \param y3 The y coordinate of the third point. /// \param z3 The z coordinate of the third point. - virtual void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const=0; + virtual void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const = 0; /// \brief Draw a circle using a 3D point and a radius. /// \param x The x coordinate of the center of the circle. /// \param y The y coordinate of the center of the circle. /// \param z The z coordinate of the center of the circle. /// \param radius The length of the radius of the circle. - virtual void drawCircle(float x, float y, float z, float radius) const=0; + virtual void drawCircle(float x, float y, float z, float radius) const = 0; /// \brief Draw an ellipse using a 3D point, width, and height. /// \param x The x coordinate of the center of the circle. /// \param y The y coordinate of the center of the circle. /// \param z The z coordinate of the center of the circle. /// \param width The width of the circle. /// \param height The height of the circle. - virtual void drawEllipse(float x, float y, float z, float width, float height) const=0; + virtual void drawEllipse(float x, float y, float z, float width, float height) const = 0; /// \brief Draw text with this renderer using the current bitmap text mode. /// /// When using the OF_BITMAPMODE_SIMPLE bitmap text strings are drawn with @@ -1019,25 +1015,24 @@ class ofBaseRenderer{ /// \param x The x position for the bottom of \p text. /// \param y The y position for the left alignment of \p text. /// \param z The z position of the text. - virtual void drawString(std::string text, float x, float y, float z) const=0; + virtual void drawString(std::string text, float x, float y, float z) const = 0; /// \brief Draw text with this renderer using an ofTrueType font. /// \param font The font to use when drawing \p text. /// \param text The text to draw with the renderer. /// \param x The x position for the bottom of \p text. /// \param y The y position for the left alignment of \p text. - virtual void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const=0; - + virtual void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const = 0; // returns true an ofPath to draw with, this allows to keep // immediate mode rendering working in multiwindow with multiple // contexts without reimplementing the logic on every renderer /// \brief Get a reference to the path used internally by this renderer. /// \returns A reference to the path used internally by this renderer. - virtual ofPath & getPath()=0; + virtual ofPath & getPath() = 0; /// \brief Get this renderer's current style object. /// \returns This renderer's current style object. - virtual ofStyle getStyle() const=0; + virtual ofStyle getStyle() const = 0; /// \brief Set this renderer's current style object. /// \param style The style object to set this renderer to use. virtual void setStyle(const ofStyle & style) = 0; @@ -1046,17 +1041,17 @@ class ofBaseRenderer{ /// This creates a new style object used by this renderer internally until /// popStyle() is called. /// - virtual void pushStyle()=0; + virtual void pushStyle() = 0; /// \brief Pop this renderer's current style from its internal style stack. /// /// This restores the style that was last saved with pushStyle(). /// - virtual void popStyle()=0; + virtual void popStyle() = 0; /// \brief Set the resolution used when drawing curves with this renderer. /// \param resolution The resolution to request this renderer to use when /// drawing curves. - virtual void setCurveResolution(int resolution)=0; + virtual void setCurveResolution(int resolution) = 0; /// \brief Set this renderer's poly winding mode. /// @@ -1069,22 +1064,21 @@ class ofBaseRenderer{ /// /// \param mode The poly winding mode to request this renderer to use. /// \sa ofPolyWindingMode - virtual void setPolyMode(ofPolyWindingMode mode)=0; + virtual void setPolyMode(ofPolyWindingMode mode) = 0; /// \brief Get a const reference of this renderer's 3D graphics object. /// \returns The 3D graphics object currently being used by this renderer. - virtual const of3dGraphics & get3dGraphics() const=0; + virtual const of3dGraphics & get3dGraphics() const = 0; /// \brief Get a reference with this renderer's 3D graphics object. /// \returns the 3D graphics object currently being used by this renderer. - virtual of3dGraphics & get3dGraphics()=0; - + virtual of3dGraphics & get3dGraphics() = 0; /// \brief Set this renderer's plane resolution using \p column and \p rows. /// \param columns The number of columns to use when drawing planes with /// this renderer. /// \param rows The number of rows to use when drawing planes with this /// renderer. - virtual void setPlaneResolution( int columns, int rows ); + virtual void setPlaneResolution(int columns, int rows); /// \brief Get this renderer's current plane resolution as a 2D vector. /// /// The resulting vector's x and y values corresponds to the current column @@ -1131,7 +1125,7 @@ class ofBaseRenderer{ /// \param width The width to use when drawing the plane with this renderer. /// \param height The height to use when drawing the plane with this /// renderer. - virtual void drawPlane(const glm::vec3& position, float width, float height) const; + virtual void drawPlane(const glm::vec3 & position, float width, float height) const; /// \brief Draw a plane with the renderer at the origin. /// /// The number of rows and columns this plane will have is dependent on this @@ -1141,7 +1135,7 @@ class ofBaseRenderer{ /// this renderer. /// \param height The height to use when drawing the plane with this /// renderer. - virtual void drawPlane( float width, float height ) const; + virtual void drawPlane(float width, float height) const; /// UV Sphere /// \brief Set the point resolution to use when drawing a sphere with this @@ -1178,7 +1172,7 @@ class ofBaseRenderer{ /// /// \param position The 3D position point to use when drawing the sphere. /// \param radius The radius to use when drawing this sphere. - virtual void drawSphere(const glm::vec3& position, float radius) const; + virtual void drawSphere(const glm::vec3 & position, float radius) const; /// \brief Draw a sphere with the renderer at the defualt origin using /// radius. /// \param radius The radius to use when drawing the sphere with this @@ -1189,7 +1183,7 @@ class ofBaseRenderer{ /// \brief Set the point resolution to use when drawing an icosphere with /// this renderer. /// \param res The desired icosphere resolution to use with this renderer. - virtual void setIcoSphereResolution( int res ); + virtual void setIcoSphereResolution(int res); /// \brief Get this renderer's current icosphere resolution. /// \returns This renderer's current icosphere resolution. virtual int getIcoSphereResolution() const; @@ -1219,7 +1213,7 @@ class ofBaseRenderer{ /// /// \param position The 3D position point to use when drawing the icosphere. /// \param radius The radius to use when drawing this icosphere. - virtual void drawIcoSphere(const glm::vec3& position, float radius) const; + virtual void drawIcoSphere(const glm::vec3 & position, float radius) const; /// \brief Draw an icosphere with the renderer at the origin using radius. /// \param radius The radius to use when drawing the icosphere with this /// renderer. @@ -1233,7 +1227,7 @@ class ofBaseRenderer{ /// to bottom. /// \param capSegments The number of annular (ring-shaped) subdivisions of /// the cylinder's endcap. Defaults to 2. - virtual void setCylinderResolution( int radiusSegments, int heightSegments, int capSegments=2 ); + virtual void setCylinderResolution(int radiusSegments, int heightSegments, int capSegments = 2); /// \brief Get this renderer's cylinder resolution as a 3D vector. /// /// The resulting vector's x, y, and z properties correspond to the radius @@ -1283,7 +1277,7 @@ class ofBaseRenderer{ /// \param radius The radius to use when drawing this cylinder's circular /// footprint. /// \param height The height to use when drawing this cylinder. - virtual void drawCylinder(const glm::vec3& position, float radius, float height) const; + virtual void drawCylinder(const glm::vec3 & position, float radius, float height) const; /// \brief Draw a cylinder at the origin using radius and height. /// /// A cylinder drawn in this way will be positioned at the origin. Radius is @@ -1306,7 +1300,7 @@ class ofBaseRenderer{ /// bottom. /// \param capSegments The number of annular (ring-shaped) subdivisions of /// the cone's endcap. - virtual void setConeResolution( int radiusSegments, int heightSegments, int capSegments=2); + virtual void setConeResolution(int radiusSegments, int heightSegments, int capSegments = 2); /// \brief Get this renderer's cone resolution as a 3D vector. /// @@ -1356,7 +1350,7 @@ class ofBaseRenderer{ /// \param radius The radius to use when drawing this cone's circular /// footprint. /// \param height The height to use when drawing this cone. - virtual void drawCone(const glm::vec3& position, float radius, float height) const; + virtual void drawCone(const glm::vec3 & position, float radius, float height) const; /// \brief Draw a cone at the origin using radius and height. /// /// This cone will be drawn with its position at the coordinate system's @@ -1371,7 +1365,7 @@ class ofBaseRenderer{ // Box /// \brief Set the resolution this renderer uses when drawing boxes. /// \param res The resolution to use for box widths, heights, and depths. - virtual void setBoxResolution( int res ); + virtual void setBoxResolution(int res); /// \brief Set the resolution this renderer uses when drawing boxes. /// \param resWidth The width resolution this renderer uses when drawing /// boxes. @@ -1379,7 +1373,7 @@ class ofBaseRenderer{ /// boxes. /// \param resDepth The depth resolution this renderer uses when drawing /// boxes. - virtual void setBoxResolution( int resWidth, int resHeight, int resDepth ); + virtual void setBoxResolution(int resWidth, int resHeight, int resDepth); /// \brief Get this renderer's current box resolution as a 3D vector. /// /// The returned vector's x, y, and z properties represent this renderer's @@ -1403,7 +1397,7 @@ class ofBaseRenderer{ /// \param width The width of the box. /// \param height The height of the box. /// \param depth The depth of the box. - virtual void drawBox( float x, float y, float z, float width, float height, float depth) const; + virtual void drawBox(float x, float y, float z, float width, float height, float depth) const; /// \brief Draws a cube using x, y, z, and size. /// coordinates. @@ -1436,7 +1430,7 @@ class ofBaseRenderer{ /// \param width The width of the box. /// \param height The height of the box. /// \param depth The depth of the box. - virtual void drawBox(const glm::vec3& position, float width, float height, float depth) const; + virtual void drawBox(const glm::vec3 & position, float width, float height, float depth) const; /// \brief Draws a cube with the specified size, starting from the specified /// position. @@ -1449,7 +1443,7 @@ class ofBaseRenderer{ /// \param position an glm::vec3 which contains the (x,y,z) coordinates for /// the cube's reference corner. /// \param size The size of the cube. - virtual void drawBox(const glm::vec3& position, float size) const; + virtual void drawBox(const glm::vec3 & position, float size) const; /// \brief Draws a cube with the specified size at the origin. /// @@ -1470,7 +1464,7 @@ class ofBaseRenderer{ /// \param width The width of the box. /// \param height The height of the box. /// \param depth The depth of the box. - virtual void drawBox( float width, float height, float depth ) const; + virtual void drawBox(float width, float height, float depth) const; /// \brief Draw the coordinate system's axes with the renderer. /// /// This draws a red, green, and blue lines for the x, y, and z axes @@ -1497,7 +1491,7 @@ class ofBaseRenderer{ /// \brief start The 3D vector to use as the first point. /// \brief end The 3D vector to use as the second point. /// \float headSize The size of the arrowhead. - virtual void drawArrow(const glm::vec3& start, const glm::vec3& end, float headSize) const; + virtual void drawArrow(const glm::vec3 & start, const glm::vec3 & end, float headSize) const; /// \brief Draw the coordinate system's axes with the renderer. /// /// This draws red, green, and blue lines for the x, y, and z rotation diff --git a/libs/openFrameworks/graphics/ofGraphicsConstants.h b/libs/openFrameworks/graphics/ofGraphicsConstants.h index c884bde3e07..3c31001f49f 100644 --- a/libs/openFrameworks/graphics/ofGraphicsConstants.h +++ b/libs/openFrameworks/graphics/ofGraphicsConstants.h @@ -2,7 +2,7 @@ #include "ofMathConstants.h" -template +template class ofColor_; typedef ofColor_ ofFloatColor; using ofDefaultVertexType = ofDefaultVec3; @@ -10,14 +10,13 @@ using ofDefaultNormalType = ofDefaultVec3; using ofDefaultColorType = ofFloatColor; using ofDefaultTexCoordType = ofDefaultVec2; -enum ofPolyRenderMode{ +enum ofPolyRenderMode { OF_MESH_POINTS, OF_MESH_WIREFRAME, OF_MESH_FILL }; - -enum ofPrimitiveMode{ +enum ofPrimitiveMode { OF_PRIMITIVE_TRIANGLES, OF_PRIMITIVE_TRIANGLE_STRIP, OF_PRIMITIVE_TRIANGLE_FAN, @@ -34,42 +33,40 @@ enum ofPrimitiveMode{ #endif }; - /// \brief Used to represent the available fill modes. /// /// \sa ofBaseRenderer -enum ofFillFlag{ +enum ofFillFlag { /// \brief Draw shapes as outlines, unfilled. - OF_OUTLINE= 0, + OF_OUTLINE = 0, /// \brief Draw shapes filled with the current draw color. OF_FILLED = 1, }; -#define OF_MAX_STYLE_HISTORY 32 +#define OF_MAX_STYLE_HISTORY 32 /// \deprecated Not currently used in the OF codebase. -#define OF_MAX_VIEWPORT_HISTORY 32 +#define OF_MAX_VIEWPORT_HISTORY 32 /// \deprecated Not currently used in the OF codebase. -#define OF_MAX_CIRCLE_PTS 1024 +#define OF_MAX_CIRCLE_PTS 1024 /// \brief Used to represent the available blending modes for drawing. -enum ofBlendMode{ +enum ofBlendMode { /// \brief Blend mode is disabled. OF_BLENDMODE_DISABLED = 0, /// \brief Blend mode used for alpha blending. - OF_BLENDMODE_ALPHA = 1, + OF_BLENDMODE_ALPHA = 1, /// \brief Blend mode used for additive blending. - OF_BLENDMODE_ADD = 2, + OF_BLENDMODE_ADD = 2, /// \brief Blend mode used for subtractive blending. OF_BLENDMODE_SUBTRACT = 3, /// \brief Blend mode used for multiplicative blending. OF_BLENDMODE_MULTIPLY = 4, /// \brief Blend mode used for screen blending. - OF_BLENDMODE_SCREEN = 5 + OF_BLENDMODE_SCREEN = 5 }; - /// \brief Represents the gradient types available to ofBackgroundGradient(). enum ofGradientMode { /// \brief Represents a top-to-bottom linear gradient. @@ -94,15 +91,15 @@ enum ofGradientMode { /// \sa ofTessellator::performTessellation() /// \sa http://glprogramming.com/red/images/Image128.gif /// \sa http://glprogramming.com/red/chapter11.html -enum ofPolyWindingMode{ +enum ofPolyWindingMode { /// \brief Fill odd winding numbers. - OF_POLY_WINDING_ODD , + OF_POLY_WINDING_ODD, /// \brief Fill all non-zero winding numbers. - OF_POLY_WINDING_NONZERO , + OF_POLY_WINDING_NONZERO, /// \brief Fill all winding numbers greater than zero. - OF_POLY_WINDING_POSITIVE , + OF_POLY_WINDING_POSITIVE, /// \brief Fill all winding numbers less than zero. - OF_POLY_WINDING_NEGATIVE , + OF_POLY_WINDING_NEGATIVE, /// \brief Fill all winding numbers greater than 1 or less than -1. /// /// This stands for "Fill ABSolute values Greater than EQual to TWO". @@ -113,16 +110,17 @@ enum ofPolyWindingMode{ /// /// \sa ofMatrixStack /// \sa http://seanmiddleditch.com/matrices-handedness-pre-and-post-multiplication-row-vs-column-major-and-notations/ -enum ofHandednessType {OF_LEFT_HANDED, OF_RIGHT_HANDED}; +enum ofHandednessType { OF_LEFT_HANDED, + OF_RIGHT_HANDED }; /// \brief represents the available matrix types used internally in ::ofMatrixStack. -enum ofMatrixMode {OF_MATRIX_MODELVIEW=0, OF_MATRIX_PROJECTION, OF_MATRIX_TEXTURE}; - - +enum ofMatrixMode { OF_MATRIX_MODELVIEW = 0, + OF_MATRIX_PROJECTION, + OF_MATRIX_TEXTURE }; /// \brief Sets the bitmap drawing mode for text. -/// \sa ofSetDrawBitmapMode() -enum ofDrawBitmapMode{ +/// \sa ofSetBitmapMode() +enum ofBitmapMode { OF_BITMAPMODE_SIMPLE = 0, OF_BITMAPMODE_SCREEN, OF_BITMAPMODE_VIEWPORT, @@ -130,20 +128,18 @@ enum ofDrawBitmapMode{ OF_BITMAPMODE_MODEL_BILLBOARD }; - /// \brief Used to represent the available rectangle drawing modes. /// /// \sa ofRectangle /// \sa ofTexture /// \sa ofImage -enum ofRectMode{ +enum ofRectMode { /// \brief Represents the mode where rectangles draw from the top left. - OF_RECTMODE_CORNER=0, + OF_RECTMODE_CORNER = 0, /// \brief Represents the mode where rectangles draw from the center. - OF_RECTMODE_CENTER=1 + OF_RECTMODE_CENTER = 1 }; - /// \brief Used to represent the available channel types in ofImage. /// /// These represent an abstraction of both CPU pixels (ofPixels) and GPU pixels @@ -151,21 +147,21 @@ enum ofRectMode{ /// ::ofImageType for a more precise description of channel types. /// /// \sa ofImage -enum ofImageType: short{ +enum ofImageType : short { /// \brief A single channel (or monochrome) image. /// /// \sa OF_PIXELS_GRAY - OF_IMAGE_GRAYSCALE = 0x00, + OF_IMAGE_GRAYSCALE = 0x00, /// \brief A three channel (or RGB) image. /// /// \sa OF_PIXELS_RGB - OF_IMAGE_COLOR = 0x01, + OF_IMAGE_COLOR = 0x01, /// \brief A four channel (or RGBA) image. /// /// \sa OF_PIXELS_RGBA - OF_IMAGE_COLOR_ALPHA = 0x02, + OF_IMAGE_COLOR_ALPHA = 0x02, /// \brief An unknown and unsupported image type. /// /// \sa OF_PIXELS_UNKNOWN - OF_IMAGE_UNDEFINED = 0x03 + OF_IMAGE_UNDEFINED = 0x03 }; diff --git a/libs/openFrameworks/graphics/ofRendererCollection.cpp b/libs/openFrameworks/graphics/ofRendererCollection.cpp index 1c82f9287a5..ccf16051630 100644 --- a/libs/openFrameworks/graphics/ofRendererCollection.cpp +++ b/libs/openFrameworks/graphics/ofRendererCollection.cpp @@ -5,90 +5,90 @@ * Author: arturo */ -#include "ofRendererCollection.h" -#include "ofGLRenderer.h" #include "ofGLProgrammableRenderer.h" +#include "ofGLRenderer.h" +#include "ofRendererCollection.h" -const std::string ofRendererCollection::TYPE="collection"; +const std::string ofRendererCollection::TYPE = "collection"; -std::shared_ptr ofRendererCollection::getGLRenderer(){ - for(auto renderer: renderers){ - if(renderer->getType()=="GL" || renderer->getType()=="ProgrammableGL"){ - return std::dynamic_pointer_cast(renderer); - } - } - #ifndef TARGET_PROGRAMMABLE_GL - return std::shared_ptr(); - #else - return std::shared_ptr(); - #endif +std::shared_ptr ofRendererCollection::getGLRenderer() { + for (auto renderer : renderers) { + if (renderer->getType() == "GL" || renderer->getType() == "ProgrammableGL") { + return std::dynamic_pointer_cast(renderer); + } + } +#ifndef TARGET_PROGRAMMABLE_GL + return std::shared_ptr(); +#else + return std::shared_ptr(); +#endif } -bool ofRendererCollection::rendersPathPrimitives(){return true;} +bool ofRendererCollection::rendersPathPrimitives() { return true; } -void ofRendererCollection::startRender(){ - for(auto renderer: renderers){ +void ofRendererCollection::startRender() { + for (auto renderer : renderers) { renderer->startRender(); } } -void ofRendererCollection::finishRender(){ - for(auto renderer: renderers){ +void ofRendererCollection::finishRender() { + for (auto renderer : renderers) { renderer->finishRender(); } } -void ofRendererCollection::draw(const ofPolyline & poly) const{ - for(auto renderer: renderers){ +void ofRendererCollection::draw(const ofPolyline & poly) const { + for (auto renderer : renderers) { renderer->draw(poly); } } -void ofRendererCollection::draw(const ofPath & shape) const{ - for(auto renderer: renderers){ +void ofRendererCollection::draw(const ofPath & shape) const { + for (auto renderer : renderers) { renderer->draw(shape); } } -void ofRendererCollection::draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const{ - for(auto renderer: renderers){ - renderer->draw(vertexData,mode,useColors,useTextures,useNormals); +void ofRendererCollection::draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const { + for (auto renderer : renderers) { + renderer->draw(vertexData, mode, useColors, useTextures, useNormals); } } -void ofRendererCollection::draw(const of3dPrimitive& model, ofPolyRenderMode renderType ) const { - for(auto renderer: renderers){ - renderer->draw( model, renderType ); - } +void ofRendererCollection::draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const { + for (auto renderer : renderers) { + renderer->draw(model, renderType); + } } -void ofRendererCollection::draw(const ofNode& node) const { - for(auto renderer: renderers){ - renderer->draw( node ); - } +void ofRendererCollection::draw(const ofNode & node) const { + for (auto renderer : renderers) { + renderer->draw(node); + } } -void ofRendererCollection::draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - for(auto renderer: renderers){ - renderer->draw(img,x,y,z,w,h,sx,sy,sw,sh); +void ofRendererCollection::draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + for (auto renderer : renderers) { + renderer->draw(img, x, y, z, w, h, sx, sy, sw, sh); } } -void ofRendererCollection::draw(const ofFloatImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - for(auto renderer: renderers){ - renderer->draw(img,x,y,z,w,h,sx,sy,sw,sh); - } +void ofRendererCollection::draw(const ofFloatImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + for (auto renderer : renderers) { + renderer->draw(img, x, y, z, w, h, sx, sy, sw, sh); + } } -void ofRendererCollection::draw(const ofShortImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ - for(auto renderer: renderers){ - renderer->draw(img,x,y,z,w,h,sx,sy,sw,sh); - } +void ofRendererCollection::draw(const ofShortImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const { + for (auto renderer : renderers) { + renderer->draw(img, x, y, z, w, h, sx, sy, sw, sh); + } } -void ofRendererCollection::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{ - for(auto renderer: renderers){ - renderer->draw(video,x,y,w,h); - } +void ofRendererCollection::draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const { + for (auto renderer : renderers) { + renderer->draw(video, x, y, w, h); + } } /*void bind(const ofBaseVideoDraws & video) const{ @@ -103,46 +103,43 @@ void unbind(const ofBaseVideoDraws & video) const{ } }*/ - -glm::mat4 ofRendererCollection::getCurrentMatrix(ofMatrixMode matrixMode_) const{ - if (!renderers.empty()) { - return renderers.front()->getCurrentMatrix(matrixMode_); - } else { - ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; - return glm::mat4(1.0f); - } +glm::mat4 ofRendererCollection::getCurrentMatrix(ofMatrixMode matrixMode_) const { + if (!renderers.empty()) { + return renderers.front()->getCurrentMatrix(matrixMode_); + } else { + ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; + return glm::mat4(1.0f); + } } - -glm::mat4 ofRendererCollection::getCurrentOrientationMatrix() const{ - if (!renderers.empty()) { - return renderers.front()->getCurrentOrientationMatrix(); - } else { - ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; - return glm::mat4(1.0f); - } +glm::mat4 ofRendererCollection::getCurrentOrientationMatrix() const { + if (!renderers.empty()) { + return renderers.front()->getCurrentOrientationMatrix(); + } else { + ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; + return glm::mat4(1.0f); + } } - -glm::mat4 ofRendererCollection::getCurrentNormalMatrix() const{ - if (!renderers.empty()) { - return renderers.front()->getCurrentNormalMatrix(); - } else { - ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; - return glm::mat4(1.0f); - } +glm::mat4 ofRendererCollection::getCurrentNormalMatrix() const { + if (!renderers.empty()) { + return renderers.front()->getCurrentNormalMatrix(); + } else { + ofLogWarning() << "No renderer in renderer collection, but current matrix requested. Returning identity matrix."; + return glm::mat4(1.0f); + } } //-------------------------------------------- // transformations -void ofRendererCollection::pushView(){ - for(auto renderer: renderers){ +void ofRendererCollection::pushView() { + for (auto renderer : renderers) { renderer->pushView(); } } -void ofRendererCollection::popView(){ - for(auto renderer: renderers){ +void ofRendererCollection::popView() { + for (auto renderer : renderers) { renderer->popView(); } } @@ -150,556 +147,555 @@ void ofRendererCollection::popView(){ // setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) -void ofRendererCollection::viewport(ofRectangle viewport){ - for(auto renderer: renderers){ - renderer->viewport(viewport); +void ofRendererCollection::viewport(ofRectangle viewport) { + for (auto renderer : renderers) { + renderer->viewport(viewport); } } -void ofRendererCollection::viewport(float x, float y, float width, float height, bool vflip){ - for(auto renderer: renderers){ - renderer->viewport(x,y,width,height,vflip); +void ofRendererCollection::viewport(float x, float y, float width, float height, bool vflip) { + for (auto renderer : renderers) { + renderer->viewport(x, y, width, height, vflip); } } -void ofRendererCollection::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist){ - for(auto renderer: renderers){ - renderer->setupScreenPerspective(width,height,fov,nearDist,farDist); +void ofRendererCollection::setupScreenPerspective(float width, float height, float fov, float nearDist, float farDist) { + for (auto renderer : renderers) { + renderer->setupScreenPerspective(width, height, fov, nearDist, farDist); } } -void ofRendererCollection::setupScreenOrtho(float width, float height, float nearDist, float farDist){ - for(auto renderer: renderers){ - renderer->setupScreenOrtho(width,height,nearDist,farDist); +void ofRendererCollection::setupScreenOrtho(float width, float height, float nearDist, float farDist) { + for (auto renderer : renderers) { + renderer->setupScreenOrtho(width, height, nearDist, farDist); } } -ofRectangle ofRendererCollection::getCurrentViewport() const{ - if(renderers.size()){ +ofRectangle ofRendererCollection::getCurrentViewport() const { + if (renderers.size()) { return renderers[0]->getCurrentViewport(); - }else{ + } else { return ofRectangle(); } } -ofRectangle ofRendererCollection::getNativeViewport() const{ - if(renderers.size()){ +ofRectangle ofRendererCollection::getNativeViewport() const { + if (renderers.size()) { return renderers[0]->getNativeViewport(); - }else{ + } else { return ofRectangle(); } } -int ofRendererCollection::getViewportWidth() const{ - if(renderers.size()){ +int ofRendererCollection::getViewportWidth() const { + if (renderers.size()) { return renderers[0]->getViewportWidth(); - }else{ + } else { return 0; } } -int ofRendererCollection::getViewportHeight() const{ - if(renderers.size()){ +int ofRendererCollection::getViewportHeight() const { + if (renderers.size()) { return renderers[0]->getViewportHeight(); - }else{ + } else { return 0; } } -void ofRendererCollection::setCoordHandedness(ofHandednessType handedness){ - for(auto renderer: renderers){ +void ofRendererCollection::setCoordHandedness(ofHandednessType handedness) { + for (auto renderer : renderers) { renderer->setCoordHandedness(handedness); } } -ofHandednessType ofRendererCollection::getCoordHandedness() const{ - if(renderers.size()){ +ofHandednessType ofRendererCollection::getCoordHandedness() const { + if (renderers.size()) { return renderers[0]->getCoordHandedness(); - }else{ + } else { return OF_LEFT_HANDED; } } //our openGL wrappers -void ofRendererCollection::pushMatrix(){ - for(auto renderer: renderers){ +void ofRendererCollection::pushMatrix() { + for (auto renderer : renderers) { renderer->pushMatrix(); } } -void ofRendererCollection::popMatrix(){ - for(auto renderer: renderers){ +void ofRendererCollection::popMatrix() { + for (auto renderer : renderers) { renderer->popMatrix(); } } -void ofRendererCollection::translate(float x, float y, float z){ - for(auto renderer: renderers){ - renderer->translate(x,y,z); +void ofRendererCollection::translate(float x, float y, float z) { + for (auto renderer : renderers) { + renderer->translate(x, y, z); } } -void ofRendererCollection::translate(const glm::vec3 & p){ - for(auto renderer: renderers){ +void ofRendererCollection::translate(const glm::vec3 & p) { + for (auto renderer : renderers) { renderer->translate(p); } } -void ofRendererCollection::scale(float xAmnt, float yAmnt, float zAmnt){ - for(auto renderer: renderers){ - renderer->scale(xAmnt,yAmnt,zAmnt); +void ofRendererCollection::scale(float xAmnt, float yAmnt, float zAmnt) { + for (auto renderer : renderers) { + renderer->scale(xAmnt, yAmnt, zAmnt); } } -void ofRendererCollection::rotateDeg(float degrees, float vecX, float vecY, float vecZ){ - for(auto renderer: renderers){ - renderer->rotateDeg(degrees,vecX,vecY,vecZ); +void ofRendererCollection::rotateDeg(float degrees, float vecX, float vecY, float vecZ) { + for (auto renderer : renderers) { + renderer->rotateDeg(degrees, vecX, vecY, vecZ); } } -void ofRendererCollection::rotateXDeg(float degrees){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateXDeg(float degrees) { + for (auto renderer : renderers) { renderer->rotateXDeg(degrees); } } -void ofRendererCollection::rotateYDeg(float degrees){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateYDeg(float degrees) { + for (auto renderer : renderers) { renderer->rotateYDeg(degrees); } } -void ofRendererCollection::rotateZDeg(float degrees){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateZDeg(float degrees) { + for (auto renderer : renderers) { renderer->rotateZDeg(degrees); } } -void ofRendererCollection::rotateDeg(float degrees){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateDeg(float degrees) { + for (auto renderer : renderers) { renderer->rotateDeg(degrees); } } -void ofRendererCollection::rotateRad(float radians, float vecX, float vecY, float vecZ){ - for(auto renderer: renderers){ - renderer->rotateRad(radians,vecX,vecY,vecZ); +void ofRendererCollection::rotateRad(float radians, float vecX, float vecY, float vecZ) { + for (auto renderer : renderers) { + renderer->rotateRad(radians, vecX, vecY, vecZ); } } -void ofRendererCollection::rotateXRad(float radians){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateXRad(float radians) { + for (auto renderer : renderers) { renderer->rotateXRad(radians); } } -void ofRendererCollection::rotateYRad(float radians){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateYRad(float radians) { + for (auto renderer : renderers) { renderer->rotateYRad(radians); } } -void ofRendererCollection::rotateZRad(float radians){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateZRad(float radians) { + for (auto renderer : renderers) { renderer->rotateZRad(radians); } } -void ofRendererCollection::rotateRad(float radians){ - for(auto renderer: renderers){ +void ofRendererCollection::rotateRad(float radians) { + for (auto renderer : renderers) { renderer->rotateRad(radians); } } -void ofRendererCollection::loadIdentityMatrix (void){ - for(auto renderer: renderers){ - renderer->loadIdentityMatrix(); - } +void ofRendererCollection::loadIdentityMatrix(void) { + for (auto renderer : renderers) { + renderer->loadIdentityMatrix(); + } } -void ofRendererCollection::loadMatrix (const glm::mat4 & m){ - for(auto renderer: renderers){ - renderer->loadMatrix( m ); - } +void ofRendererCollection::loadMatrix(const glm::mat4 & m) { + for (auto renderer : renderers) { + renderer->loadMatrix(m); + } } -void ofRendererCollection::loadMatrix (const float * m){ - for(auto renderer: renderers){ - renderer->loadMatrix( m ); - } +void ofRendererCollection::loadMatrix(const float * m) { + for (auto renderer : renderers) { + renderer->loadMatrix(m); + } } -void ofRendererCollection::multMatrix (const glm::mat4 & m){ - for(auto renderer: renderers){ - renderer->multMatrix( m ); - } +void ofRendererCollection::multMatrix(const glm::mat4 & m) { + for (auto renderer : renderers) { + renderer->multMatrix(m); + } } -void ofRendererCollection::multMatrix (const float * m){ - for(auto renderer: renderers){ - renderer->multMatrix( m ); - } +void ofRendererCollection::multMatrix(const float * m) { + for (auto renderer : renderers) { + renderer->multMatrix(m); + } } -void ofRendererCollection::setOrientation(ofOrientation orientation, bool vflip){ - for(auto renderer: renderers){ - renderer->setOrientation( orientation, vflip ); - } +void ofRendererCollection::setOrientation(ofOrientation orientation, bool vflip) { + for (auto renderer : renderers) { + renderer->setOrientation(orientation, vflip); + } } -bool ofRendererCollection::isVFlipped() const{ - if(!renderers.empty()){ - return renderers.front()->isVFlipped(); - }else{ - ofLogWarning() << "No renderer in renderer collection, but vflipped requested returning true."; - return true; - } +bool ofRendererCollection::isVFlipped() const { + if (!renderers.empty()) { + return renderers.front()->isVFlipped(); + } else { + ofLogWarning() << "No renderer in renderer collection, but vflipped requested returning true."; + return true; + } } -void ofRendererCollection::matrixMode(ofMatrixMode mode){ - for(auto renderer: renderers){ - renderer->matrixMode( mode ); - } +void ofRendererCollection::matrixMode(ofMatrixMode mode) { + for (auto renderer : renderers) { + renderer->matrixMode(mode); + } } -void ofRendererCollection::loadViewMatrix(const glm::mat4& m){ - for(auto renderer: renderers){ - renderer->loadViewMatrix( m ); - } +void ofRendererCollection::loadViewMatrix(const glm::mat4 & m) { + for (auto renderer : renderers) { + renderer->loadViewMatrix(m); + } } -void ofRendererCollection::multViewMatrix(const glm::mat4& m){ - for(auto renderer: renderers){ - renderer->multViewMatrix( m ); - } +void ofRendererCollection::multViewMatrix(const glm::mat4 & m) { + for (auto renderer : renderers) { + renderer->multViewMatrix(m); + } } -glm::mat4 ofRendererCollection::getCurrentViewMatrix() const{ - if(!renderers.empty()){ - return renderers.front()->getCurrentViewMatrix(); - }else{ - ofLogWarning() << "No renderer in renderer collection, but current view matrix requested. Returning identity matrix."; - return glm::mat4(1.0); - } +glm::mat4 ofRendererCollection::getCurrentViewMatrix() const { + if (!renderers.empty()) { + return renderers.front()->getCurrentViewMatrix(); + } else { + ofLogWarning() << "No renderer in renderer collection, but current view matrix requested. Returning identity matrix."; + return glm::mat4(1.0); + } } - // screen coordinate things / default gl values -void ofRendererCollection::setupGraphicDefaults(){ - for(auto renderer: renderers){ +void ofRendererCollection::setupGraphicDefaults() { + for (auto renderer : renderers) { renderer->setupGraphicDefaults(); - } - path.setMode(ofPath::COMMANDS); - path.setUseShapeColor(false); + } + path.setMode(ofPath::COMMANDS); + path.setUseShapeColor(false); } -void ofRendererCollection::setupScreen(){ - for(auto renderer: renderers){ +void ofRendererCollection::setupScreen() { + for (auto renderer : renderers) { renderer->setupScreen(); } } // color options -void ofRendererCollection::setColor(float r, float g, float b){ - for(auto renderer: renderers){ - renderer->setColor(r,g,b); +void ofRendererCollection::setColor(float r, float g, float b) { + for (auto renderer : renderers) { + renderer->setColor(r, g, b); } } -void ofRendererCollection::setColor(float r, float g, float b, float a){ - for(auto renderer: renderers){ - renderer->setColor(r,g,b,a); +void ofRendererCollection::setColor(float r, float g, float b, float a) { + for (auto renderer : renderers) { + renderer->setColor(r, g, b, a); } } -void ofRendererCollection::setColor(const ofFloatColor & color){ - for(auto renderer: renderers){ - renderer->setColor(color); +void ofRendererCollection::setColor(const ofFloatColor & color) { + for (auto renderer : renderers) { + renderer->setColor(color); } } -void ofRendererCollection::setColor(const ofFloatColor & color, float _a){ - for(auto renderer: renderers){ - renderer->setColor(color,_a); +void ofRendererCollection::setColor(const ofFloatColor & color, float _a) { + for (auto renderer : renderers) { + renderer->setColor(color, _a); } } -void ofRendererCollection::setColor(float gray){ - for(auto renderer: renderers){ - renderer->setColor(gray); +void ofRendererCollection::setColor(float gray) { + for (auto renderer : renderers) { + renderer->setColor(gray); } } -void ofRendererCollection::ofRendererCollection::setHexColor( int hexColor ){ - for(auto renderer: renderers){ - renderer->setHexColor(hexColor); +void ofRendererCollection::ofRendererCollection::setHexColor(int hexColor) { + for (auto renderer : renderers) { + renderer->setHexColor(hexColor); } } // hex, like web 0xFF0033; // bg color -ofFloatColor ofRendererCollection::getBackgroundColor(){ - if(renderers.size()){ +ofFloatColor ofRendererCollection::getBackgroundColor() { + if (renderers.size()) { return renderers[0]->getBackgroundColor(); - }else{ - return ofFloatColor(200.f/255.f); + } else { + return ofFloatColor(200.f / 255.f); } } -void ofRendererCollection::setBackgroundColor(const ofFloatColor & color){ - for(auto renderer: renderers){ - renderer->setBackgroundColor(color); +void ofRendererCollection::setBackgroundColor(const ofFloatColor & color) { + for (auto renderer : renderers) { + renderer->setBackgroundColor(color); } } -bool ofRendererCollection::getBackgroundAuto(){ - if(renderers.size()){ +bool ofRendererCollection::getBackgroundAuto() { + if (renderers.size()) { return renderers[0]->getBackgroundAuto(); - }else{ + } else { return true; } } -void ofRendererCollection::background(const ofFloatColor & c){ - for(auto renderer: renderers){ - renderer->background(c); +void ofRendererCollection::background(const ofFloatColor & c) { + for (auto renderer : renderers) { + renderer->background(c); } } -void ofRendererCollection::background(float brightness){ - for(auto renderer: renderers){ - renderer->background(brightness); +void ofRendererCollection::background(float brightness) { + for (auto renderer : renderers) { + renderer->background(brightness); } } -void ofRendererCollection::background(int hexColor, int _a){ - for(auto renderer: renderers){ - renderer->background(hexColor,_a); +void ofRendererCollection::background(int hexColor, int _a) { + for (auto renderer : renderers) { + renderer->background(hexColor, _a); } } -void ofRendererCollection::background(float r, float g, float b, float a){ - for(auto renderer: renderers){ - renderer->background(r,g,b,a); +void ofRendererCollection::background(float r, float g, float b, float a) { + for (auto renderer : renderers) { + renderer->background(r, g, b, a); } } -void ofRendererCollection::setBackgroundAuto(bool bManual){ - for(auto renderer: renderers){ - renderer->setBackgroundAuto(bManual); +void ofRendererCollection::setBackgroundAuto(bool bManual) { + for (auto renderer : renderers) { + renderer->setBackgroundAuto(bManual); } } -void ofRendererCollection::clear(){ - for(auto renderer: renderers){ - renderer->clear(); +void ofRendererCollection::clear() { + for (auto renderer : renderers) { + renderer->clear(); } } -void ofRendererCollection::clear(float r, float g, float b, float a){ - for(auto renderer: renderers){ - renderer->clear(r,g,b,a); +void ofRendererCollection::clear(float r, float g, float b, float a) { + for (auto renderer : renderers) { + renderer->clear(r, g, b, a); } } -void ofRendererCollection::clear(float brightness, float a){ - for(auto renderer: renderers){ - renderer->clear(brightness,a); +void ofRendererCollection::clear(float brightness, float a) { + for (auto renderer : renderers) { + renderer->clear(brightness, a); } } -void ofRendererCollection::clearAlpha(){ - for(auto renderer: renderers){ - renderer->clearAlpha(); +void ofRendererCollection::clearAlpha() { + for (auto renderer : renderers) { + renderer->clearAlpha(); } } // drawing modes -void ofRendererCollection::setRectMode(ofRectMode mode){ - for(auto renderer: renderers){ - renderer->setRectMode(mode); +void ofRendererCollection::setRectMode(ofRectMode mode) { + for (auto renderer : renderers) { + renderer->setRectMode(mode); } } -ofRectMode ofRendererCollection::getRectMode(){ - if(renderers.empty()){ - return OF_RECTMODE_CORNER; - }else{ - return renderers[0]->getRectMode(); - } +ofRectMode ofRendererCollection::getRectMode() { + if (renderers.empty()) { + return OF_RECTMODE_CORNER; + } else { + return renderers[0]->getRectMode(); + } } -void ofRendererCollection::setFillMode(ofFillFlag fill){ - for(auto renderer: renderers){ - renderer->setFillMode(fill); +void ofRendererCollection::setFillMode(ofFillFlag fill) { + for (auto renderer : renderers) { + renderer->setFillMode(fill); + } + if (fill == OF_FILLED) { + path.setFilled(true); + path.setStrokeWidth(0); + } else { + path.setFilled(false); + path.setStrokeWidth(getStyle().lineWidth); } - if(fill==OF_FILLED){ - path.setFilled(true); - path.setStrokeWidth(0); - }else{ - path.setFilled(false); - path.setStrokeWidth(getStyle().lineWidth); - } } -ofFillFlag ofRendererCollection::getFillMode(){ - if(renderers.empty()){ - return OF_FILLED; - }else{ - return renderers[0]->getFillMode(); - } +ofFillFlag ofRendererCollection::getFillMode() { + if (renderers.empty()) { + return OF_FILLED; + } else { + return renderers[0]->getFillMode(); + } } -void ofRendererCollection::setLineWidth(float lineWidth){ - for(auto renderer: renderers){ - renderer->setLineWidth(lineWidth); - } - if(!getStyle().bFill){ - path.setStrokeWidth(lineWidth); - } +void ofRendererCollection::setLineWidth(float lineWidth) { + for (auto renderer : renderers) { + renderer->setLineWidth(lineWidth); + } + if (!getStyle().bFill) { + path.setStrokeWidth(lineWidth); + } } void ofRendererCollection::setDepthTest(bool depthTest) { - for(auto renderer: renderers){ - renderer->setDepthTest(depthTest); - } + for (auto renderer : renderers) { + renderer->setDepthTest(depthTest); + } } -void ofRendererCollection::setBlendMode(ofBlendMode blendMode){ - for(auto renderer: renderers){ - renderer->setBlendMode(blendMode); +void ofRendererCollection::setBlendMode(ofBlendMode blendMode) { + for (auto renderer : renderers) { + renderer->setBlendMode(blendMode); } } -void ofRendererCollection::setLineSmoothing(bool smooth){ - for(auto renderer: renderers){ - renderer->setLineSmoothing(smooth); +void ofRendererCollection::setLineSmoothing(bool smooth) { + for (auto renderer : renderers) { + renderer->setLineSmoothing(smooth); } } -void ofRendererCollection::setCircleResolution(int res){ - for(auto renderer: renderers){ - renderer->setCircleResolution(res); +void ofRendererCollection::setCircleResolution(int res) { + for (auto renderer : renderers) { + renderer->setCircleResolution(res); } } -void ofRendererCollection::enablePointSprites(){ - for(auto renderer: renderers){ - if(renderer->getType()=="GL" || renderer->getType()=="ProgrammableGL"){ +void ofRendererCollection::enablePointSprites() { + for (auto renderer : renderers) { + if (renderer->getType() == "GL" || renderer->getType() == "ProgrammableGL") { std::dynamic_pointer_cast(renderer)->enablePointSprites(); } } } -void ofRendererCollection::disablePointSprites(){ - for(auto renderer: renderers){ - if(renderer->getType()=="GL" || renderer->getType()=="ProgrammableGL"){ +void ofRendererCollection::disablePointSprites() { + for (auto renderer : renderers) { + if (renderer->getType() == "GL" || renderer->getType() == "ProgrammableGL") { std::dynamic_pointer_cast(renderer)->disablePointSprites(); } } } -void ofRendererCollection::enableAntiAliasing(){ - for(auto renderer: renderers){ - renderer->enableAntiAliasing(); +void ofRendererCollection::enableAntiAliasing() { + for (auto renderer : renderers) { + renderer->enableAntiAliasing(); } } -void ofRendererCollection::disableAntiAliasing(){ - for(auto renderer: renderers){ - renderer->disableAntiAliasing(); +void ofRendererCollection::disableAntiAliasing() { + for (auto renderer : renderers) { + renderer->disableAntiAliasing(); } } -void ofRendererCollection::setBitmapTextMode(ofDrawBitmapMode mode){ - for(auto renderer: renderers){ - renderer->setBitmapTextMode(mode); +void ofRendererCollection::setBitmapTextMode(ofBitmapMode mode) { + for (auto renderer : renderers) { + renderer->setBitmapTextMode(mode); } } -ofStyle ofRendererCollection::getStyle() const{ - if(renderers.empty()){ - return ofStyle(); - }else{ - return renderers[0]->getStyle(); - } +ofStyle ofRendererCollection::getStyle() const { + if (renderers.empty()) { + return ofStyle(); + } else { + return renderers[0]->getStyle(); + } } -void ofRendererCollection::pushStyle(){ - for(auto renderer: renderers){ - renderer->pushStyle(); +void ofRendererCollection::pushStyle() { + for (auto renderer : renderers) { + renderer->pushStyle(); } } -void ofRendererCollection::popStyle(){ - for(auto renderer: renderers){ - renderer->popStyle(); +void ofRendererCollection::popStyle() { + for (auto renderer : renderers) { + renderer->popStyle(); } } -void ofRendererCollection::setStyle(const ofStyle & style){ - for(auto renderer: renderers){ - renderer->setStyle(style); +void ofRendererCollection::setStyle(const ofStyle & style) { + for (auto renderer : renderers) { + renderer->setStyle(style); } } -void ofRendererCollection::setCurveResolution(int res){ - for(auto renderer: renderers){ - renderer->setCurveResolution(res); +void ofRendererCollection::setCurveResolution(int res) { + for (auto renderer : renderers) { + renderer->setCurveResolution(res); } path.setCurveResolution(res); } -void ofRendererCollection::setPolyMode(ofPolyWindingMode mode){ - for(auto renderer: renderers){ - renderer->setPolyMode(mode); +void ofRendererCollection::setPolyMode(ofPolyWindingMode mode) { + for (auto renderer : renderers) { + renderer->setPolyMode(mode); } path.setPolyWindingMode(mode); } // drawing -void ofRendererCollection::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{ - for(auto renderer: renderers){ - renderer->drawLine(x1,y1,z1,x2,y2,z2); +void ofRendererCollection::drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const { + for (auto renderer : renderers) { + renderer->drawLine(x1, y1, z1, x2, y2, z2); } } -void ofRendererCollection::drawRectangle(float x, float y, float z, float w, float h) const{ - for(auto renderer: renderers){ - renderer->drawRectangle(x,y,z,w,h); +void ofRendererCollection::drawRectangle(float x, float y, float z, float w, float h) const { + for (auto renderer : renderers) { + renderer->drawRectangle(x, y, z, w, h); } } -void ofRendererCollection::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{ - for(auto renderer: renderers){ - renderer->drawTriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3); +void ofRendererCollection::drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const { + for (auto renderer : renderers) { + renderer->drawTriangle(x1, y1, z1, x2, y2, z2, x3, y3, z3); } } -void ofRendererCollection::drawCircle(float x, float y, float z, float radius) const{ - for(auto renderer: renderers){ - renderer->drawCircle(x,y,z,radius); +void ofRendererCollection::drawCircle(float x, float y, float z, float radius) const { + for (auto renderer : renderers) { + renderer->drawCircle(x, y, z, radius); } } -void ofRendererCollection::drawEllipse(float x, float y, float z, float width, float height) const{ - for(auto renderer: renderers){ - renderer->drawEllipse(x,y,z,width,height); +void ofRendererCollection::drawEllipse(float x, float y, float z, float width, float height) const { + for (auto renderer : renderers) { + renderer->drawEllipse(x, y, z, width, height); } } -void ofRendererCollection::drawString(std::string text, float x, float y, float z) const{ - for(auto renderer: renderers){ - renderer->drawString(text, x,y,z); +void ofRendererCollection::drawString(std::string text, float x, float y, float z) const { + for (auto renderer : renderers) { + renderer->drawString(text, x, y, z); } } -void ofRendererCollection::drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const{ - for(auto renderer: renderers){ - renderer->drawString(font, text, x,y); +void ofRendererCollection::drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const { + for (auto renderer : renderers) { + renderer->drawString(font, text, x, y); } } -void ofRendererCollection::bind(const ofCamera & camera, const ofRectangle & viewport){ - for(auto renderer: renderers){ - renderer->bind(camera, viewport); +void ofRendererCollection::bind(const ofCamera & camera, const ofRectangle & viewport) { + for (auto renderer : renderers) { + renderer->bind(camera, viewport); } } -void ofRendererCollection::unbind(const ofCamera & camera){ - for(auto renderer: renderers){ +void ofRendererCollection::unbind(const ofCamera & camera) { + for (auto renderer : renderers) { renderer->unbind(camera); } } -const of3dGraphics & ofRendererCollection::get3dGraphics() const{ - return graphics3d; +const of3dGraphics & ofRendererCollection::get3dGraphics() const { + return graphics3d; } -of3dGraphics & ofRendererCollection::get3dGraphics(){ - return graphics3d; +of3dGraphics & ofRendererCollection::get3dGraphics() { + return graphics3d; } -ofPath & ofRendererCollection::getPath(){ - return path; +ofPath & ofRendererCollection::getPath() { + return path; } diff --git a/libs/openFrameworks/graphics/ofRendererCollection.h b/libs/openFrameworks/graphics/ofRendererCollection.h index 9a6c1e2f6ad..0d331427c1a 100644 --- a/libs/openFrameworks/graphics/ofRendererCollection.h +++ b/libs/openFrameworks/graphics/ofRendererCollection.h @@ -1,36 +1,36 @@ #pragma once -#include "ofGraphicsBaseTypes.h" #include "of3dGraphics.h" +#include "ofGraphicsBaseTypes.h" #include "ofPath.h" -class ofRendererCollection: public ofBaseRenderer{ +class ofRendererCollection : public ofBaseRenderer { public: - ofRendererCollection():graphics3d(this){} - ~ofRendererCollection(){} - - static const std::string TYPE; - const std::string & getType(){ return TYPE; } + ofRendererCollection() + : graphics3d(this) { } + ~ofRendererCollection() { } - std::shared_ptr getGLRenderer(); + static const std::string TYPE; + const std::string & getType() { return TYPE; } - bool rendersPathPrimitives(); + std::shared_ptr getGLRenderer(); - void startRender(); + bool rendersPathPrimitives(); - void finishRender(); + void startRender(); + void finishRender(); - using ofBaseRenderer::draw; + using ofBaseRenderer::draw; - void draw(const ofPolyline & poly) const; - void draw(const ofPath & shape) const; + void draw(const ofPolyline & poly) const; + void draw(const ofPath & shape) const; - void draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const; + void draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const; - void draw(const of3dPrimitive& model, ofPolyRenderMode renderType ) const ; + void draw(const of3dPrimitive & model, ofPolyRenderMode renderType) const; - void draw(const ofNode& node) const ; + void draw(const ofNode & node) const; void draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const; @@ -52,67 +52,65 @@ class ofRendererCollection: public ofBaseRenderer{ } }*/ - glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const; - glm::mat4 getCurrentOrientationMatrix() const; glm::mat4 getCurrentNormalMatrix() const; //-------------------------------------------- // transformations - void pushView(); + void pushView(); - void popView(); + void popView(); // setup matrices and viewport (upto you to push and pop view before and after) // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight()) // if nearDist or farDist are 0 assume defaults (calculated based on width / height) void viewport(ofRectangle viewport); - void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip=true); + void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool vflip = true); - void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0); + void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0); - void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1); + void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1); - ofRectangle getCurrentViewport() const; + ofRectangle getCurrentViewport() const; - ofRectangle getNativeViewport() const; + ofRectangle getNativeViewport() const; - int getViewportWidth() const; - int getViewportHeight() const; + int getViewportWidth() const; + int getViewportHeight() const; - void setCoordHandedness(ofHandednessType handedness); - ofHandednessType getCoordHandedness() const; + void setCoordHandedness(ofHandednessType handedness); + ofHandednessType getCoordHandedness() const; //our openGL wrappers - void pushMatrix(); - void popMatrix(); - void translate(float x, float y, float z = 0); - void translate(const glm::vec3 & p); - void scale(float xAmnt, float yAmnt, float zAmnt = 1); + void pushMatrix(); + void popMatrix(); + void translate(float x, float y, float z = 0); + void translate(const glm::vec3 & p); + void scale(float xAmnt, float yAmnt, float zAmnt = 1); - void rotateDeg(float degrees, float vecX, float vecY, float vecZ); - void rotateXDeg(float degrees); - void rotateYDeg(float degrees); - void rotateZDeg(float degrees); - void rotateDeg(float degrees); + void rotateDeg(float degrees, float vecX, float vecY, float vecZ); + void rotateXDeg(float degrees); + void rotateYDeg(float degrees); + void rotateZDeg(float degrees); + void rotateDeg(float degrees); - void rotateRad(float radians, float vecX, float vecY, float vecZ); - void rotateXRad(float radians); - void rotateYRad(float radians); - void rotateZRad(float radians); - void rotateRad(float radians); - void loadIdentityMatrix (void); + void rotateRad(float radians, float vecX, float vecY, float vecZ); + void rotateXRad(float radians); + void rotateYRad(float radians); + void rotateZRad(float radians); + void rotateRad(float radians); + void loadIdentityMatrix(void); - void loadMatrix (const glm::mat4 & m); + void loadMatrix(const glm::mat4 & m); - void loadMatrix (const float * m); + void loadMatrix(const float * m); - void multMatrix (const glm::mat4 & m); + void multMatrix(const glm::mat4 & m); - void multMatrix (const float * m); + void multMatrix(const float * m); void setOrientation(ofOrientation orientation, bool vflip); @@ -120,17 +118,16 @@ class ofRendererCollection: public ofBaseRenderer{ void matrixMode(ofMatrixMode mode); - void loadViewMatrix(const glm::mat4& m); + void loadViewMatrix(const glm::mat4 & m); - void multViewMatrix(const glm::mat4& m); + void multViewMatrix(const glm::mat4 & m); glm::mat4 getCurrentViewMatrix() const; - // screen coordinate things / default gl values - void setupGraphicDefaults(); + void setupGraphicDefaults(); - void setupScreen(); + void setupScreen(); // color options void setColor(float r, float g, float b); @@ -143,7 +140,7 @@ class ofRendererCollection: public ofBaseRenderer{ void setColor(float gray); - void setHexColor( int hexColor ); + void setHexColor(int hexColor); // bg color ofFloatColor getBackgroundColor(); @@ -156,17 +153,17 @@ class ofRendererCollection: public ofBaseRenderer{ void background(float brightness); - void background(int hexColor, int _a=255); + void background(int hexColor, int _a = 255); - void background(float r, float g, float b, float a=1.f); + void background(float r, float g, float b, float a = 1.f); void setBackgroundAuto(bool bManual); void clear(); - void clear(float r, float g, float b, float a=0); + void clear(float r, float g, float b, float a = 0); - void clear(float brightness, float a=0); + void clear(float brightness, float a = 0); void clearAlpha(); @@ -193,7 +190,7 @@ class ofRendererCollection: public ofBaseRenderer{ void disableAntiAliasing(); - void setBitmapTextMode(ofDrawBitmapMode mode); + void setBitmapTextMode(ofBitmapMode mode); ofStyle getStyle() const; @@ -231,7 +228,7 @@ class ofRendererCollection: public ofBaseRenderer{ ofPath & getPath(); - std::vector > renderers; + std::vector> renderers; of3dGraphics graphics3d; ofPath path; };