PDA

View Full Version : Bezier Mesh ... No Normals :o(

Andrew Jameson
06-25-2003, 01:00 PM
I'm trying to produce a bezier patch with different textures front/back. It all works but I'd be really grateful if someone could tell me how to get the normals set correctly ... they're not working at all ... if I add a glScalef(1,-1,1) then the top face seems to work ... it's as if the normals that are calculated are 180 degrees wrong !

Much appreciated ... well an answer / solution will be ...

Andrew

------------------------

const
ControlPoints : Array[0..3, 0..3, 0..2] of GLfloat = (
((-5/2, -1.0, 4), (-5/2, -1.0, 2), (-5/2, -1, -2), (-5/2, -1, -4)),
((-5/4, -1.0, 4), (-5/4, -1.0, 2), (-5/4, -1, -2), (-5/4, -1, -4)),
(( 5/4, -1.0, 4), ( 5/4, -1.0, 2), ( 5/4, -1, -2), ( 5/4, -1, -4)),
(( 5/2, -2.0, 4), ( 5/2, -1.0, 2), ( 5/2, -1, -2), ( 5/2, -1, -4)));
textres: array [0..1, 0..1, 0..1] of GLfloat =
(((0.0, 1.0), (0.0, 0.0)), ((1.0, 1.0), (1.0, 0.0)));

..
..

glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, @textres);
glMap2f(GL_MAP2_VERTEX_3,
0, 1, // The range of the surface's U parameter (usually 0..1).
3, // The number of values between vertices in the U direction.
4, // The order of the curves in the U direction.
0, 1, // The range of the V parameter.
12, // The number of values between consecutive V vertices.
4, // The order of the V curves.
@ControlPoints); // Pointer to the control points.

glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_MAP2_TEXTURE_COORD_2);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);

glColor3ub(200, 200, 200);

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, @cMaterialSpecularFrontCover);
glBindTexture(GL_TEXTURE_2D, GLTextures[cNotebookCover]);
glMapGrid2f(12, 0.0, 1.0, 12, 0.0, 1.0);
glEvalMesh2(GL_FILL, 0, 12, 0, 12);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, @cMaterialSpecularDefault);

glFrontFace(GL_CW); // Draw the back ... reverse the winding.
glBindTexture(GL_TEXTURE_2D, GLTextures[cNotebookBack]);
glEvalMesh2(GL_FILL, 0, 12, 0, 12);
glFrontFace(GL_CCW);

glDisable(GL_MAP2_VERTEX_3);
glDisable(GL_MAP2_TEXTURE_COORD_2);
glDisable(GL_AUTO_NORMAL);

V-man
06-25-2003, 07:57 PM
Why this line?

- glFrontFace(GL_CW);

Andrew Jameson
06-25-2003, 09:03 PM
glFrontFace(GL_CW); - To get reverse winding for the back face texture.

I gave up with trying to get normals and assigned a fixed value of 1 and -1 for y. In the end the page curl was too subtle to notice as the page turns pretty quickly anyway ... so I dropped the idea.

This was my first experience of using bezier surfaces ... not a good experience and very little out there ... no examples anywhere on how to use glMap2f(GL_MAP2_NORMAL ..) and the glu functions seem equally elusive. I can see why NeHe's only bezier example generates the bezier in code rather than rely on library functions.

If anyone does have any examples or links to code to illustrate how to produce NURBS/Bezier patches that support textures and normals then I'm interested !

Thanks

Andrew

kansler
06-25-2003, 10:31 PM
Hi,

Maybe these pages help a bit:

http://www.jch.com/NURBS/

http://www.cepba.upc.es/docs/sgi_doc/SGI_Developer/books/OpenGL_PG/sgi_html/ch13.html

http://www.mat.ucsb.edu/~c.ramakr/articles/dls/nurbs.pdf

V-man
06-26-2003, 06:58 AM
The second link is from the Red Book and also included in the GLU examples.

>>>glFrontFace(GL_CW); - To get reverse winding for the back face texture.<<<

This doesn't give reverse winding. This tells GL *what is front and what is back*.

You can enable two sided lighting or just restructure your control grid to do it right.