void Direct3DCircleBatcher::renderPartialCircle(Circle &circle, int arcDegrees, Color &c, GpuProgramWrapper &gpuProgramWrapper) { m_iNumPoints = 0; D3DManager->m_colorVertices.clear(); for (int i = 90; i < (450 - arcDegrees); i += DEGREE_SPACING) { float rad = DEGREES_TO_RADIANS(i); float cos = cosf(rad); float sin = sinf(rad); addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); } float rad = DEGREES_TO_RADIANS(450 - arcDegrees); float cos = cosf(rad); float sin = sinf(rad); addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); endBatch(gpuProgramWrapper); }
void OpenGLESCircleBatcher::renderPartialCircle(Circle &circle, int arcDegrees, Color &c, GpuProgramWrapper &gpuProgramWrapper) { OGLESManager->m_colorVertices.clear(); OGLESManager->addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints = 1; for (int i = 90 - arcDegrees; i > -270; i -= DEGREE_SPACING) { float rad = DEGREES_TO_RADIANS(i); float cos = cosf(rad); float sin = sinf(rad); OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints++; } float rad = DEGREES_TO_RADIANS(-270); float cos = cosf(rad); float sin = sinf(rad); OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints++; endBatch(gpuProgramWrapper); }
void BatchRenderEngine::render() { endBatch(); flush(); glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glActiveTexture(GL_TEXTURE0); CEGUI::System::getSingleton().renderAllGUIContexts(); glDisable(GL_SCISSOR_TEST); // Prevents flickering caused by CEGUI call swapWindowBuffer(); clear(0.0f, 0.15f, 0.3f, 1.0f); startBatch(); }
ofRectangle ofxFontStash::drawMultiLineColumn( string & text, float size, float x, float y, float maxW, int &numLines, bool dontDraw, int maxLines, bool giveBackNewLinedText, bool* wordsWereTruncated){ ofRectangle totalArea = ofRectangle(x,y,0,0); if(wordsWereTruncated){ *wordsWereTruncated = false; } if (stash != NULL){ numLines = 0; if(!dontDraw){ glPushMatrix(); glTranslatef(x, y, 0.0f); } //ofLine(0, 0, maxW, 0); vector<string>splitLines; ofRectangle r; //ofUTF8Ptr start = ofUTF8::beginPtr(text); ofUTF8Ptr iter = ofUTF8::beginPtr(text); ofUTF8Ptr lineStart = iter; ofUTF8Ptr lastSpace; ofUTF8Ptr stop = ofUTF8::endPtr(text); string thisLine = ""; bool foundSpace = false; bool foundNewLine = false; while(iter < stop) { ofUniChar c = ofUTF8::getNext(iter); // get the next unichar and iterate if ( ofUnicode::isSpace(c) ){ foundSpace = true; lastSpace = iter; } if ( ofTextConverter::toUTF8(c) == "\n" ){ foundNewLine = true; } thisLine += ofTextConverter::toUTF8(c); r = getBBox(thisLine.c_str(), size, 0,0); if ( r.width > maxW || foundNewLine ) { //we went too far, lets jump back to our closest space if(foundNewLine){ if (thisLine == "\n"){ //if the whole line is only \n, replace with a space to avoid weird things thisLine = " "; }else{ //otherwise remove the "\n" thisLine = thisLine.substr(0, thisLine.length()-1); } splitLines.push_back(thisLine); }else{ if (foundSpace){ //cout << "## foundSpace! (" << thisLine << ")" << endl; string finalLine = walkAndFill(lineStart, iter, lastSpace); splitLines.push_back(finalLine); iter = lastSpace; }else{ //cout << "## no Space! (" << thisLine << ")" << endl; splitLines.push_back(thisLine); if(wordsWereTruncated){ *wordsWereTruncated = true; } } } //reset counter vars lineStart = iter; r.width = 0; thisLine = ""; foundSpace = foundNewLine = false; }else{ if(iter == stop){ //last line! string finalLine = walkAndFill(lineStart, iter, stop); splitLines.push_back(finalLine); break; } } } if(!dontDraw) beginBatch(); numLines = splitLines.size(); int linesToDraw = 0; if (maxLines > 0 ){ linesToDraw = MIN(splitLines.size(), maxLines); numLines = splitLines.size(); } for(int i = 0; i < linesToDraw; i++){ float yy = lineHeight * OFX_FONT_STASH_LINE_HEIGHT_MULT * size * i; if(!dontDraw){ ofPushMatrix(); ofTranslate(0, yy); drawBatch(splitLines[i], size, 0, 0 ); ofPopMatrix(); } #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 8 totalArea = totalArea.getUnion( getBBox(splitLines[i], size, x, y + yy)); #else totalArea = getBBox(splitLines[i], size, x, y + yy); //TODO! #endif } if(!dontDraw){ endBatch(); glPopMatrix(); } //return through reference the edited text (with newLines!) if(giveBackNewLinedText){ text = ""; for (int i = 0; i < numLines; i++){ text += splitLines[i]; if (i != numLines-1) text += "\n"; } } }else{ ofLogError("ofxFontStash", "can't drawMultiLine() without having been setup first!"); } return totalArea; }
void OpenGLESLineBatcher::endBatch() { endBatch(*OGLESManager->m_colorProgram); }
ofRectangle ofxFontStash::drawMultiLineColumn( string & _text, float size, float x, float y, float maxW, int &numLines, bool dontDraw, int maxLines, bool giveBackNewLinedText, bool* wordsWereTruncated){ string text = _text; if (!utf8::is_valid(text.begin(), text.end())){ text = LocaleToUtf8(text); } ofRectangle totalArea = ofRectangle(x,y,0,0); if(wordsWereTruncated){ *wordsWereTruncated = false; } if (stash != NULL){ numLines = 0; if(!dontDraw){ glPushMatrix(); glTranslatef(x, y, 0.0f); } //ofLine(0, 0, maxW, 0); vector<string>splitLines; ofRectangle r; const char * iter = text.c_str(); const char * lineStart = iter; const char * lastSpace; const char * stop = text.c_str() + text.length(); string thisLine = ""; bool foundSpace = false; bool foundNewLine = false; while(iter < stop) { unsigned int c = utf8::unchecked::next(iter); // get the next unichar and iterate if ( isSpace(c) ){ foundSpace = true; lastSpace = iter; } if ( toUTF8(c) == "\n" ){ foundNewLine = true; } thisLine += toUTF8(c); r = getBBox(thisLine.c_str(), size, 0,0); if ( r.width > maxW || foundNewLine ) { //we went too far, lets jump back to our closest space if(foundNewLine){ if (thisLine == "\n"){ //if the whole line is only \n, replace with a space to avoid weird things thisLine = " "; }else{ //otherwise remove the "\n" thisLine = thisLine.substr(0, thisLine.length()-1); } splitLines.push_back(thisLine); }else{ if (foundSpace){ string finalLine = walkAndFill(lineStart, iter, lastSpace); splitLines.push_back(finalLine); // Edge case where if max width is met and first character is space if(!(utf8::unchecked::next(lineStart) == 0x20)){ iter = lastSpace; } }else{ splitLines.push_back(thisLine); if(wordsWereTruncated){ *wordsWereTruncated = true; } } } //reset counter vars lineStart = iter; r.width = 0; thisLine = ""; foundSpace = foundNewLine = false; }else{ if(iter == stop){ //last line! string finalLine = walkAndFill(lineStart, iter, stop); splitLines.push_back(finalLine); break; } } } if(!dontDraw) beginBatch(); numLines = splitLines.size(); int linesToDraw = 0; if (maxLines > 0 ){ linesToDraw = MIN(splitLines.size(), maxLines); numLines = splitLines.size(); }else{ linesToDraw = splitLines.size(); } for(int i = 0; i < linesToDraw; i++){ float yy = lineHeight * OFX_FONT_STASH_LINE_HEIGHT_MULT * size * i; if(!dontDraw){ ofPushMatrix(); ofTranslate(0, yy); drawBatch(splitLines[i], size, 0, 0 ); ofPopMatrix(); } #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR >= 8 totalArea = totalArea.getUnion( getBBox(splitLines[i], size, x, y + yy)); #else totalArea = getBBox(splitLines[i], size, x, y + yy); //TODO! #endif } if(!dontDraw){ endBatch(); glPopMatrix(); } //return through reference the edited text (with newLines!) if(giveBackNewLinedText){ text = ""; for (int i = 0; i < numLines; i++){ if (i < maxLines || maxLines == 0){ text += splitLines[i]; if (i != numLines-1) text += "\n"; } } } }else{ ofLogError("ofxFontStash") << "can't draw() without having been setup first!"; } return totalArea; }
void BatchRenderEngine::enqueue(Renderable r, GLuint * indices) { // Check in regard to drawString function - error? unsigned int vertNum; unsigned int indNum; unsigned int i; const GLuint tid = (GLuint)r.getTid(); float ts = 0.0f; vertNum = r.getVertices().size(); indNum = (vertNum / 4) * 6; // Assumes all input renderables are sprites - fix if (vertNum + _currVerts > MAX_VERTS || indNum + _currInds > MAX_INDICES || _currTextures >= MAX_TEXTURES) // we've reached our limit, draw everything and restart { endBatch(); flush(); startBatch(); } // Error possibly here - incorrect textures if (tid > 0) { bool found = false; for (unsigned int i = 0; i < _currTextures; i++) { if (_textures[i] == tid) { ts = (float)i; found = true; break; } } if (!found) { if (_currTextures >= MAX_TEXTURES) { endBatch(); flush(); startBatch(); } ts = _currTextures * 1.0f; _textures[_currTextures] = tid * 1.0f; _currTextures++; } } else ts = -1.0f; std::vector<Vertex *> verts = r.getVertices(); if (indices == NULL) { indices = new GLuint[6]; indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 2; indices[4] = 3; indices[5] = 0; indNum = 6; } // Store all verts and attributes in arrays for (i = 0; i<vertNum; i++) { _vertices[_currVerts + i].pos = *(verts[i]->GetPos()); _vertices[_currVerts + i].texCoord = *(verts[i]->GetTexCoord()); _vertices[_currVerts + i].normal = *(verts[i]->GetNormal()); _vertices[_currVerts + i].color = *(verts[i]->GetColor()); _vertices[_currVerts + i].tid = ts; } // Store all indices in an array for (i = 0; i < indNum; i++) { _indices[_currInds + i] = indices[i] + _currVerts; } _currVerts += vertNum; _currInds += indNum; }