FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Changing a material's color

5 posters

Go down

Changing a material's color Empty Changing a material's color

Post  meteors Thu Nov 27, 2008 4:54 pm

Hi all,

I am having trouble figuring out the correct way to change the color properties of an object's material.

This is the code I am using currently. It sets the wrong colors and the object is not shaded at all:

//the color_arr is mine
my_material->diffuse->x = obj->color_arr[0];
my_material->diffuse->y = obj->color_arr[1];
my_material->diffuse->z = obj->color_arr[2];
my_material->diffuse->w = obj->color_arr[3];

//render the material
sio2MaterialRender(my_material);

//render the object
sio2ObjectRender(my_object, sio2->_SIO2camera, 0);
sio2ObjectReset();
sio2MaterialReset();



Can someone please tell me the correct way to re-set a material's color, and render the object properly?


Thank you!! Kind regards,
-joshua
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  meteors Thu Nov 27, 2008 6:13 pm

Ok, sio2interactive helped me. All I was trying to do was alter the RGB of an existing material exported from Blender.

This works:

SIO2material *_SIO2material = ( SIO2material * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_MATERIAL, "material/myMaterial" );

_SIO2material->diffuse->x = 0;
_SIO2material->diffuse->y = 1;
_SIO2material->diffuse->z = 0;

// Render all the resources.
sio2ResourceRender( sio2->_SIO2resource,
sio2->_SIO2window,
_SIO2camera );



Thanks again!
-j
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Thu Mar 26, 2009 10:08 am

I used this method to change the material color for an object, and I used sio2LampEnableLight when render the object and material; the problem is that the object/material is not shaded. Why?

Another question (and more important): is it possible to link other material to an object in runtime mode?

Thank you

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  meteors Thu Mar 26, 2009 10:32 am

To change the material, you need to set:

my_object->_SIO2vertexgroup[0]->_SIO2material

...where _SIO2material is your custom material.

Regarding the shading, are you passing SIO2_RENDER_SOLID_OBJECT to sio2ResourceRender?


Best,
-j
meteors
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Fri Mar 27, 2009 4:01 am

Did you mean: my_object->_SIO2vertexgroup[0]->_SIO2material = my_material ?

I'm getting a bad access error.
what I need is duplicate an object ("loading time") an then set different materials for the duplicated at "runtime".

Thank you for reply, really appreciate it Smile

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  Jawdy Fri Mar 27, 2009 5:04 am

Check out Tutorial 06_1 some more (I've been re-reading and working with this one for a while now, heh)... in there the comments mention that SIO2 remembers the last used material, so if you're changing your material using diffuse->x or whatever, then use the sio2RenderMaterial() function.
Then you can use renderObject() which is also used in Tutorial 06_1 (used for drawing the selected object, the duplicated object and any instances of the selected object).

Hope that helps.
Jawdy
Jawdy

Posts : 65
Join date : 2009-03-17
Location : UK

http://www.gaslightgames.co.uk

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  sio2interactive Fri Mar 27, 2009 5:05 am

If you are changing some material value, you need to call sio2MaterialReset() if you want to make the change, as SIO2 try as much is it can (while not beeing too paranoid) to avoid changing values that have already been set.
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Fri Mar 27, 2009 5:21 am

Well, I don't want to change the material value. I just want to link other material (created on blender) to the duplicated objects when I load/create/duplicate them (before the render routine occurs), so that when I render all resources (including the duplicated), the duplicate objects are rendered with the material that I linked to them before.

Can I do this?

Thank you

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  Jawdy Fri Mar 27, 2009 5:24 am

I would think that you could create an SIO2material instance and assign it to your other material - do this in your templateLoading function, and then you could assign the material to the material property in the render section?
Or is that what you've already tried?
Jawdy
Jawdy

Posts : 65
Join date : 2009-03-17
Location : UK

http://www.gaslightgames.co.uk

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  sio2interactive Fri Mar 27, 2009 5:31 am

When you duplicate objects in run-time you are creating an instance (sio2ObjectDuplicate). If you want to have an independent object you need to do a hard copy, but this will require more memory. What type of material you need to render? like a simple color or another material with different textures etc...?
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Fri Mar 27, 2009 5:45 am

-----------------------------------
Exactly, the problem is that when I try to assign the materials to my duplicated objects it gives me a bad access error.
It seems the duplicated objects doesn't own a _SIO2vertexgroup[0]->_SIO2material but uses the material of the original object.

Am I right?
If yes, How can I init a vertexgroup and a material to the object?

Thanks for your effort Jawdy Smile
-----------------------------------

sio2 have just answer my question,

for now is a simple color. My goal here is to separate the things: object and materials (blender) and logic.
You could think that I could make all my objects with different materials in blender, but what if I really wanted to do a hard copy or just give the duplicated a vertex group and material?

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  Jawdy Fri Mar 27, 2009 5:50 am

andreassilva wrote:-----------------------------------
Exactly, the problem is that when I try to assign the materials to my duplicated objects it gives me a bad access error.
It seems the duplicated objects doesn't own a _SIO2vertexgroup[0]->_SIO2material but uses the material of the original object.

Am I right?
If yes, How can I init a vertexgroup and a material to the object?

Thanks for your effort Jawdy Smile
-----------------------------------

sio2 have just answer my question,

for now is a simple color. My goal here is to separate the things: object and materials (blender) and logic.
You could think that I could make all my objects with different materials in blender, but what if I really wanted to do a hard copy or just give the duplicated a vertex group and material?

No problem Smile
I'm still a complete newb when it comes to SIO2, but trying to learn and if I can help, then great - but the man who knows all the answers is sio2 Very Happy
Jawdy
Jawdy

Posts : 65
Join date : 2009-03-17
Location : UK

http://www.gaslightgames.co.uk

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Fri Mar 27, 2009 6:22 am

I'm a newb too

I hope he can help with me with this.

Can you sio2? :p

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  andreassilva Fri Mar 27, 2009 2:41 pm

Solved by linking the materials to objects in blender...

andreassilva

Posts : 22
Join date : 2009-02-19

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  compaqdrew Wed May 13, 2009 2:06 am

sio2interactive wrote:If you want to have an independent object you need to do a hard copy

Can you give a code sample for hard-copying an object? I'm trying to procedurally-generate the ground and would like to apply light transformations (slight shading, maybe some vertex transformations) to my ground tiles.

compaqdrew

Posts : 4
Join date : 2009-05-07

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  sio2interactive Wed May 13, 2009 2:13 am

Do you really have to? the process will be slow on the device and not really practical... and since some GL calls are necessary you need to do the operation within the main thread... What exactly are you trying to achieve...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  compaqdrew Wed May 13, 2009 2:30 am

I'm trying to procedurally generate an infinite world--as you walk forward, tiles in the far distance are generated, and tiles behind you are destroyed. Currently i'm using sio2ObjectDuplicate to take a single cube, duplicate it, and tile it about 300 times to cover the visible area. As you walk forward, tiles distantly behind you are relocated such that they are distantly in front of you. This happens just outside the clipping plane, creating the illusion of infinite space. That's all working rather well.

Of course, using the same ground tile everywhere is rather boring. I could just blender up a palette of ground tiles, but I'd prefer to manage my tiles procedurally. For instance: as you walk forward, tiles become darker, and in the other direction, they become lighter. Or: As you walk in one direction, the tiles increase in alpha. Of course, I would do this on a row-by-row basis so that I would only have to load 30-40 materials in memory at any one time.

compaqdrew

Posts : 4
Join date : 2009-05-07

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  sio2interactive Wed May 13, 2009 2:40 am

What I would do in your case is create another thread with a shared another GL context... all the loading / unloading should be done there...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  compaqdrew Wed May 13, 2009 2:42 am

sio2interactive wrote:What I would do in your case is create another thread with a shared another GL context... all the loading / unloading should be done there...

Fair enough. But as to my original question--how would you go about hard cloning an object?

compaqdrew

Posts : 4
Join date : 2009-05-07

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  sio2interactive Wed May 13, 2009 2:49 am

I don't think you should hard-copy them... I think you should stream your world from the SIO2 file...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Changing a material's color Empty Re: Changing a material's color

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum