Page 1 of 1

SMaterial problem

Posted: Sun Jan 13, 2008 10:16 pm
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!

Posted: Sun Jan 13, 2008 11:06 pm
by shogun
What does the console say?
Is texture != 0?
Did you check your texture paths?

Posted: Sun Jan 13, 2008 11:19 pm
by mk.1
Show your vertex data. Do they have uv coords applied?

Posted: Mon Jan 14, 2008 1:34 am
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 );

Posted: Mon Jan 14, 2008 6:53 pm
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.

Posted: Mon Jan 14, 2008 7:08 pm
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.

Posted: Mon Jan 14, 2008 7:41 pm
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! :)

Posted: Mon Jan 14, 2008 9:16 pm
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.

Posted: Mon Jan 14, 2008 11:16 pm
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!

Posted: Tue Jan 15, 2008 8:45 am
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.

Posted: Tue Jan 15, 2008 10:30 pm
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?

Posted: Wed Jan 16, 2008 9:37 am
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..

Posted: Wed Jan 16, 2008 9:52 pm
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 ...