// XXX Need a way to deal with blits with Camera/Lighting. void DisplayDeviceOpenGL::doBlitTexture(const TexturePtr& tex, int dstx, int dsty, int dstw, int dsth, float rotation, int srcx, int srcy, int srcw, int srch) { ASSERT_LOG(false, "DisplayDevice::doBlitTexture deprecated"); ASSERT_LOG(!tex, "Texture passed in was not of expected type."); const float tx1 = float(srcx) / tex->width(); const float ty1 = float(srcy) / tex->height(); const float tx2 = srcw == 0 ? 1.0f : float(srcx + srcw) / tex->width(); const float ty2 = srch == 0 ? 1.0f : float(srcy + srch) / tex->height(); const float uv_coords[] = { tx1, ty1, tx2, ty1, tx1, ty2, tx2, ty2, }; const float vx1 = float(dstx); const float vy1 = float(dsty); const float vx2 = float(dstx + dstw); const float vy2 = float(dsty + dsth); const float vtx_coords[] = { vx1, vy1, vx2, vy1, vx1, vy2, vx2, vy2, }; // Apply blend mode from texture if there is any. BlendEquationScopeOGL be_scope(*tex); BlendModeScopeOGL bm_scope(*tex); glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3((vx1+vx2)/2.0f,(vy1+vy2)/2.0f,0.0f)) * glm::rotate(glm::mat4(1.0f), rotation, glm::vec3(0.0f,0.0f,1.0f)) * glm::translate(glm::mat4(1.0f), glm::vec3(-(vx1+vy1)/2.0f,-(vy1+vy1)/2.0f,0.0f)); glm::mat4 mvp = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f) * model; auto shader = OpenGL::ShaderProgram::defaultSystemShader(); shader->makeActive(); getDefaultShader()->setUniformsForTexture(tex); shader->setUniformValue(shader->getMvpUniform(), glm::value_ptr(mvp)); shader->setUniformValue(shader->getColorUniform(), glm::value_ptr(glm::vec4(1.0f,1.0f,1.0f,1.0f))); // XXX the following line are only temporary, obviously. //shader->setUniformValue(shader->getUniform("discard"), 0); glEnableVertexAttribArray(shader->getVertexAttribute()); glVertexAttribPointer(shader->getVertexAttribute(), 2, GL_FLOAT, GL_FALSE, 0, vtx_coords); glEnableVertexAttribArray(shader->getTexcoordAttribute()); glVertexAttribPointer(shader->getTexcoordAttribute(), 2, GL_FLOAT, GL_FALSE, 0, uv_coords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableVertexAttribArray(shader->getTexcoordAttribute()); glDisableVertexAttribArray(shader->getVertexAttribute()); }
// テクスチャ設定 void Sprite::texture( TexturePtr tex ) { texture_ = tex; T3_NULL_ASSERT( texture_ ); float tex_width = static_cast<float>(tex->width()); float tex_height = static_cast<float>(tex->height()); size(Vec2(tex_width, tex_height)); adjustPivotByCenter(); }