
"GL.ShadeModel (ShadingModel.Smooth)" doesnt seem to have any effect
Posted Monday, 16 March, 2009 - 13:32 by darkante inHi.
I am working on a loader for AC3D models (www.ac3d.org).
Everything works fine except that my models are flat and not smooth :-P
Here's my InitGL function:
-----------------------------
private void InitGL() { /* Enable texture mapping */ GL.Enable(EnableCap.Texture2D); /* Enable smooth shading */ <b>GL.ShadeModel(ShadingModel.Smooth);</b> GL.Disable(EnableCap.ColorMaterial); GL.Enable(EnableCap.Lighting); GL.Enable(EnableCap.Light0); /* Set the background black */ GL.ClearColor(0.0f, 0.5f, 0.0f, 0.0f); /* Depth buffer setup */ GL.ClearDepth(1.0f); /* Enable depth testing */ GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.DepthTest); /* Really nice perspective calculations */ GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); }
-----------------------------
Using OpenTK, version 0.9.5, and the GLControl inside a Windows Form. Running Windows XP. Developing in Visual Studio 2008.
I've attached example code. You have to add OpenTK.dll and OpenTK.Utilities.dll to the bin\Debug folder manually (sorry, the zip file was to big to upload with them...)
Any help or pointers is much appreciated! :)
Thanks in advance,
Andreas
[Moderator edit: word wrapping in title]
| Attachment | Size |
|---|---|
| ExampleCode.zip | 121.07 KB |


Comments
Re: "GL.ShadeModel (ShadingModel.Smooth)" doesnt seem to ...
I skimmed through the code and nothing seemed out of place. How did you create the models? Did you enable smooth normals in your 3d editor?
Re: "GL.ShadeModel (ShadingModel.Smooth)" doesnt seem to ...
Thanks for the reply.
I've enabled smooth models in my 3d editor...
I calculate surface normals with the following function (from three points on the surface):
--------------------------------------------------------------
--------------------------------------------------------------
And here's what the ACNormal and ACVertex classes look like:
--------------------------------------------------------------
--------------------------------------------------------------
Hmm...
/Andreas
Re: "GL.ShadeModel (ShadingModel.Smooth)" doesnt seem to ...
I'm pretty sure this calculation will give you flat normals. What you can do is add a second pass which interpolates the normals of adjustent triangles, if their angle is less than 30 degrees. While this will give you smooth normals, they won't be as high quality as "true" normals, which are set by the artist in the editor.
I am not familiar with the AC3D file format: does it contain per-vertex normals? If it does, why don't you use them directly, instead of calculating face normals in code?
Edit: Try putting code in <code><code/> tags, it's easier to read. ;)
Re: "GL.ShadeModel (ShadingModel.Smooth)" doesnt seem to ...
Unfortunately, there are no pre-calculated normals. They have to be done in code...
I am considering moving on to another format. I want a easy format with skeletal animations and pre-calculated stuff like you mentioned :)
Got any recommendations? Whats your experience with Milkshape 3D?
Thanks for your help so far.
/Andreas
(Had a look at the AC3D format. Apparently there's a crease angle that can be used in my calculations................
http://www.inivis.com/forum/showthread.php?t=1821&highlight=crease+angle)