void AbstractChart::renderTickLabels(int pWindowId, unsigned w, unsigned h, std::vector<std::string> &texts, glm::mat4 &transformation, int coor_offset, bool useZoffset) { auto &fonter = getChartFont(); fonter->setOthro2D(int(w), int(h)); float pos[2]; for (StringIter it = texts.begin(); it!=texts.end(); ++it) { int idx = int(it - texts.begin()); glm::vec4 p = glm::vec4(mTickTextX[idx+coor_offset], mTickTextY[idx+coor_offset], (useZoffset ? mTickTextZ[idx+coor_offset] : 0), 1); glm::vec4 res = transformation * p; /* convert text position from [-1,1] range to * [0, 1) range and then offset horizontally * to compensate for margins and ticksize */ pos[0] = w*(res.x/res.w+1.0f)/2.0f; pos[1] = h*(res.y/res.w+1.0f)/2.0f; /* offset based on text size to align * text center with tick mark position */ if(coor_offset < mTickCount) { pos[0] -= ((CHART2D_FONT_SIZE*it->length()/2.0f)); }else if(coor_offset >= mTickCount && coor_offset < 2*mTickCount) { pos[1] -= ((CHART2D_FONT_SIZE)); }else { pos[0] -= ((CHART2D_FONT_SIZE*it->length()/2.0f)); pos[1] -= ((CHART2D_FONT_SIZE)); } fonter->render(pWindowId, pos, WHITE, it->c_str(), CHART2D_FONT_SIZE); } }
void AbstractChart2D::renderChart(const void* pWnd, int pX, int pY, int pVPW, int pVPH) { float w = float(pVPW - (mLeftMargin + mRightMargin + mTickSize)); float h = float(pVPH - (mTopMargin + mBottomMargin + mTickSize)); float offset_x = (1.9f * (mLeftMargin+mTickSize) + (w - pVPW)) / pVPW; float offset_y = (1.9f * (mBottomMargin+mTickSize) + (h - pVPH)) / pVPH; float scale_x = w / pVPW; float scale_y = h / pVPH; CheckGL("Begin Chart::render"); bindResources(pWnd); /* bind the plotting shader program */ glUseProgram(mBorderProgram); /* set uniform attributes of shader * for drawing the plot borders */ glm::mat4 trans = glm::scale(glm::translate(glm::mat4(1), glm::vec3(offset_x, offset_y, 0)), glm::vec3(scale_x, scale_y, 1)); glUniformMatrix4fv(mBorderMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); glUniform4fv(mBorderColorIndex, 1, WHITE); /* Draw borders */ glDrawArrays(GL_LINE_LOOP, 0, 4); /* reset shader program binding */ glUseProgram(0); /* bind the sprite shader program to * draw ticks on x and y axes */ glPointSize((GLfloat)mTickSize); glUseProgram(mSpriteProgram); glUniform4fv(mSpriteTickcolorIndex, 1, WHITE); glUniformMatrix4fv(mSpriteMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); /* Draw tick marks on y axis */ glUniform1i(mSpriteTickaxisIndex, 1); glDrawArrays(GL_POINTS, 4, mTickCount); /* Draw tick marks on x axis */ glUniform1i(mSpriteTickaxisIndex, 0); glDrawArrays(GL_POINTS, 4+mTickCount, mTickCount); glUseProgram(0); glPointSize(1); unbindResources(); auto &fonter = getChartFont(); fonter->setOthro2D(int(w), int(h)); float pos[2]; /* render tick marker texts for y axis */ for (StringIter it = mYText.begin(); it!=mYText.end(); ++it) { int idx = int(it - mYText.begin()); glm::vec4 res = trans * glm::vec4(mTickTextX[idx], mTickTextY[idx], 0, 1); /* convert text position from [-1,1] range to * [0, 1) range and then offset horizontally * to compensate for margins and ticksize */ pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[0] -= (pVPW-w)*0.60f; fonter->render(pWnd, pos, WHITE, it->c_str(), CHART2D_FONT_SIZE); } /* render tick marker texts for x axis */ for (StringIter it = mXText.begin(); it!=mXText.end(); ++it) { int idx = int(it - mXText.begin()); /* mTickCount offset is needed while reading point coordinates for * x axis tick marks */ glm::vec4 res = trans * glm::vec4(mTickTextX[idx+mTickCount], mTickTextY[idx+mTickCount], 0, 1); /* convert text position from [-1,1] range to * [0, 1) range and then offset vertically * to compensate for margins and ticksize */ pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[1] -= (pVPH-h)*0.34f; /* offset horizontally based on text size to align * text center with tick mark position */ pos[0] -= (CHART2D_FONT_SIZE*(it->length()-2)/2.0f); fonter->render(pWnd, pos, WHITE, it->c_str(), CHART2D_FONT_SIZE); } /* render chart axes titles */ if (!mYTitle.empty()) { glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[0] -= (pVPW-w)*0.76; fonter->render(pWnd, pos, WHITE, mYTitle.c_str(), CHART2D_FONT_SIZE, true); } if (!mXTitle.empty()) { glm::vec4 res = trans * glm::vec4(0.0f, -1.0f, 0.0f, 1.0f); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[1] -= (pVPH-h)*0.66; fonter->render(pWnd, pos, WHITE, mXTitle.c_str(), CHART2D_FONT_SIZE); } CheckGL("End Chart::render"); }
void AbstractChart2D::renderChart(int pX, int pY, int pVPW, int pVPH) const { float w = float(pVPW - (mLeftMargin + mRightMargin + mTickSize)); float h = float(pVPH - (mTopMargin + mBottomMargin + mTickSize)); float offset_x = (2.0f * (mLeftMargin+mTickSize) + (w - pVPW)) / pVPW; float offset_y = (2.0f * (mBottomMargin+mTickSize) + (h - pVPH)) / pVPH; float scale_x = w / pVPW; float scale_y = h / pVPH; CheckGL("Begin Chart::render"); glEnableVertexAttribArray(mBorderPointIndex); glBindBuffer(GL_ARRAY_BUFFER, mDecorVBO); glVertexAttribPointer(mBorderPointIndex, 2, GL_FLOAT, GL_FALSE, 0, 0); /* bind the plotting shader program */ glUseProgram(mBorderProgram); /* set uniform attributes of shader * for drawing the plot borders */ glm::mat4 trans = glm::scale(glm::translate(glm::mat4(1), glm::vec3(offset_x, offset_y, 0)), glm::vec3(scale_x, scale_y, 1)); glUniformMatrix4fv(mBorderMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); glUniform4fv(mBorderColorIndex, 1, WHITE); /* Draw borders */ glDrawArrays(GL_LINE_LOOP, 0, 4); /* reset shader program binding */ glUseProgram(0); /* bind the sprite shader program to * draw ticks on x and y axes */ glPointSize((GLfloat)mTickSize); /* Following line is required for opengl compatibility profile */ glEnable(GL_POINT_SPRITE); glUseProgram(mSpriteProgram); glUniform4fv(mSpriteTickcolorIndex, 1, WHITE); glUniformMatrix4fv(mSpriteMatIndex, 1, GL_FALSE, glm::value_ptr(trans)); /* Draw tick marks on y axis */ glUniform1i(mSpriteTickaxisIndex, 1); glDrawArrays(GL_POINTS, 4, mTickCount); /* Draw tick marks on x axis */ glUniform1i(mSpriteTickaxisIndex, 0); glDrawArrays(GL_POINTS, 4+mTickCount, mTickCount); glUseProgram(0); glPointSize(1); glDisableVertexAttribArray(mBorderPointIndex); glBindBuffer(GL_ARRAY_BUFFER, 0); /* Following line is required for opengl compatibility profile */ glDisable(GL_POINT_SPRITE); auto &fonter = getChartFont(); fonter.setOthro2D(int(w), int(h)); float pos[2]; /* render tick marker texts for y axis */ for (StringIter it = mYText.begin(); it!=mYText.end(); ++it) { int idx = int(it - mYText.begin()); glm::vec4 res = trans * glm::vec4(mTickTextX[idx], mTickTextY[idx], 0, 1); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[0] -= (pVPW-w)*0.50f; fonter.render(pos, WHITE, it->c_str(), 15); } /* render tick marker texts for x axis */ for (StringIter it = mXText.begin(); it!=mXText.end(); ++it) { int idx = int(it - mXText.begin()); /* mTickCount offset is needed while reading point coordinates for * x axis tick marks */ glm::vec4 res = trans * glm::vec4(mTickTextX[idx+mTickCount], mTickTextY[idx+mTickCount], 0, 1); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[1] -= (pVPH-h)*0.32f; fonter.render(pos, WHITE, it->c_str(), 15); } /* render chart axes titles */ if (!mYTitle.empty()) { glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[0] -= (pVPW-w)*0.70f; fonter.render(pos, WHITE, mYTitle.c_str(), 15, true); } if (!mXTitle.empty()) { glm::vec4 res = trans * glm::vec4(0.0f, -1.0f, 0.0f, 1.0f); pos[0] = w*(res.x+1.0f)/2.0f; pos[1] = h*(res.y+1.0f)/2.0f; pos[1] -= (pVPH-h)*0.70f; fonter.render(pos, WHITE, mXTitle.c_str(), 15); } CheckGL("End Chart::render"); }
void CryptoManager::loadCertificates() throw() { if(!BOOLSETTING(USE_TLS)) return; SSL_CTX_set_verify(serverContext, SSL_VERIFY_NONE, 0); SSL_CTX_set_verify(clientContext, SSL_VERIFY_NONE, 0); SSL_CTX_set_verify(clientVerContext, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0); SSL_CTX_set_verify(serverVerContext, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0); const string& cert = SETTING(TLS_CERTIFICATE_FILE); const string& key = SETTING(TLS_PRIVATE_KEY_FILE); if(cert.empty() || key.empty()) { LogManager::getInstance()->message(STRING(NO_CERTIFICATE_FILE_SET)); return; } if(File::getSize(cert) == -1 || File::getSize(key) == -1) { // Try to generate them... try { generateCertificate(); } catch(const CryptoException& e) { LogManager::getInstance()->message(STRING(CERTIFICATE_GENERATION_FAILED) + e.getError()); } } if(SSL_CTX_use_certificate_file(serverContext, SETTING(TLS_CERTIFICATE_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_CERTIFICATE)); return; } if(SSL_CTX_use_certificate_file(clientContext, SETTING(TLS_CERTIFICATE_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_CERTIFICATE)); return; } if(SSL_CTX_use_certificate_file(serverVerContext, SETTING(TLS_CERTIFICATE_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_CERTIFICATE)); return; } if(SSL_CTX_use_certificate_file(clientVerContext, SETTING(TLS_CERTIFICATE_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_CERTIFICATE)); return; } if(SSL_CTX_use_PrivateKey_file(serverContext, SETTING(TLS_PRIVATE_KEY_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_PRIVATE_KEY)); return; } if(SSL_CTX_use_PrivateKey_file(clientContext, SETTING(TLS_PRIVATE_KEY_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_PRIVATE_KEY)); return; } if(SSL_CTX_use_PrivateKey_file(serverVerContext, SETTING(TLS_PRIVATE_KEY_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_PRIVATE_KEY)); return; } if(SSL_CTX_use_PrivateKey_file(clientVerContext, SETTING(TLS_PRIVATE_KEY_FILE).c_str(), SSL_FILETYPE_PEM) != SSL_SUCCESS) { LogManager::getInstance()->message(STRING(FAILED_TO_LOAD_PRIVATE_KEY)); return; } StringList certs = File::findFiles(SETTING(TLS_TRUSTED_CERTIFICATES_PATH), "*.pem"); StringList certs2 = File::findFiles(SETTING(TLS_TRUSTED_CERTIFICATES_PATH), "*.crt"); certs.insert(certs.end(), certs2.begin(), certs2.end()); for(StringIter i = certs.begin(); i != certs.end(); ++i) { if( SSL_CTX_load_verify_locations(clientContext, i->c_str(), NULL) != SSL_SUCCESS || SSL_CTX_load_verify_locations(clientVerContext, i->c_str(), NULL) != SSL_SUCCESS || SSL_CTX_load_verify_locations(serverContext, i->c_str(), NULL) != SSL_SUCCESS || SSL_CTX_load_verify_locations(serverVerContext, i->c_str(), NULL) != SSL_SUCCESS ) { LogManager::getInstance()->message("Failed to load trusted certificate from " + *i); } } certsLoaded = true; }