void COverlayTextureGL::Render(SRenderState& state) { glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_texture); if(m_pma) glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); else glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); DRAWRECT rd; if (m_pos == POSITION_RELATIVE) { rd.top = state.y - state.height * 0.5; rd.bottom = state.y + state.height * 0.5; rd.left = state.x - state.width * 0.5; rd.right = state.x + state.width * 0.5; } else { rd.top = state.y; rd.bottom = state.y + state.height; rd.left = state.x; rd.right = state.x + state.width; } #if defined(HAS_GL) CRenderSystemGL* renderSystem = dynamic_cast<CRenderSystemGL*>(CServiceBroker::GetRenderSystem()); renderSystem->EnableShader(SM_TEXTURE); GLint posLoc = renderSystem->ShaderGetPos(); GLint tex0Loc = renderSystem->ShaderGetCoord0(); GLint uniColLoc = renderSystem->ShaderGetUniCol(); GLfloat col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; struct PackedVertex { float x, y, z; float u1, v1; } vertex[4]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of the vertices GLuint vertexVBO; GLuint indexVBO; glUniform4f(uniColLoc,(col[0]), (col[1]), (col[2]), (col[3])); // Setup vertex position values vertex[0].x = rd.left; vertex[0].y = rd.top; vertex[0].z = 0; vertex[0].u1 = 0.0f; vertex[0].v1 = 0.0; vertex[1].x = rd.right; vertex[1].y = rd.top; vertex[1].z = 0; vertex[1].u1 = m_u; vertex[1].v1 = 0.0f; vertex[2].x = rd.right; vertex[2].y = rd.bottom; vertex[2].z = 0; vertex[2].u1 = m_u; vertex[2].v1 = m_v; vertex[3].x = rd.left; vertex[3].y = rd.bottom; vertex[3].z = 0; vertex[3].u1 = 0.0f; vertex[3].v1 = m_v; glGenBuffers(1, &vertexVBO); glBindBuffer(GL_ARRAY_BUFFER, vertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(PackedVertex)*4, &vertex[0], GL_STATIC_DRAW); glVertexAttribPointer(posLoc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, x))); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, sizeof(PackedVertex), BUFFER_OFFSET(offsetof(PackedVertex, u1))); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(tex0Loc); glGenBuffers(1, &indexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*4, idx, GL_STATIC_DRAW); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, 0); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(tex0Loc); glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &vertexVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDeleteBuffers(1, &indexVBO); renderSystem->DisableShader(); #else CRenderSystemGLES* renderSystem = dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem()); renderSystem->EnableGUIShader(SM_TEXTURE); GLint posLoc = renderSystem->GUIShaderGetPos(); GLint colLoc = renderSystem->GUIShaderGetCol(); GLint tex0Loc = renderSystem->GUIShaderGetCoord0(); GLint uniColLoc = renderSystem->GUIShaderGetUniCol(); GLfloat col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat ver[4][2]; GLfloat tex[4][2]; GLubyte idx[4] = {0, 1, 3, 2}; //determines order of triangle strip glVertexAttribPointer(posLoc, 2, GL_FLOAT, 0, 0, ver); glVertexAttribPointer(colLoc, 4, GL_FLOAT, 0, 0, col); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, 0, 0, tex); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(colLoc); glEnableVertexAttribArray(tex0Loc); glUniform4f(uniColLoc,(col[0]), (col[1]), (col[2]), (col[3])); // Setup vertex position values ver[0][0] = ver[3][0] = rd.left; ver[0][1] = ver[1][1] = rd.top; ver[1][0] = ver[2][0] = rd.right; ver[2][1] = ver[3][1] = rd.bottom; // Setup texture coordinates tex[0][0] = tex[0][1] = tex[1][1] = tex[3][0] = 0.0f; tex[1][0] = tex[2][0] = m_u; tex[2][1] = tex[3][1] = m_v; glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, idx); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(colLoc); glDisableVertexAttribArray(tex0Loc); renderSystem->DisableGUIShader(); #endif glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); }
void COverlayGlyphGL::Render(SRenderState& state) { if ((m_texture == 0) || (m_count == 0)) return; glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, m_texture); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glMatrixModview.Push(); glMatrixModview->Translatef(state.x, state.y, 0.0f); glMatrixModview->Scalef(state.width, state.height, 1.0f); glMatrixModview.Load(); #ifdef HAS_GL CRenderSystemGL* renderSystem = dynamic_cast<CRenderSystemGL*>(CServiceBroker::GetRenderSystem()); renderSystem->EnableShader(SM_FONTS); GLint posLoc = renderSystem->ShaderGetPos(); GLint colLoc = renderSystem->ShaderGetCol(); GLint tex0Loc = renderSystem->ShaderGetCoord0(); std::vector<VERTEX> vecVertices( 6 * m_count); VERTEX *vertices = &vecVertices[0]; for (int i=0; i<m_count*4; i+=4) { *vertices++ = m_vertex[i]; *vertices++ = m_vertex[i+1]; *vertices++ = m_vertex[i+2]; *vertices++ = m_vertex[i+1]; *vertices++ = m_vertex[i+3]; *vertices++ = m_vertex[i+2]; } GLuint VertexVBO; glGenBuffers(1, &VertexVBO); glBindBuffer(GL_ARRAY_BUFFER, VertexVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(VERTEX)*vecVertices.size(), &vecVertices[0], GL_STATIC_DRAW); glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(VERTEX), BUFFER_OFFSET(offsetof(VERTEX, x))); glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(VERTEX), BUFFER_OFFSET(offsetof(VERTEX, r))); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, GL_FALSE, sizeof(VERTEX), BUFFER_OFFSET(offsetof(VERTEX, u))); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(colLoc); glEnableVertexAttribArray(tex0Loc); glDrawArrays(GL_TRIANGLES, 0, vecVertices.size()); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(colLoc); glDisableVertexAttribArray(tex0Loc); glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &VertexVBO); renderSystem->DisableShader(); #else CRenderSystemGLES* renderSystem = dynamic_cast<CRenderSystemGLES*>(CServiceBroker::GetRenderSystem()); renderSystem->EnableGUIShader(SM_FONTS); GLint posLoc = renderSystem->GUIShaderGetPos(); GLint colLoc = renderSystem->GUIShaderGetCol(); GLint tex0Loc = renderSystem->GUIShaderGetCoord0(); // stack object until VBOs will be used std::vector<VERTEX> vecVertices( 6 * m_count); VERTEX *vertices = &vecVertices[0]; for (int i=0; i<m_count*4; i+=4) { *vertices++ = m_vertex[i]; *vertices++ = m_vertex[i+1]; *vertices++ = m_vertex[i+2]; *vertices++ = m_vertex[i+1]; *vertices++ = m_vertex[i+3]; *vertices++ = m_vertex[i+2]; } vertices = &vecVertices[0]; glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, sizeof(VERTEX), (char*)vertices + offsetof(VERTEX, x)); glVertexAttribPointer(colLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(VERTEX), (char*)vertices + offsetof(VERTEX, r)); glVertexAttribPointer(tex0Loc, 2, GL_FLOAT, GL_FALSE, sizeof(VERTEX), (char*)vertices + offsetof(VERTEX, u)); glEnableVertexAttribArray(posLoc); glEnableVertexAttribArray(colLoc); glEnableVertexAttribArray(tex0Loc); glDrawArrays(GL_TRIANGLES, 0, vecVertices.size()); glDisableVertexAttribArray(posLoc); glDisableVertexAttribArray(colLoc); glDisableVertexAttribArray(tex0Loc); renderSystem->DisableGUIShader(); #endif glMatrixModview.PopLoad(); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); }