jasonwkeith Posted May 20, 2014 Share Posted May 20, 2014 I am working my way through some of the sample code and making slight modifications. I am stuck with a very simple problem. I cannot manage to get a model to successfully render a texture. I am using slightly modified code from the leadwerks docs and a stock material. Any insight to my challenged code/thought process is appreciated. #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } bool App::Start() { window = Window::Create(); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->SetRotation(5, 0, 0); camera->Move(0, 0, -6); Light* light = DirectionalLight::Create(); light->SetRotation(35, 35, 0); Model* model = NULL; model = Model::Create(); model->SetColor(1.0, 0.0, 1.0); model->SetPosition(0, 0, 0); material = Material::Load("Materials/Concrete/concrete_dirty.mat"); Surface* surface = model->AddSurface(); surface->AddVertex(-0.5, -0.5, 0, 0, 0, -1); surface->AddVertex(0.5, -0.5, 0, 0, 0, -1); surface->AddVertex(0.5, 0.5, 0, 0, 0, -1); surface->AddVertex(-0.5, 0.5, 0, 0, 0, -1); surface->AddTriangle(2, 1, 0); surface->AddTriangle(0, 3, 2); surface->UpdateAABB(); model->SetMaterial(material,1); model->UpdateAABB(Entity::LocalAABB | Entity::GlobalAABB); return true; } bool App::Loop() { if (window->Closed() || window->KeyDown(Key::Escape)) return false; Time::Update(); world->Update(); world->Render(); context->Sync(); return true; } Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 20, 2014 Share Posted May 20, 2014 i think you need to perform an update on the surface... http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/surface/surfaceupdate-r638 EDIT - actually that works just fine for me in lua... all except for the SetMaterial command. The second argument is bool not integer and will cause an error. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
shadmar Posted May 20, 2014 Share Posted May 20, 2014 Add the UV map (last two) surface->AddVertex(-0.5, -0.5, 0, 0, 0, -1, -1,-1); surface->AddVertex(0.5, -0.5, 0, 0, 0, -1, 1,-1); surface->AddVertex(0.5, 0.5, 0, 0, 0, -1, 1,1); surface->AddVertex(-0.5, 0.5, 0, 0, 0, -1, -1,1); Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Edspirit Posted July 22, 2022 Share Posted July 22, 2022 On 5/20/2014 at 7:04 PM, shadmar said: Add the UV map (last two) surface->AddVertex(-0.5, -0.5, 0, 0, 0, -1, -1,-1); surface->AddVertex(0.5, -0.5, 0, 0, 0, -1, 1,-1); surface->AddVertex(0.5, 0.5, 0, 0, 0, -1, 1,1); surface->AddVertex(-0.5, 0.5, 0, 0, 0, -1, -1,1); Hi @shadmar, How do you add the UV map in independent Vertex index? I didn't see any documentation on this topic. Best Regards, Ed Quote Link to comment Share on other sites More sharing options...
Edspirit Posted July 24, 2022 Share Posted July 24, 2022 Hi All, I did figure it out that you need to setup the coords for the tex to make it work. Thanks all. Best Regards, Ed Quote Link to comment Share on other sites More sharing options...
reepblue Posted July 24, 2022 Share Posted July 24, 2022 This code below creates a plane model facing forward along the Z axis with a squared texture uniformly mapped. //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Leadwerks::Model* CreatePlaneModel() { auto mdl = Leadwerks::Model::Create(); auto surf = mdl->AddSurface(); surf->AddVertex(-0.5, -0.5, 0, 0, 0, -1); surf->AddVertex(0.5, -0.5, 0, 0, 0, -1); surf->AddVertex(0.5, 0.5, 0, 0, 0, -1); surf->AddVertex(-0.5, 0.5, 0, 0, 0, -1); surf->AddTriangle(2, 1, 0); surf->AddTriangle(0, 3, 2); surf->FlipNormals(); surf->Update(); surf->SetVertexTexCoords(1, Leadwerks::Vec2(0, 1), 0); // Bottom Left surf->SetVertexTexCoords(2, Leadwerks::Vec2(0, 0), 0); // Top Left surf->SetVertexTexCoords(3, Leadwerks::Vec2(1, 0), 0); // Top Right surf->SetVertexTexCoords(0, Leadwerks::Vec2(1, 1), 0); // Bottom Right mdl->UpdateAABB(Leadwerks::Entity::LocalAABB); mdl->UpdateAABB(Leadwerks::Entity::GlobalAABB); return mdl; } Hope this helps. 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Edspirit Posted July 24, 2022 Share Posted July 24, 2022 3 hours ago, reepblue said: surf->FlipNormals(); Thanks reepblue! I missed this piece of the code. Best Regards, Ed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.