loading effect shows nothing

Started by
28 comments, last by Comboy 15 years, 11 months ago
Quote:Original post by KOzymandias
As I see it, you only set the effect, you do not actually draw the parts...


i set part.effect to blinn and i draw the mesh, did i miss something, there's no such a thing part.draw
Advertisement
foreach (ModelMeshPart part in mesh.MeshParts){  blinn.Begin();  foreach (EffectPass pass in this.blinn.CurrentTechnique.Passes)  {     pass.Begin();     blinn.Parameters["ColorTexture"].SetValue(diffuseMap);     blinn.CommitChanges();     part.Effect = blinn;     pass.End();  }  blinn.End();}


Drawing needs to take place within the effect loop, not after.

In the above loop, it doesn't appear that you draw anything. Look at the previous posts and see if the comments make sense now.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

ok but if i put mesh.draw before effect.end it shows the error message

Begin cannot be called again until End has been successfully called.
I'm not familar with XNA but the XNA reference at Microsoft says, about ModelMesh.Draw:

"Draws all the ModelMeshPart objects in this mesh, using their current Effect settings."

I'm guessing but something like the following appears to be more appropriate.

blinn.Parameters["ColorTexture"].SetValue(diffuseMap);foreach (ModelMeshPart part in mesh.MeshParts){     part.Effect = blinn;}mesh.Draw();

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

this is from apply an effect sample from microsoft
protected override void Draw(GameTime gameTime)        {            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);            graphics.GraphicsDevice.RenderState.CullMode =                CullMode.CullClockwiseFace;            graphics.GraphicsDevice.VertexDeclaration =                    cubeVertexDeclaration;            graphics.GraphicsDevice.Indices = indexBuffer;            graphics.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionColor.SizeInBytes);            // The effect is a compiled effect created and compiled elsewhere            // in the application.            effect.Begin();            foreach (EffectPass pass in effect.CurrentTechnique.Passes)            {                pass.Begin();                graphics.GraphicsDevice.DrawIndexedPrimitives(                    PrimitiveType.TriangleList,                    0,                    0,                    cubeVertices.Length,                    0,                    12);                pass.End();            }            effect.End();            base.Draw(gameTime);        }    }


it use base.draw after ending the effect

That's an overloaded function for the Draw() method.

What an overloaded (perhaps it's "overridden" in XNA) method does is "intercept" the Draw method for your object.

In other words, when mesh.Draw() is called, it executes the overridden method.

Note in the example that base.Draw() is called after all the parts are drawn.

However, the info at Microsoft for ModelMeshPart states:

"It is not necessary to use this class directly. In advanced rendering scenarios, it is possible to draw using ModelMeshPart properties in combination with the vertex and index buffers on ModelMesh. However, in most cases, ModelMesh.Draw will be sufficient."

You may be making the process much more complicated than it needs to be.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

i use (modelmesh mesh) and then mesh.draw
so i'm using the modelmesh.draw

and for (modelmeshpart part) there's nothing like part.draw

so i can't draw part and i can't draw mesh before ending the effect, that confuses me

on the other hand modelmesh doesn't have effect property, it's only with the modelmeshpart
Microsoft, on ModelMesh Draw: "Draws all the ModelMeshPart objects in this mesh, using their current Effect settings."

Why not give it a try?

1. load the effect
2. set the effect parameters (like the texture)
3. load the mesh
4. set the effect for each part

Since you don't change the effect settings, you should only need to do the above once.

Then call mesh.Draw().

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

believe me or not I can't draw the mesh or meshparts before ending the effect.

someone please tell me if i'm doing it in right order, many days have passed and i still can't do anything,
blinn = Content.Load<Effect>("blinn");


Mmm...shouldn't it be
blinn = Content.Load<Effect>("blinn.fx");


Or your file has got no extension?

This topic is closed to new replies.

Advertisement