Jump to content

Brush and Face SetMaterial() does not work?


Dreikblack
 Share

Go to solution Solved by Dreikblack,

Recommended Posts

Brush changes only a color after setting a material. Maybe i missing something or doing it wrong.

Putting brush->Build(); after brush->SetMaterial(mtl); don't change anything.

Made a model box just to show how i  do expect brush to look so it's not light or something.

image.thumb.png.749c0448a1a38328a98f57007cd27021.png

#include "UltraEngine.h"

using namespace UltraEngine;

const WString remotepath = "https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets";

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a world
    auto world = CreateWorld();

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.8);
    camera->Turn(35, 0, 0);
    camera->Move(0, 0, -2);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-20, 20);
    light->SetArea(20, 20);
    light->SetRotation(35, 35, 0);

    //Create brush
    auto brush = CreateBrush(world);
   // brush->SetColor(0, 0, 1);

    //Add brush vertices
    float w = 1; float h = 1; float d = 1;
    brush->AddVertex(w * 0.5, h * 0.5, d * 0.5);
    brush->AddVertex(-w * 0.5, h * 0.5, d * 0.5);
    brush->AddVertex(-w * 0.5, h * 0.5, -d * 0.5);
    brush->AddVertex(w * 0.5, h * 0.5, -d * 0.5);
    brush->AddVertex(w * 0.5, -h * 0.5, d * 0.5);
    brush->AddVertex(-w * 0.5, -h * 0.5, d * 0.5);
    brush->AddVertex(-w * 0.5, -h * 0.5, -d * 0.5);
    brush->AddVertex(w * 0.5, -h * 0.5, -d * 0.5);

    //Add faces
    auto face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(1);
    face->AddIndice(2);
    face->AddIndice(3);

    auto mtl2 = CreateMaterial();
    mtl2->SetTexture(LoadTexture(remotepath + "/Materials/tiles.dds"));
    face->SetMaterial(mtl2);

    face = brush->AddFace();
    face->AddIndice(4);
    face->AddIndice(5);
    face->AddIndice(6);
    face->AddIndice(7);

    face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(1);
    face->AddIndice(5);
    face->AddIndice(4);

    face = brush->AddFace();
    face->AddIndice(2);
    face->AddIndice(3);
    face->AddIndice(7);
    face->AddIndice(6);

    face = brush->AddFace();
    face->AddIndice(1);
    face->AddIndice(2);
    face->AddIndice(6);
    face->AddIndice(5);

    face = brush->AddFace();
    face->AddIndice(0);
    face->AddIndice(3);
    face->AddIndice(7);
    face->AddIndice(4);

    //Finalize the brush
    brush->Build();

    auto mtl = CreateMaterial();
    mtl->SetTexture(LoadTexture(remotepath + "/Materials/tiles.dds"));
    brush->SetMaterial(mtl);

    auto model = CreateBox(world);
    model->SetPosition(2, 0, 0);
    model->SetMaterial(mtl);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...