Jump to content

Sprite with pixmap


Dreikblack
 Share

Go to solution Solved by klepto2,

Recommended Posts

When i'm trying to create Sprite with Pixmap texture it's invisible. Label and usual Sprites can be seen

image.thumb.png.44ff1017bcd348c9fc92d6f55f20fb2a.png

#include "UltraEngine.h"

using namespace UltraEngine;


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

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

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

	auto light = CreateBoxLight(world);
	light->SetRange(-10, 10);
	light->SetRotation(15, 15, 0);
	light->SetColor(2);

	//Create camera
	auto camera = CreateCamera(world);
	camera->SetClearColor(0.125);
	camera->SetPosition(0, 0, -3);
	camera->SetFov(70);

	auto default_font = LoadFont("Fonts\\arial.ttf");
	auto ui = CreateInterface(world, default_font, framebuffer->GetSize());
	ui->SetRenderLayers(2);
	ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
	auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
	uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
	uiCamera->SetRenderLayers(2);
	uiCamera->SetClearMode(CLEAR_DEPTH);

	auto label = CreateLabel("TEST GUI LABEL", 100, 100, 100, 50, ui->root);

	auto pixmap = CreatePixmap(iVec2(100, 100)); 
	pixmap->Fill(Vec4(0.5f, 0.5f, 1, 1));
	auto tex = CreateTexture(TEXTURE_2D, 100, 100, TEXTURE_RGBA, { pixmap }, 1, TEXTURE_CLAMP_UV);
	auto mtl = CreateMaterial();
	mtl->SetTexture(tex);
	mtl->SetShadow(false);
	mtl->SetTransparent(true);
	mtl->SetShaderFamily(LoadShaderFamily("Shaders/WidgetBlock.fam"));

    //Create pixmap sprite
    auto sprite = CreateSprite(world, 0, 0);
    sprite->SetPosition(0, 0);
  //  sprite->SetViewMode(SPRITEVIEW_BILLBOARD);
	sprite->SetMaterial(mtl);
	sprite->SetText("Test");
	sprite->SetRenderLayers(2);
	//Create usual sprite
    auto sprite2 = CreateSprite(world, 2, 2);
    sprite2->SetPosition(2, 0, 0);
    sprite2->SetViewMode(SPRITEVIEW_BILLBOARD);

    //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

  • Solution
2 hours ago, Dreikblack said:

When i'm trying to create Sprite with Pixmap texture it's invisible. Label and usual Sprites can be seen

image.thumb.png.44ff1017bcd348c9fc92d6f55f20fb2a.png

#include "UltraEngine.h"

using namespace UltraEngine;


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

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

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

	auto light = CreateBoxLight(world);
	light->SetRange(-10, 10);
	light->SetRotation(15, 15, 0);
	light->SetColor(2);

	//Create camera
	auto camera = CreateCamera(world);
	camera->SetClearColor(0.125);
	camera->SetPosition(0, 0, -3);
	camera->SetFov(70);

	auto default_font = LoadFont("Fonts\\arial.ttf");
	auto ui = CreateInterface(world, default_font, framebuffer->GetSize());
	ui->SetRenderLayers(2);
	ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
	auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
	uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
	uiCamera->SetRenderLayers(2);
	uiCamera->SetClearMode(CLEAR_DEPTH);

	auto label = CreateLabel("TEST GUI LABEL", 100, 100, 100, 50, ui->root);

	auto pixmap = CreatePixmap(iVec2(100, 100)); 
	pixmap->Fill(Vec4(0.5f, 0.5f, 1, 1));
	auto tex = CreateTexture(TEXTURE_2D, 100, 100, TEXTURE_RGBA, { pixmap }, 1, TEXTURE_CLAMP_UV);
	auto mtl = CreateMaterial();
	mtl->SetTexture(tex);
	mtl->SetShadow(false);
	mtl->SetTransparent(true);
	mtl->SetShaderFamily(LoadShaderFamily("Shaders/WidgetBlock.fam"));

    //Create pixmap sprite
    auto sprite = CreateSprite(world, 0, 0);
    sprite->SetPosition(0, 0);
  //  sprite->SetViewMode(SPRITEVIEW_BILLBOARD);
	sprite->SetMaterial(mtl);
	sprite->SetText("Test");
	sprite->SetRenderLayers(2);
	//Create usual sprite
    auto sprite2 = CreateSprite(world, 2, 2);
    sprite2->SetPosition(2, 0, 0);
    sprite2->SetViewMode(SPRITEVIEW_BILLBOARD);

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

    return 0;
}

2 Things:

  1. I believe the WidgetBlock Family is not the right one, better use the unlit family for this.
  2. your sprite with the material has a size of 0,0 so it will never be displayed no matter what you try to do
auto pixmap = CreatePixmap(iVec2(100, 100));
	pixmap->Fill(Vec4(0.5f, 0.5f, 1, 1));
	auto tex = CreateTexture(TEXTURE_2D, 100, 100, TEXTURE_RGBA, { pixmap }, 1, TEXTURE_CLAMP_UV);
	auto mtl = CreateMaterial();
	mtl->SetTexture(tex);
	mtl->SetShadow(false);
	mtl->SetTransparent(true);
	mtl->SetShaderFamily(LoadShaderFamily("Shaders/Unlit.fam"));

	//Create pixmap sprite
	auto sprite = CreateSprite(world, 40, 40);
	sprite->SetPosition(20, 20);
	//sprite->SetViewMode(SPRITEVIEW_BILLBOARD);
	sprite->SetMaterial(mtl);
	sprite->SetText("Test");
	sprite->SetRenderLayers(2);

with these changes the colored sprite is visible in the lower left corner.

  • Thanks 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

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...