动态纹理创建/生成 [英] Dynamic Texture Creation/Generation

查看:70
本文介绍了动态纹理创建/生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我为我目前正在处理的后勤软件创建了一个纹理原型,以便为附近公司的保留区域提供免费和占用存储容量。



原型看起来像这样:纹理原型

然后将纹理映射到对象上并分配给保留区域。



到目前为止这么好,现在到了实际问题!



纹理必须根据分配的保持区域改变其外观。

根据保留区域必须更改的功能是:

- 文本(即不同存储材料的不同名称)

- 左边是弯曲的黄色条,右边是弯曲的红色条(取决于自由量和取得的存储容量,条形或多或少地填充弯曲条纹,也可能改变颜色)



现在我真的不知道如何处理这个问题。很明显,我不能提前为所有区域的所有fillstates创建纹理,然后在运行时选择相应的一个。



所以我的想法是不知何故以某种方式在运行时生成这些纹理或创建某种具有可交换部分的模板。



你认为这可以实现吗?如果是,那你的方法是什么?您之前是否遇到过类似的问题,或者您是否有任何窍门或技巧如何以最佳方式处理此任务?也许你知道一个可以支持我的库吗?



现在我正在使用VS 2012 C ++,OpenSG for Scene generation和OpenGL。



提前谢谢大家!

Hi guys,
I created a texture protoype for a logistic software I currently work on, to visualize free and taken storage capacities of holding areas for a company in the neighbourhood.

The prototype looks something like this: Texture Prototype
The texture is then mapped on an object and assigned to a holding area.

So far so good, now to the actual problem!

The texture has to change its appearance depending on the holding area it is assigned to.
The features that have to change according to the holding area are:
- the Text (i.e. different name for different stored materials)
- the curved yellow bar on the left and the curved red bar on the right (depending on the amount of free and taken storage capacity the bar fill up the curved bars more or less and may also change their colors)

Now I don't really know how to approach this problem. It is obvious that I can't create textures for all fillstates of all the areas in advance and then just pick the respective one at runtime.

So my idea was to somehow generate these textures on runtime somehow or create some kind of template with exchangable parts.

Do you think that would be realisable? If yesm what would be your approach? Did you guys encounter some similar problem before or do you have any tipps or tricks how to approach this task best way? Maybe you know a library that can support me on this?

Right now I'm working with VS 2012 C++, OpenSG for Scene generation and OpenGL.

Thanks Guys in advance!

推荐答案

是的,这既可行也相对容易。我是否使用GDI或GDI +取决于我是否想要支持透明度/渐变 - 您的图像看起来显示由半透明黑线生成的阴影,因此需要gdi +才能完全复制它。



这里有一些让你入门的东西。它非常简单,只是一系列圆圈,线条和弧形,带有淡淡的文字。



Yes, this is both possible and relatively easy. Whether or not I used GDI or GDI+ would depend on whether or not I wanted to support transparency/gradients - your image appears to show shadows generated by semi-opaque black lines, so gdi+ would be needed to duplicate it exactly.

Here's a little something to get you started. Its quite simple, just a series of circles, lines and arcs with a touch of text.

HBITMAP zCreateDibSection(HDC hdc, int width, int height, int bitCount)
{
    BITMAPINFO bi;
    ZeroMemory(&bi, sizeof(bi));
    bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
    bi.bmiHeader.biWidth = width;
    bi.bmiHeader.biHeight = height;
    bi.bmiHeader.biPlanes = 1;
    bi.bmiHeader.biBitCount = bitCount;
    bi.bmiHeader.biCompression = BI_RGB;
    return CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, 0,0,0);
}

// should allow for size specification
// I've hardcoded it to 256x256 pixels
HBITMAP genTexture(wchar_t *text1, wchar_t *text2, COLORREF col1, COLORREF col2, int fillPercent1, int fillPercent2)
{
    HPEN origPen, thinBlack, thickBlack;
    HBRUSH origBrush, bkgBrush, col1Brush, col2Brush;
    HDC memDC;
    HBITMAP origBmp, result;
    RECT imgRect;
    RECT outerRc, innerRc;
    HFONT origFont, font;

    memDC = CreateCompatibleDC(0);
    origBmp = (HBITMAP) GetCurrentObject(memDC, OBJ_BITMAP);
    origPen = (HPEN) GetCurrentObject(memDC, OBJ_PEN);
    origBrush = (HBRUSH) GetCurrentObject(memDC, OBJ_BRUSH);
    origFont = (HFONT) GetCurrentObject(memDC, OBJ_FONT);

    result = zCreateDibSection(memDC, 256, 256, 24);
    SelectObject(memDC, result);

    SetRect(&innerRc, 256/4,256/4,256*3/4-1,256*3/4-1);
    SetRect(&outerRc, 0,0,255,255);

    bkgBrush = CreateSolidBrush( RGB(204,204,204) );
    FillRect(memDC, &outerRc, bkgBrush);

    thickBlack = CreatePen(PS_SOLID, 2, 0);
    SelectObject(memDC, thickBlack);
    SelectObject(memDC, GetStockObject(WHITE_BRUSH));
    Ellipse(memDC, outerRc.left,outerRc.top,outerRc.right,outerRc.bottom);

    BeginPath(memDC);
        col2Brush = CreateSolidBrush(col2);
        SelectObject(memDC, col2Brush);
        MoveToEx(memDC,128,128,NULL);


        AngleArc(memDC, 127,127,126,-90.0,(fillPercent2 / 100.0)*180.0);
        LineTo(memDC,128,128);
    EndPath(memDC);
    FillPath(memDC);


    BeginPath(memDC);
        col1Brush = CreateSolidBrush(col1);
        SelectObject(memDC, col1Brush);
        MoveToEx(memDC,128,128,NULL);
        AngleArc(memDC, 127,127,126,-90.0,-(fillPercent1 / 100.0)*180.0);
        LineTo(memDC,128,128);
    EndPath(memDC);
    FillPath(memDC);


    //  inner circle
    SelectObject(memDC, GetStockObject(WHITE_BRUSH));
    Ellipse(memDC, 64,64,(256*0.75)-1,(256*0.75)-1);

    MoveToEx(memDC, 66, 128, NULL);
    LineTo(memDC, 190,128);

    RECT textRectTop, textRectBottom;
    SetRect(&textRectTop, 64,64,192,128);
    SetRect(&textRectBottom, 64,128,192,192);

    font = CreateFont(-24, 0, 0, 0, 0, FALSE, FALSE, FALSE, 1, 0, 0, 0, 0, "Verdana");// ("Ms Shell Dlg"));
    SelectObject(memDC, font);
    DrawTextW(memDC, text1, -1, &textRectTop, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
    DrawTextW(memDC, text2, -1, &textRectBottom, DT_CENTER|DT_VCENTER|DT_SINGLELINE);


    // clean-up
    SelectObject(memDC, origBrush);
    SelectObject(memDC, origPen);
    SelectObject(memDC, origBmp);
    SelectObject(memDC, origFont);


    DeleteObject(col1Brush);
    DeleteObject(col2Brush);
    DeleteObject(font);
    DeleteObject(thickBlack);
    DeleteObject(bkgBrush);

    DeleteDC(memDC);
    return result;
}

void onPaint(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    HBITMAP img = genTexture(L"Text 1",L"Text 2", RGB(255,192,0),RGB(192,80,77),  50,66);
    HDC hdc;
    PAINTSTRUCT ps;
    HBITMAP old;
    HDC memDC;

    memDC = CreateCompatibleDC(0);
    old = (HBITMAP)SelectObject(memDC, img);

    hdc = BeginPaint(hwnd, &ps);

    BitBlt(hdc, 0,0, 255,255, memDC, 0,0, SRCCOPY);

    EndPaint(hwnd, &ps);
    SelectObject(memDC, old);
    DeleteObject(img);
}


BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
    }
    return TRUE;

    case WM_CLOSE:
    {
        EndDialog(hwndDlg, 0);
    }
    return TRUE;

    case WM_PAINT:
        onPaint(hwndDlg, wParam, lParam);
        return 0;

    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
        }
    }
    return TRUE;
    }
    return FALSE;
}


这篇关于动态纹理创建/生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆