// see drawSubsection void mui::TextureAtlas::addSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh){ GLfloat px0 = x; // up to you to get the aspect ratio right GLfloat py0 = y; GLfloat px1 = w+x; GLfloat py1 = h+y; if (tex.texData.bFlipTexture == ofIsVFlipped()){ swap(py0,py1); } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 -= w/2; py0 -= h/2; px1 -= w/2; py1 -= h/2; } // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0.0f; GLfloat offseth = 0.0f; if (!ofGLSupportsNPOTTextures() && ofIsTextureEdgeHackEnabled()) { offsetw = 1.0f / (tex.texData.tex_w); offseth = 1.0f / (tex.texData.tex_h); } // ------------------------------------------------- ofPoint topLeft = tex.getCoordFromPoint(sx, sy); ofPoint bottomRight = tex.getCoordFromPoint(sx + sw, sy + sh); GLfloat tx0 = topLeft.x + offsetw; GLfloat ty0 = topLeft.y + offseth; GLfloat tx1 = bottomRight.x - offsetw; GLfloat ty1 = bottomRight.y - offseth; add.addVertex(ofVec3f(px0,py0,z)); add.addVertex(ofVec3f(px1,py0,z)); add.addVertex(ofVec3f(px1,py1,z)); add.addVertex(ofVec3f(px0,py0,z)); add.addVertex(ofVec3f(px1,py1,z)); add.addVertex(ofVec3f(px0,py1,z)); add.addTexCoord(ofVec3f(tx0,ty0)); add.addTexCoord(ofVec3f(tx1,ty0)); add.addTexCoord(ofVec3f(tx1,ty1)); add.addTexCoord(ofVec3f(tx0,ty0)); add.addTexCoord(ofVec3f(tx1,ty1)); add.addTexCoord(ofVec3f(tx0,ty1)); }
//These methods let us add custom GUI parameters and respond to their events void CloudsVisualSystemRandomDigits2::selfSetupGui(){ ofGetRectMode() == OF_RECTMODE_CENTER; customGui = new ofxUISuperCanvas("RANDOM DIGITS 2", gui); customGui->copyCanvasStyle(gui); customGui->copyCanvasProperties(gui); customGui->setName("RANDOM DIGITS 2"); customGui->setWidgetFontSize(OFX_UI_FONT_SMALL); customGui->addIntSlider("X Count", 1, 200, &xCount); customGui->addIntSlider("Y Count", 1, 200, &yCount); customGui->addIntSlider("Z Count", 1, 200, &zCount); customGui->addIntSlider("X Spacing", 1, 200, &xSpacing); customGui->addIntSlider("Y Spacing", 1, 200, &ySpacing); customGui->addIntSlider("Z Spacing", 1, 1000, &zSpacing); customGui->addSlider("X Noise", 0, 200, &xNoise); customGui->addSlider("Y Noise", 0, 200, &yNoise); customGui->addSlider("Z Noise", 0, 500, &zNoise); customGui->addButton("Update Number Placing", true); customGui->addSlider("Dark Color", 0, 2, &dark); customGui->addSlider("Light Color", 0, 2, &light); customGui->addSlider("FOG DENSITY", 0.0f, 0.1f, &fogDensity); customGui->addToggle("ROTATION FIX HACK", &rotationFix); ofAddListener(customGui->newGUIEvent, this, &CloudsVisualSystemRandomDigits2::selfGuiEvent); guis.push_back(customGui); guimap[customGui->getName()] = customGui; }
//---------------------------------------------------------- void ofTextureBak::draw(float x, float y, float w, float h){ glEnable(textureTarget); // bind the texture glBindTexture( textureTarget, (GLuint)textureName[0] ); GLint px0 = 0; // up to you to get the aspect ratio right GLint py0 = 0; GLint px1 = (GLint)w; GLint py1 = (GLint)h; if (bFlipTexture == true){ GLint temp = py0; py0 = py1; py1 = temp; } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 = (GLint)-w/2; py0 = (GLint)-h/2; px1 = (GLint)+w/2; py1 = (GLint)+h/2; } // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0; GLfloat offseth = 0; if (textureTarget == GL_TEXTURE_2D){ offsetw = 1.0f/(tex_w); offseth = 1.0f/(tex_h); } // ------------------------------------------------- GLfloat tx0 = 0+offsetw; GLfloat ty0 = 0+offseth; GLfloat tx1 = tex_t - offsetw; GLfloat ty1 = tex_u - offseth; glPushMatrix(); glTranslated(x, y, 0); glBegin( GL_QUADS ); glTexCoord2f(tx0,ty0); glVertex3i(px0, py0,0); glTexCoord2f(tx1,ty0); glVertex3i(px1, py0,0); glTexCoord2f(tx1,ty1); glVertex3i(px1, py1,0); glTexCoord2f(tx0,ty1); glVertex3i(px0, py1,0); glEnd(); glPopMatrix(); glDisable(textureTarget); }
//-------------------------------------------------------------- void ofxFileDialog::drawFilenames(int offset, int bottomOffset, bool highlight) { int x = 0; float center = (m_height-s_charHeight*offset)*0.5; int top = -center+(s_charHeight*2); int bottom = center-(s_charHeight*bottomOffset); int displayRange = m_visibleLines-offset; // center vertically ofPushMatrix(); ofTranslate(0, m_visibleLines*0.5*s_charHeight); // start drawing based on current file location in file list so selection remains centered float y = (m_currentFile/(float)m_filenames.size()) * -s_charHeight * (float)m_filenames.size() + s_charHeight; unsigned int count = 0; for(vector<u32string>::iterator i = m_filenames.begin(); i != m_filenames.end(); i++) { m_numLines = 0; bool isDir = m_directories.find(count) != m_directories.end(); // don't draw on top of path if(y < top) { y += s_charHeight; count++; continue; } // only show numbers in the display range if(((int)count > ((int)m_currentFile - (int)displayRange)) && ((int)count < ((int)m_currentFile + (int)displayRange))) { for(int c = 0; c < i->size(); ++c) { // current file background if(highlight && count == m_currentFile) { ofSetColor(m_settings->getCursorColor().r, m_settings->getCursorColor().g, m_settings->getCursorColor().b, m_settings->getCursorColor().a * m_settings->getAlpha()); ofRectMode rectMode = ofGetRectMode(); ofSetRectMode(OF_RECTMODE_CORNER); ofDrawRectangle(x, y-s_charHeight, characterWidth((*i)[c]), s_charHeight); ofSetRectMode(rectMode); } // file or dir name x = s_font->drawCharacter((*i)[c], x, y, s_textShadow); } x = 0; } y += s_charHeight; count++; // don't draw beyond bottom if(y > bottom) { break; } } ofPopMatrix(); }
//-------------------------------------------------------------- void ofxFileDialog::drawSaveAs() { bool drawnCursor = false; int x = 0, y = s_charHeight; s_font->setColor(m_settings->getTextColor(), m_settings->getAlpha()); s_font->setShadowColor(m_settings->getTextShadowColor(), m_settings->getAlpha()); if(m_saveAsState == FOLDER_DIALOG) { drawNewFolder(); } else { ofPushMatrix(); ofTranslate(0, s_charHeight*2); // info text s_font->drawString(s_saveAsText, x, y, s_textShadow); // new file name with cursor y += s_charHeight*2; for(unsigned int i = 0; i < m_text.size(); ++i) { // draw cursor if(m_saveAsState == FILENAME && i == m_position) { drawCursor(x, y); drawnCursor = true; } // text x = s_font->drawCharacter(m_text[i], x, y, s_textShadow); } // draw cursor if we have no text, or if we're at the end of the buffer if(m_saveAsState == FILENAME && !drawnCursor) { drawCursor(x, y); } drawFilenames(5, 2, m_saveAsState == BROWSER); ofPopMatrix(); y = m_height-s_charHeight; if(m_saveAsState == FOLDER) { int width = s_font->stringWidth(s_newFolderButtonText); ofSetColor(m_settings->getCursorColor().r, m_settings->getCursorColor().g, m_settings->getCursorColor().b, m_settings->getCursorColor().a * m_settings->getAlpha()); ofRectMode rectMode = ofGetRectMode(); ofSetRectMode(OF_RECTMODE_CORNER); ofDrawRectangle(x, y-s_charWidth, width, s_charHeight); ofSetRectMode(rectMode); } s_font->drawString(s_newFolderButtonText, 0, y, s_textShadow); } }
// copied almost directly from ofTexture.cpp // changes: // - no anchor point support (doesn't make sense) // - removed bind/unbind/activetex //---------------------------------------------------------- void mui::TextureAtlas::drawSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) { GLfloat px0 = x; // up to you to get the aspect ratio right GLfloat py0 = y; GLfloat px1 = w+x; GLfloat py1 = h+y; if (tex.texData.bFlipTexture == ofIsVFlipped()){ swap(py0,py1); } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 -= w/2; py0 -= h/2; px1 -= w/2; py1 -= h/2; } //we translate our drawing points by our anchor point. //we still respect ofRectMode so if you have rect mode set to //OF_RECTMODE_CENTER your anchor will be relative to that. GLfloat anchorX; GLfloat anchorY; // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0.0f; GLfloat offseth = 0.0f; if (!ofGLSupportsNPOTTextures() && ofIsTextureEdgeHackEnabled()) { offsetw = 1.0f / (tex.texData.tex_w); offseth = 1.0f / (tex.texData.tex_h); } // ------------------------------------------------- ofPoint topLeft = tex.getCoordFromPoint(sx, sy); ofPoint bottomRight = tex.getCoordFromPoint(sx + sw, sy + sh); GLfloat tx0 = topLeft.x + offsetw; GLfloat ty0 = topLeft.y + offseth; GLfloat tx1 = bottomRight.x - offsetw; GLfloat ty1 = bottomRight.y - offseth; /*if(z>0 || z<0){ ofPushMatrix(); ofTranslate(0,0,z); }*/ quad.getVertices()[0].set(px0,py0,z); quad.getVertices()[1].set(px1,py0,z); quad.getVertices()[2].set(px1,py1,z); quad.getVertices()[3].set(px0,py1,z); quad.getTexCoords()[0].set(tx0,ty0); quad.getTexCoords()[1].set(tx1,ty0); quad.getTexCoords()[2].set(tx1,ty1); quad.getTexCoords()[3].set(tx0,ty1); quad.draw(); }
//---------------------------------------------------------- void ofTexture::draw(float x, float y, float w, float h){ glEnable(texData.textureTarget); // bind the texture glBindTexture( texData.textureTarget, (GLuint)texData.textureName[0] ); GLfloat px0 = 0; // up to you to get the aspect ratio right GLfloat py0 = 0; GLfloat px1 = w; GLfloat py1 = h; if (texData.bFlipTexture == true){ GLint temp = (GLint)py0; py0 = py1; py1 = temp; } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 = -w/2; py0 = -h/2; px1 = +w/2; py1 = +h/2; } //we translate our drawing points by our anchor point. //we still respect ofRectMode so if you have rect mode set to //OF_RECTMODE_CENTER your anchor will be relative to that. GLfloat anchorX; GLfloat anchorY; if(bAnchorIsPct){ anchorX = anchor.x * w; anchorY = anchor.y * h; }else{ anchorX = anchor.x; anchorY = anchor.y; } px0 -= anchorX; py0 -= anchorY; px1 -= anchorX; py1 -= anchorY; // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0; GLfloat offseth = 0; if (texData.textureTarget == GL_TEXTURE_2D && bTexHackEnabled) { offsetw = 1.0f / (texData.tex_w); offseth = 1.0f / (texData.tex_h); } // ------------------------------------------------- GLfloat tx0 = 0+offsetw; GLfloat ty0 = 0+offseth; GLfloat tx1 = texData.tex_t - offsetw; GLfloat ty1 = texData.tex_u - offseth; glPushMatrix(); glTranslatef(x,y,0.0f); GLfloat tex_coords[] = { tx0,ty0, tx1,ty0, tx1,ty1, tx0,ty1 }; GLfloat verts[] = { px0,py0, px1,py0, px1,py1, px0,py1 }; glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glTexCoordPointer(2, GL_FLOAT, 0, tex_coords ); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, verts ); glDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glPopMatrix(); glDisable(texData.textureTarget); }
//---------------------------------------------------------- void ofTexture::drawSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) { if(!texData.bAllocated){ return; } GLfloat px0 = x; // up to you to get the aspect ratio right GLfloat py0 = y; GLfloat px1 = w+x; GLfloat py1 = h+y; if (texData.bFlipTexture == ofIsVFlipped()){ swap(py0,py1); } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 -= w/2; py0 -= h/2; px1 -= w/2; py1 -= h/2; } //we translate our drawing points by our anchor point. //we still respect ofRectMode so if you have rect mode set to //OF_RECTMODE_CENTER your anchor will be relative to that. GLfloat anchorX; GLfloat anchorY; if(bAnchorIsPct){ anchorX = anchor.x * w; anchorY = anchor.y * h; }else{ anchorX = anchor.x; anchorY = anchor.y; } px0 -= anchorX; py0 -= anchorY; px1 -= anchorX; py1 -= anchorY; // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0.0f; GLfloat offseth = 0.0f; if (!ofGLSupportsNPOTTextures() && bTexHackEnabled) { offsetw = 1.0f / (texData.tex_w); offseth = 1.0f / (texData.tex_h); } // ------------------------------------------------- ofPoint topLeft = getCoordFromPoint(sx, sy); ofPoint bottomRight = getCoordFromPoint(sx + sw, sy + sh); GLfloat tx0 = topLeft.x + offsetw; GLfloat ty0 = topLeft.y + offseth; GLfloat tx1 = bottomRight.x - offsetw; GLfloat ty1 = bottomRight.y - offseth; quad.getVertices()[0].set(px0,py0,z); quad.getVertices()[1].set(px1,py0,z); quad.getVertices()[2].set(px1,py1,z); quad.getVertices()[3].set(px0,py1,z); quad.getTexCoords()[0].set(tx0,ty0); quad.getTexCoords()[1].set(tx1,ty0); quad.getTexCoords()[2].set(tx1,ty1); quad.getTexCoords()[3].set(tx0,ty1); // make sure we are on unit 0 - we may change this when setting shader samplers // before glEnable or else the shader gets confused /// ps: maybe if bUsingArbTex is enabled we should use glActiveTextureARB? //glActiveTexture(GL_TEXTURE0); bool wasBound = texData.isBound; if(!wasBound) bind(0); quad.draw(); if(!wasBound) unbind(0); }
void ramDrawBasicFloor(const int floorPattern, const float floorSize, const float tileSize, const ofColor& c1, const ofColor& c2) { if (floorPattern == ramFloor::FLOOR_NONE) return; glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable(GL_DEPTH_TEST); glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_LINE); glPolygonOffset(4.0, 1.0); int division = floorSize / tileSize; ofPushStyle(); ofSetLineWidth(1.0); ofPushMatrix(); ofRotate(90.0f, 1.0f, 0.0f, 0.0f); if (ofGetRectMode() != OF_RECTMODE_CENTER) { float w = division * tileSize; ofTranslate(-w / 2.0f, -w / 2.0f); } glNormal3f(0.0f, 1.0f, 0.0f); if (floorPattern == ramFloor::FLOOR_PLANE) { ofFill(); ofSetColor(c1); ofRect(0, 0, 0, division * tileSize, division * tileSize); } for (int i = 0; i < division; i++) { for (int j = 0; j < division; j++) { switch (floorPattern) { case ramFloor::FLOOR_CHECKER_PATTERN: ofFill(); ofSetColor((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1) ? c1 : c2); ofRect(i * tileSize, j * tileSize, tileSize, tileSize); break; case ramFloor::FLOOR_GRID_LINES: ofNoFill(); ofSetColor(c1); ofRect(i * tileSize, j * tileSize, tileSize, tileSize); break; } } } ofPopMatrix(); ofPopStyle(); glPopAttrib(); }
//------------------------------------ ofMesh ofTexture::getMeshForSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{ ofMesh quad; if(!texData.bAllocated){ return quad; } GLfloat px0 = x; // up to you to get the aspect ratio right GLfloat py0 = y; GLfloat px1 = w+x; GLfloat py1 = h+y; if (texData.bFlipTexture == ofIsVFlipped()){ swap(py0,py1); } // for rect mode center, let's do this: if (ofGetRectMode() == OF_RECTMODE_CENTER){ px0 -= w/2; py0 -= h/2; px1 -= w/2; py1 -= h/2; } //we translate our drawing points by our anchor point. //we still respect ofRectMode so if you have rect mode set to //OF_RECTMODE_CENTER your anchor will be relative to that. GLfloat anchorX; GLfloat anchorY; if(bAnchorIsPct){ anchorX = anchor.x * w; anchorY = anchor.y * h; }else{ anchorX = anchor.x; anchorY = anchor.y; } px0 -= anchorX; py0 -= anchorY; px1 -= anchorX; py1 -= anchorY; // ------------------------------------------------- // complete hack to remove border artifacts. // slightly, slightly alters an image, scaling... // to remove the border. // we need a better solution for this, but // to constantly add a 2 pixel border on all uploaded images // is insane.. GLfloat offsetw = 0.0f; GLfloat offseth = 0.0f; if (!ofGLSupportsNPOTTextures() && bTexHackEnabled) { offsetw = 1.0f / (texData.tex_w); offseth = 1.0f / (texData.tex_h); } // ------------------------------------------------- ofPoint topLeft = getCoordFromPoint(sx, sy); ofPoint bottomRight = getCoordFromPoint(sx + sw, sy + sh); GLfloat tx0 = topLeft.x + offsetw; GLfloat ty0 = topLeft.y + offseth; GLfloat tx1 = bottomRight.x - offsetw; GLfloat ty1 = bottomRight.y - offseth; quad.setMode(OF_PRIMITIVE_TRIANGLE_FAN); quad.getVertices().resize(4); quad.getTexCoords().resize(4); quad.getVertices()[0].set(px0,py0,z); quad.getVertices()[1].set(px1,py0,z); quad.getVertices()[2].set(px1,py1,z); quad.getVertices()[3].set(px0,py1,z); quad.getTexCoords()[0].set(tx0,ty0); quad.getTexCoords()[1].set(tx1,ty0); quad.getTexCoords()[2].set(tx1,ty1); quad.getTexCoords()[3].set(tx0,ty1); return quad; }