Jump to content

Can't get SetMaterial to work in C++


Wchris
 Share

Recommended Posts

If it's not a bug what's wrong with my code please ?

 

What can be causing this

 

#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->SetPosition(0, 0, -5);

light = DirectionalLight::Create();
light->SetRotation(45, 45, 45);
light->SetPosition(0, 0, -3);
//Create a material
Material* material = Material::Create();
material->Load("Materials\Developer\Bluegrid.mat");
//material->SetColor(1, 0, 0);
//Create a model and apply the material to it
Model* model = Model::Box();
model->SetPosition(0, -2, 0);
model->SetScale(10, 1, 10);
model->SetMaterial(material);
return true;
}
bool App::Loop()
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Time::Update();
world->Update();
world->Render();
context->DrawRect(100, 10, 100, 60);
context->Sync();
return true;
}

 

This is what I get

post-44-0-81567800-1465558591.jpg

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

In C++ and Lua you have to do this to get a slash, otherwise you are specifying something else:

material->Load("Materials\\Developer\\Bluegrid.mat");

 

For example, \" will specify a quote symbol inside a string.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Sorry guys, really wish it would be so easy ... but it's still diving me mad.

Something must be wrong in my setup sad.png

\\ are converted into / in log see screenshot + no error but still no good

post-44-0-97497600-1465589124_thumb.jpg

 

Crossing fingers someone will figure out

Even tryed with full path as you can see... but in both case log says material and texture is loaded. Just not applyed.

 

PS: I'll switch to beta buid now, maybe it'll help

 

EDIT: same result with beta, I think I need some sleep now ...

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

You sneaky person.

 

Material* material = Material::Create();
material->Load("Materials\Developer\Bluegrid.mat");

Should be:

Material* material = Material::Load("Materials\Developer\Bluegrid.mat");

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

You sneaky person.

Hi Josh smile.png

You found the explanation and saved my day. As a reward I'll tell you why we got there wink.png

 

I started from this example of setmaterial http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetmaterial-r183 and could have avoided the pitfall if I used the load exemple http://www.leadwerks.com/werkspace/page/api-reference/_/material/materialload-r266

 

If you refer to the fact that my avatar remained invisible, it was because since LE3 armageddon and loss of possibility to use other alternative programming languages I was not using the engine anymore, but I still loved Leadwerks for the simplicity of it's command set and visuals. Since I was not using the engine and had nothing to exchange with the community I decided to go invisible.

 

Why I'm back after so long ? Well, because after version 4 of Leadwerks I realized that people who were working on a SWIG wrapper finally failed. So I started writing my own called PWIG (Pascal Wrapper and Interface Generator). This forced me to install VC++ 2013 and learn the basics of C++ to tell my generator how to code in C++ for me.

 

Stay relax, I perfectly understand you want to promote lua since it provides you more visibility of what people can achieve; it makes sense. Since I do not have enought knowledge of C++ and cannot provide good support I will not promote my work and this time it will stay a private work. So don't fear an alternate programming way will emerge, it won't happen this time.

 

I really like some of the C++ features I discovered even if I still dislike his SMS style syntax. But one syntax flaw that made PWIG generate the code above is that there is no clear specification of the constructors in the class. In Pascal you must specify the keywords constructor/destructor but in C++ you can have as many as you want and specify nothing, so LOAD is a constructor that replaces CREATE but no way to know. And this leads to errors if you use a class and are not it's conceptor, errors that even you have difficulty to spot because of the ambiguity of the language.

 

Cheers

Thank you

post-44-0-49100700-1465634936.jpg

 

PS1 : I have awaken because VC++ can finally compile the code PWIG produces (It restored my willpower) but I have no idea how to solve the constructor enigma yet.

 

PS2: Please don't tkink I prefer Pascal because of the syntax. It's not really the main reason. I prefer it because of the Component API build on top and integrated with the IDE. It simplifies my work and makes the code easyer to manage. C++ is great but I prefer to work with a small subset than being overwhelmed, I just like simplicity. I guess people who love Blitzmax think the same way.

  • Upvote 1

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

You sneaky person.

 

Material* material = Material::Create();
material->Load("Materials\Developer\Bluegrid.mat");

Should be:

Material* material = Material::Load("Materials\Developer\Bluegrid.mat");

 

What strange is that I do the same mistake with model = Model::create(); Model->Load(...) instead of model = Model::load

and it works, do you have an idea why ? Sorry I'm still a beginner in C++.

Windows 7 home - 32 bits

Intel Quad Q6600 - nVidia GTX 460 1GB - 2 GB RAM

Link to comment
Share on other sites

Both will load and return a material or model. However, your code was applying a blank material you created to the surface. You're able to see the model because the model doesn't get "applied" to anything. It simply exists in the world, although your model variable still does not contain the model you loaded.

 

This should never ever be called this way:

material->Load("Materials\Developer\Bluegrid.mat");

 

Material::Load() is a static function, which basically means it is a global function for the class. C++ is a little lenient in that it lets you call it with an instance of the class, which I don't think is appropriate.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

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