void OpenGLShaderQuad::Render(double t, IPluginObjectInstance *pInstance) { IContext *pContext = dynamic_cast<IBaseInstance *>(pInstance)->GetContext(); IRenderContextParams *contextParams = (IRenderContextParams *)pContext->TopContextParamObject(); width = contextParams->GetFrameBufferWidth(); height = contextParams->GetFrameBufferHeight(); BeginOrtho(); OpenGLShaderBase::ReloadIfNeeded(); texture_count = 0; glGetError(); program->Attach(); unsigned int idResolution = program->GetUniform("iResolution"); unsigned int idGlobalTime = program->GetUniform("iGlobalTime"); // set user parameters SetParametersFromList(pInstance); if (idResolution != -1) { glUniform2f(idResolution, (float)width, (float)height); } if (idGlobalTime != -1) { glUniform1f(idGlobalTime, (float)t); } if (useblend->v->boolean) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glColor4f(1,1,1, alpha->v->float_val); // glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //glBlendFunc(GL_ONE, GL_ONE); //printf("%f:%f\n",t,alpha->v->float_val); } if (depthwrite->v->boolean) { glDepthMask(GL_TRUE); } else { glDepthMask(GL_FALSE); } if (texture->v->int_val != 0) { glActiveTexture(GL_TEXTURE0+texture_count); glBindTexture(GL_TEXTURE_2D,texture->v->int_val); texture_count++; } glBegin(GL_QUADS); /* glTexCoord2f(0.0f,0.0f); glVertex2f(-1.0f, -1.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(1, -1.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f,1.0f); glVertex2f(-1.0f, 1.0f); */ for(int i=0;i<texture_count;i++) glMultiTexCoord2f(GL_TEXTURE0+i,0.0f,0.0f); glVertex2f(-1.0f, -1.0f); for(int i=0;i<texture_count;i++) glMultiTexCoord2f(GL_TEXTURE0+i,1.0f,0.0f); glVertex2f(1, -1.0f); for(int i=0;i<texture_count;i++) glMultiTexCoord2f(GL_TEXTURE0+i,1.0f,1.0f); glVertex2f(1.0f, 1.0f); for(int i=0;i<texture_count;i++) glMultiTexCoord2f(GL_TEXTURE0+i,0.0f,1.0f); glVertex2f(-1.0f, 1.0f); glEnd(); //glBegin(GL_QUADS); if (texture_count > 0) { for(int i=0;i<texture_count;i++) { glActiveTexture(GL_TEXTURE0+i); glBindTexture(GL_TEXTURE_2D, 0); } glActiveTexture(GL_TEXTURE0); // set this back to 0 other wise the active texture is still valid glDisable(GL_TEXTURE_2D); } if (useblend->v->boolean) { glDisable(GL_BLEND); } program->Detach(); EndOrtho(); //glDisable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); }
void OpenGLDrawText::Render(double t, IPluginObjectInstance *pInstance) { // Render bitmaps IContext *pContext = dynamic_cast<IBaseInstance *>(pInstance)->GetContext(); IRenderContextParams *contextParams = (IRenderContextParams *)pContext->TopContextParamObject(); float width = contextParams->GetWindowWidth(); float height = contextParams->GetWindowHeight(); float px_width = contextParams->GetFrameBufferWidth(); float px_height = contextParams->GetFrameBufferHeight(); //printf("win (%d,%d), fb (%d:%d)\n",(int)width,(int)height,(int)px_width,(int)px_height); float xfac = px_width/width; float yfac = px_height/height; unsigned int uniform_tex = 0; unsigned int uniform_color = 0; if (rendered) return; rendered = false; if (useShaders) { OpenGLShaderBase::ReloadIfNeeded(); OpenGLShaderBase::Attach(); } //Window mode: // win (640,360), fb (1280:720) // xfac/yfac 2.000000:2.000000 // sx/sy 0.003125:0.005556 //Full screen: // win (1280,720), fb (2560:1600) // xfac/yfac 2.000000:2.222222 // sx/sy 0.001563:0.003086 float sx = 2.0 / width; float sy = 2.0 / height; //float sx = xfac / width; //float sy = yfac / height; // printf("xfac/yfac %f:%f\n",xfac,yfac); // printf("sx/sy %f:%f\n",sx,sy); sx *= width/height; //sy *= width/height; // ok for retina full screen -> but NOT in windowed mode // sx *= xfac; // sy *= yfac; // glActiveTexture(GL_TEXTURE0); glPushMatrix(); glScalef(-1,1,1); textureFont->SetRenderScaling(sx,sy); float xp,yp; float str_width, str_height; float linepos = 0; std::string strBase = std::string(text->v->string); Tokenizer tok(strBase, "\\"); while (true) { std::string str = tok.NextIncludeSpace(); if (str.empty()) break; textureFont->Estimate(str, &str_width, &str_height); xp = yp = 0; xp = position->v->vector[0]; yp = position->v->vector[1] + linepos; switch(alignment->v->int_val) { case 0 : // none, use position break; case 1 : xp = 0; break; case 2 : // right xp = 1 - str_width; break; case 3 : // center xp = 0 - str_width/2.0f; break; } // printf("alignment: %d\n",alignment->v->int_val); if (useblend->v->boolean == true) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(color->v->rgba[0], color->v->rgba[1], color->v->rgba[2], alpha->v->float_val); // glColor4f(1,1,1, alpha->v->float_val); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } else { glColor4f(color->v->rgba[0], color->v->rgba[1], color->v->rgba[2], alpha->v->float_val); } textureFont->Draw(str,xp,yp); linepos -= sy * 0.5 * (float)fontSize->v->int_val; } glPopMatrix(); if (useShaders) { OpenGLShaderBase::Detach(); } if (useblend->v->boolean) { glDisable(GL_BLEND); } }
void OpenGLShaderQuad::Render(double t, IPluginObjectInstance *pInstance) { IContext *pContext = dynamic_cast<IBaseInstance *>(pInstance)->GetContext(); IRenderContextParams *contextParams = (IRenderContextParams *)pContext->TopContextParamObject(); width = contextParams->GetFrameBufferWidth(); height = contextParams->GetFrameBufferHeight(); BeginOrtho(); OpenGLShaderBase::ReloadIfNeeded(); program->Attach(); unsigned int idResolution = program->GetUniform("iResolution"); unsigned int idGlobalTime = program->GetUniform("iGlobalTime"); if (idResolution != -1) { glUniform2f(idResolution, (float)width, (float)height); } if (idGlobalTime != -1) { glUniform1f(idGlobalTime, (float)t); } // set user parameters SetParametersFromList(pInstance); if (depthwrite->v->boolean) { glDepthMask(GL_TRUE); } else { glDepthMask(GL_FALSE); } bool bUseTexture = false; if (texture->v->int_val != 0) { glBindTexture(GL_TEXTURE_2D,texture->v->int_val); glEnable(GL_TEXTURE_2D); bUseTexture = true; } glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex2f(-1.0f, -1.0f); glTexCoord2f(1.0f,0.0f); glVertex2f(1, -1.0f); glTexCoord2f(1.0f,1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f,1.0f); glVertex2f(-1.0f, 1.0f); glEnd(); //glBegin(GL_QUADS); if (bUseTexture) { glDisable(GL_TEXTURE_2D); } EndOrtho(); program->Detach(); //glDisable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); }