PDA

View Full Version : Texturing NURBS



laprej
04-30-2004, 08:53 PM
Hey all,

While trying to texture map a NURBS, I had some problems. Every time I tried to do it, the end result was a striped object. I was just trying to put a window on my (crappy) car. Instead I got stripes of windows - not what I wanted. Here's some of the code:


//glEnable(GL_TEXTURE_2D);
//glBindTexture(GL_TEXTURE_2D, textures[2]);

gluBeginSurface(myNurbs);
/*
gluNurbsSurface(myNurbs,
10, u_knots, 8, v_knots,
4 * 3, 3, &ctl_points[0][0][0],
5, 4, GL_MAP2_TEXTURE_COORD_2);
*/Can anyone see the problem? Is this even where the problem lies? Or am I thinking about how to texture a NURBS the wrong way? I just imagined the texture was like a sheet that I threw over the surface. Anyway, thanks in advance.

ZbuffeR
05-01-2004, 12:03 AM
Or am I thinking about how to texture a NURBS the wrong way? I just imagined the texture was like a sheet that I threw over the surface.You think about it the right way.
It seems just to be the implementation, but I can't help much more.

laprej
05-03-2004, 02:34 PM
Could someone post a little snippet of code that textures their NURBS then? I would very much appreciate it.

laprej
05-03-2004, 03:00 PM
Could someone post a little snippet of code that textures their NURBS then? I would very much appreciate it.

plasmonster
05-03-2004, 03:31 PM
laprej,

It looks to me like you're on the right track, just be aware that each surface that you specify contains its own control point array. It's not clear from your code wheather the control points are for vertex positions or texture coords.

Here's the basic surface template:

gluBeginSurface(nobj);

gluNurbsSurface(nobj, . . ., GL_MAP2_TEXTURE_COORD_2);
gluNurbsSurface(nobj, . . ., GL_MAP2_NORMAL);
gluNurbsSurface(nobj, . . ., GL_MAP2_VERTEX_4);

gluEndSurface(nobj);

The idea is that you can separately specify the data in each surface. Keep an eye on your knot vector too, make sure the tex coords are what you expect for the effect your after. Also, check that all your dimensions are what the gl expects, as outlined in the docs.

There are alternatives to this explicit texture surface. You could use the texture gen functionality instead, if one such mapping would suffice.

laprej
05-03-2004, 09:25 PM
Well, I have the Red Book, and I read that little chunk of pseudo code. I would really like to see some real code because I've tried a bunch of stuff and nothing is working... After my first post I quickly realized I was accidentally passing in the vertex coords (as you mentioned) which was the reason I was getting the striping effect. I corrected that, but I still can't get it to look right.

plasmonster
05-03-2004, 10:41 PM
I corrected that, but I still can't get it to look right.
I have no idea what "right" means. Give us an idea of what it is you are trying to do, and maybe some code showing how you are trying to achieve it. The code you gave above, save one line, is a series of comments.

If you have the red book, then you have a good demo in front of you. The only thing the demo lacks is texture coordinate setup, so this must be your problem area. If you are looking for a texture fit across the surface, then your tex coord control would be points in a unit grid: s in [0,1], t in [0,1]. I would think the knot vector provided in the demo would do nicely, but I don't know what effect you're after.