コード例 #1
0
ファイル: Rendering.cpp プロジェクト: alexanderkunz/raindrop
void Sprite::Render()
{
    if (!ShouldDraw())
        return;

    UpdateTexture();

    SetBlendingMode(BlendingMode);

    // Assign our matrix.
    SetShaderParameters(ColorInvert, AffectedByLightning, Centered, false, BlackToTransparent);

    Mat4 Mat = GetMatrix();
    WindowFrame.SetUniform(U_MVP, &(Mat[0][0]));

    // Set the color.
    WindowFrame.SetUniform(U_COLOR, Red, Green, Blue, Alpha);

    SetTexturedQuadVBO(UvBuffer);
    DoQuadDraw();

    DrawLighten();

    FinalizeDraw();
}
コード例 #2
0
ファイル: Rendering.cpp プロジェクト: alexanderkunz/raindrop
void DrawTexturedQuad(Image* ToDraw, const AABB& TextureCrop, const Transformation& QuadTransformation,
    const EBlendMode &Mode, const ColorRGB &InColor)
{
    if (ToDraw)
        ToDraw->Bind();
    else return;

    WindowFrame.SetUniform(U_COLOR, InColor.Red, InColor.Green, InColor.Blue, InColor.Alpha);

    SetBlendingMode(Mode);

    float CropPositions[8] = {
        // topright
        TextureCrop.P2.X / (float)ToDraw->w,
        TextureCrop.P2.Y / (float)ToDraw->h,
        // bottom right
        TextureCrop.P2.X / (float)ToDraw->w,
        TextureCrop.P1.Y / (float)ToDraw->h,
        // bottom left
        TextureCrop.P1.X / (float)ToDraw->w,
        TextureCrop.P1.Y / (float)ToDraw->h,
        // topleft
        TextureCrop.P1.X / (float)ToDraw->w,
        TextureCrop.P2.Y / (float)ToDraw->h,
    };

    TextureBuffer->AssignData(CropPositions);
    SetTexturedQuadVBO(TextureBuffer);

    DoQuadDraw();

    FinalizeDraw();
}
コード例 #3
0
ファイル: Rendering.cpp プロジェクト: alexanderkunz/raindrop
void DrawPrimitiveQuad(Transformation &QuadTransformation, const EBlendMode &Mode, const ColorRGB &Color)
{
    Image::BindNull();
    WindowFrame.SetUniform(U_COLOR, Color.Red, Color.Green, Color.Blue, Color.Alpha);

    SetBlendingMode(Mode);

    Mat4 Mat = QuadTransformation.GetMatrix();
    WindowFrame.SetUniform(U_MVP, &(Mat[0][0]));

    // Assign position attrib. pointer
    SetPrimitiveQuadVBO();
    DoQuadDraw();
    FinalizeDraw();

    Image::ForceRebind();
}
コード例 #4
0
        // Called by Rocket when it wants to render application-compiled geometry.
        void RenderInterface::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
        {
            InternalGeometryHandle *Handle = (InternalGeometryHandle*)geometry;
            Mat4 tMatrix = glm::translate(Mat4(), Vec3(translation.x, translation.y, 0));

            glDisable(GL_DEPTH_TEST);
            glDepthMask(GL_FALSE);
            SetBlendingMode(BLEND_ALPHA);

            // bind texture
            if (Handle->tex)
                Handle->tex->Bind();
			else {
				Image::BindNull();
			}

            SetShaderParameters(false, false, false, false, false, Handle->tex == nullptr);
            WindowFrame.SetUniform(U_COLOR, 1, 1, 1, 1);
            WindowFrame.SetUniform(U_MVP, &(tMatrix[0][0]));

            // bind VBOs
            Handle->vert->Bind();
            glVertexAttribPointer(WindowFrame.EnableAttribArray(A_POSITION), 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);

            Handle->uv->Bind();
            glVertexAttribPointer(WindowFrame.EnableAttribArray(A_UV), 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);

            Handle->color->Bind();
            glVertexAttribPointer(WindowFrame.EnableAttribArray(A_COLOR), 4, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);

            Handle->indices->Bind();
            glDrawElements(GL_TRIANGLES, Handle->num_indices, GL_UNSIGNED_INT, 0);

            FinalizeDraw();

            glEnable(GL_DEPTH_TEST);
            glDepthMask(GL_TRUE);
        }
コード例 #5
0
ファイル: Rendering.cpp プロジェクト: alexanderkunz/raindrop
void TruetypeFont::Render(const std::string &In, const Vec2 &Position, const Mat4 &Transform)
{
    const char* Text = In.c_str();
    int Line = 0;
    glm::vec3 vOffs(Position.x, Position.y + scale, 0);

    if (!IsValid)
        return;

    UpdateWindowScale();

    SetBlendingMode(BLEND_ALPHA);

    SetShaderParameters(false, false, false, false, false, true);
    WindowFrame.SetUniform(U_COLOR, Red, Green, Blue, Alpha);
    SetPrimitiveQuadVBO();

    try
    {
        utf8::iterator<const char*> it(Text, Text, Text + In.length());
        utf8::iterator<const char*> itend(Text + In.length(), Text, Text + In.length());
        for (; it != itend; ++it)
        {
            CheckCodepoint(*it); // Force a regeneration of this if necessary
            codepdata &cp = GetTexFromCodepoint(*it);
            unsigned char* tx = cp.tex;
            glm::vec3 trans = vOffs + glm::vec3(cp.xofs, cp.yofs, 0);
            glm::mat4 dx;

            if (*it == 10) // utf-32 line feed
            {
                Line++;
                vOffs.x = Position.x;
                vOffs.y = Position.y + scale * (Line + 1);
                continue;
            }

            dx = Transform * glm::translate(Mat4(), trans) * glm::scale(Mat4(), glm::vec3(cp.w, cp.h, 1));

            // do the actual draw?
            if (cp.gltx == 0)
            {
                glGenTextures(1, &cp.gltx);
                glBindTexture(GL_TEXTURE_2D, cp.gltx);

                glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

                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_MIN_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

                glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, cp.tw, cp.th, 0, GL_ALPHA, GL_UNSIGNED_BYTE, tx);
            }
            else
                glBindTexture(GL_TEXTURE_2D, cp.gltx);

            WindowFrame.SetUniform(U_MVP, &(dx[0][0]));

            DoQuadDraw();

            utf8::iterator<const char*> next = it;
            next++;
            if (next != itend)
            {
                float aW = stbtt_GetCodepointKernAdvance(info.get(), *it, *next);
                int bW;
                stbtt_GetCodepointHMetrics(info.get(), *it, &bW, NULL);
                vOffs.x += aW * virtualscale + bW * virtualscale;
            }
        }
    }
#ifndef NDEBUG
    catch (utf8::exception &ex)
    {
        Utility::DebugBreak();
        Log::Logf("Invalid UTF-8 string %s was passed. Error type: %s\n", ex.what());
    }
#else
    catch (...)
    {
        // nothing
    }
#endif

    FinalizeDraw();
    Image::ForceRebind();
}