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.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sat Apr 04, 2009 12:57 pm
Sorry I have to ask again.
I just cannot put textures on the faces.
Code: Select all
vertbuf->Material.MaterialType = video::EMT_SOLID;
vertbuf->Material.Shininess = 20.0f;
vertbuf->Material.SpecularColor.set(255,255,255,255);
vertbuf->Material.setFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
video::ITexture* sample_texture =
SceneManager->getVideoDriver()->getTexture("/home/philipp/cprogs/ODF/odfl_reader/fake_texture.tga");
(whereas vertbuf is my meshbuffer)
The result: the whole level has the same color and it does not look like any of my textures.
I tried looking into the documentation, but I only found the Doxygen-stuff. Aren't there any tutorials about writing a meshloader?
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat Apr 04, 2009 3:50 pm
Just check the SMaterial API, you'll find a place to attach the textures.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sat Apr 04, 2009 3:55 pm
Oh sorry, I forgot to post this line:
Code: Select all
vertbuf->Material.setTexture(triangle_count, sample_texture);
(whereas triangle_count is iterated in a for-loop)
What's missing?
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat Apr 04, 2009 5:32 pm
triangleCount? You should use 0 for most material types. Iterate over the meshbuffers/materials for other parts of the mesh.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sat Apr 04, 2009 5:59 pm
Shall I create a meshbuffer for each material? Because, I don't see a function in the meshbuffer which lets me append a texture to a specified face.
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat Apr 04, 2009 8:30 pm
Yes, that's exactly the idea with meshbuffers. There are several reasons why you want to add a new meshbuffer. Logical grouping is one, but the main reason is to add a new material. Meshbuffers have the same material for all faces of that buffer.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sun Apr 05, 2009 10:29 am
So does it mean that some meshbuffers contain the same verts? Did I get that right? oO
So for sharing memory, could I put a vector of vertices into my loader and then just give the references to each meshbuffer? Is it allowed to put multiple references on one variable in C++? oO
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sun Apr 05, 2009 10:45 am
If you have multiple materials at the very same 3d position you'd need duplicated vertices, one for each mehsbuffer. Don't know what you mean by references in this context.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sun Apr 05, 2009 12:33 pm
core::array wants a reference:
So can I have a vertices and then push back its references in different arrays? (because I get strange valgrind SIGSEGV errors after the mesh is loaded)
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sun Apr 05, 2009 1:20 pm
OK, I found out that two references on the same variable are allowed.
Now that I put all in seperate meshbuffers, it is displayed wrong. Valgrind says, that memory is accessed which was deleted, which was latelely allocated using the push_back() function:
Code: Select all
face_buffer->Vertices.push_back( odfl_verts.at(second_point) );
These segfault errors occur AFTER the mesh is loaded.
Is a reallocation segfault issue known?
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Thu Apr 09, 2009 10:09 pm
Code: Select all
for(unsigned int count2=0; count2 < face_count; ++count2)
{
SMeshBuffer* face_buffer = new SMeshBuffer;
ODFLFile->read(&connects, 2);
short start_point, second_point, third_point;
ODFLFile->read(&start_point, 2);
ODFLFile->read(&second_point, 2);
face_buffer->Vertices.push_back(odfl_verts.at(start_point) );
face_buffer->Vertices.push_back(odfl_verts.at(second_point) ); // !!!
for(short connect_count=1; connect_count < connects-1; ++connect_count)
{
ODFLFile->read(&third_point, 2);
face_buffer->Vertices.push_back( odfl_verts.at(third_point) );
face_buffer->Indices.push_back(start_point);
face_buffer->Indices.push_back(second_point);
face_buffer->Indices.push_back(third_point);
second_point = third_point;
++triangle_count;
}
odfl_faces.push_back(tmp_face);
mesh->addMeshBuffer(face_buffer);
face_buffer->drop();
}
The line with the !!! seems to cause the segfault. The vertice I push back is ok, so I think the face_buf->Vertices is the problem.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sat Apr 11, 2009 4:49 pm
Please Help Me
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat Apr 11, 2009 8:47 pm
Well, your second index seems out-of-bounds. Simple like that.
L o
Posts: 44 Joined: Sun Mar 29, 2009 2:53 pm
Post
by L o » Sat Apr 11, 2009 9:38 pm
No, definetely not. It would have throw()n an exception in this case.
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Sat Apr 11, 2009 11:36 pm
Well, push_back won't bail out either.