SMaterial problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

SMaterial problem

Post by radubolovan »

here is the code:

Code: Select all

SMaterial material;
material.Lighting = false;
material.ZBuffer = true;
material.ZWriteEnable = true;
material.BackfaceCulling = false;
material.TextureLayer[0].TextureWrap = video::ETC_CLAMP;
material.setTexture( 0, texture );
here is the draw:

Code: Select all

videoDriver->setMaterial( m_material );
videoDriver->drawIndexedTriangleFan( vertices, 4, indices, 2 );
vertices are in trigonometric order
and indices are 0, 1, 2, 3

The problem that I have is that the texture is black :(
it is an png with some transparency with 128x128 pixels

Why is that? What have I done wrong?

Thank you!
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

What does the console say?
Is texture != 0?
Did you check your texture paths?
mk.1
Posts: 76
Joined: Wed Oct 10, 2007 7:37 pm

Post by mk.1 »

Show your vertex data. Do they have uv coords applied?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

are the code snippets exactly the same as you use in your prog ???
then there is an error with the material name/variable !!!
you declare a var named material:

Code: Select all

SMaterial material;
but then you use m_material:

Code: Select all

videoDriver->setMaterial( m_material );
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

1) texture is not NULL:
2)
console wrote:Loaded texture: home/radu/Proiecte/3D_data/Example1/textures/sun/sun.png
3) Vertex data is calculated dinamically ... the uv coords ... hm ... which parameter contains these?

4)
Acki wrote:are the code snippets exactly the same as you use in your prog ???
then there is an error with the material name/variable !!!
you declare a var named material:

Code: Select all

SMaterial material;
but then you use m_material:

Code: Select all

videoDriver->setMaterial( m_material );
I've pasted wrong ... the cod in my programm is good.

Code is like this:

Code: Select all

SMaterial material;
videoDriver->setMaterial( material );
More info: I work on Linux & OpenGL.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

3) Vertex data is calculated dinamically ... the uv coords ... hm ... which parameter contains these?
video::S3DVertex::TCoords
If you did not set them you will not get texture displayed correctly.

Also you need to set MaterialType parameter of SMaterial to use transparent texture else with default one, transparent pixels will not be rendered transparent. You probably want to set it to EMT_TRANSPARENT_ALPHA_CHANNEL.
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

new code:

Code: Select all

m_tex[0].Pos = vector3df( m_pos.X-0.5f, m_pos.Y+0.5f, m_pos.Z );
m_tex[1].Pos = vector3df( m_pos.X-0.5f, m_pos.Y-0.5f, m_pos.Z );
m_tex[2].Pos = vector3df( m_pos.X+0.5f, m_pos.Y-0.5f, m_pos.Z );
m_tex[3].Pos = vector3df( m_pos.X+0.5f, m_pos.Y+0.5f, m_pos.Z );

m_tex[0].TCoords = vector2df( 0.0f, 0.0f );
m_tex[1].TCoords = vector2df( 1.0f, 0.0f );
m_tex[2].TCoords = vector2df( 1.0f, 1.0f );
m_tex[3].TCoords = vector2df( 0.0f, 1.0f );
m_pos is a 3d position
and

Code: Select all

material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
Before that I saw a black rectangle ... now I see a black circle ... my texture has colors!
But I solved the problem with:

Code: Select all

m_tex[0].Color = m_tex[1].Color = m_tex[2].Color = m_tex[3].Color = SColor( 255, 255, 255, 255 );
Thank you very much to all of you! :)
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You should set all vertex attributes to render them properly ...position, UV, normal, color. Also make sure you set lighting for your node properly. If you are not using any light source ...turn it off else everything will be black.
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

Now I know :)
Anyway ... if you read my first post you will se that I setted most things ... the only problem was this:

Code: Select all

m_tex[0].Color = m_tex[1].Color = m_tex[2].Color = m_tex[3].Color = SColor( 255, 255, 255, 255 );
Thank you again!
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You did not set Normal ...this may be ok if you disabled lighting but if lighting is on you might get weird results.
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

arras wrote:You did not set Normal ...this may be ok if you disabled lighting but if lighting is on you might get weird results.
I'm working on it! :)
I'm trying to make a sun ... I've calculated positions and it's work just fine ... now the normals should be the vector:
(sunpos - cam_pos).normalized();
I think ...
//later
And I have two more problems ... I have trying to draw some debug info ... for example all sun positions like this:

Code: Select all

for( nIndex = 0; nIndex < SECONDS_PER_DAY; nIndex++ )
{
	GLubyte a = 255;
	GLubyte r = 255;
	GLubyte g = 0;
	GLubyte b = 0;

	glBegin( GL_POINTS );
	glColor4ub( r, g, b, a );
	glVertex3f( m_positions[nIndex].X, m_positions[nIndex].Y, m_positions[nIndex].Z );
	glEnd();
}
Problem nr1: if I don't set

Code: Select all

material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL;
all points are black
Problem nr2: if I set that nothing is visible
What's wrong?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Code: Select all

now the normals should be the vector:
(sunpos - cam_pos).normalized();
I think ... 
Most of the time not! Normaly you want normal to be perpendicular to the surface it belongs to. Of course you may want to to "smooth" them in order that your mesh does not show too much edges. Normal is independent on light source.

As for your other questions, I have no idea. Somebody else might help..
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

arras wrote:Most of the time not! Normaly you want normal to be perpendicular to the surface it belongs to. Of course you may want to to "smooth" them in order that your mesh does not show too much edges. Normal is independent on light source.

As for your other questions, I have no idea. Somebody else might help..
(sunpos - cam_pos).normalized(); it is perpendiculary on the "sun" because I orientate the texture to be perpendicular to (sunpos - cam_pos).normalized(); so the camera will always see it as a circle (or something).

But the direction (sunpos - cam_pos).normalized(); is not quite good! the correct one is (sunpos + cam_pos).normalized(); ... so the normals be directioned to the camera.

I hope my english is understanable...

Answers to the other questions will help me very much ...
Post Reply