Archived

This topic is now archived and is closed to further replies.

weasalmongler

Rendering Bezier Patches from Quake 3 bsp levels

Recommended Posts

weasalmongler    205
Right, the time has come for me to render the patches section of the Quake3 level. I imaging this is done with functions like : glMap2f(...); glMapGrid2f(...); glEvalMesh2(...); How do I now render the patches section, does anybody have a code example or pseudocode or something, as I am finding it very complicated. I am not sure how to use the vertices from the level to generate a proper sized curved surface. Can anybody help? -Weasalmongler

Share this post


Link to post
Share on other sites
CheeseGrater    122
You use the vertices as control points on a quadratic bezier surface.

Quadratic bezier surfaces are 3x3, so if you have a greater size in a patch, you can divide it up into 3x3 patches and render those. Remember that they have to share a set of control points to be continuous, though. A 3x5 patch, for example, is really a pair of 3x3 patches.

I can''t help you out with any code examples for EvalMesh, unfortunately. I tesselate my patches at load time to save on CPU resources. With EvalMesh you''re stuck tesselating at run time unless you are willing to use display lists.

Share this post


Link to post
Share on other sites
weasalmongler    205
Thanks, your information has helped.

I still feel that I need more help though, could anybody else go into more detail and maybe give some pseudocode examples.

-Weasalmongler

Share this post


Link to post
Share on other sites
CheeseGrater    122
If you''re going to use OpenGL evaluators, the Red Book has code examples for drawing bezier surfaces.

If you want to tesslate the bezier patches yourself, then read over the articles about bezier curves and patches here on gamedev, which are pretty decent.

There really isn''t anything special about quake3''s bezier patches, so any tutorials you find (like the one at Nehe''s site) are going to apply.

Share this post


Link to post
Share on other sites
weasalmongler    205
Sorry, I know how to use the OpenGL evaluators, I have some information on it already from books, what I don''t understand is how to use the Quake3 format of faces and meshes etc, with the evaluators to draw the surface, How do I only pass the proper vertices to the functions?

-Weasalmongler

Share this post


Link to post
Share on other sites
CheeseGrater    122
Well, the Red Book uses a [4][4][3] array for a cubic surface. Cubic''s have 4x4 control points, and quake uses quadratics, which have 3x3 control points. Copy the vertex positions pointed to by the face into a [3][3][3] array of floats.

Then just follow the existing example. The only other change ought to be knocking down the ''order'' argument of the evaluator by one.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster

Ok. You can download all the source code to the red book from
ftp://sgigate.sgi.com/pub/opengl/opengl1_1.tar.Z

If you can''t get there either, here is the relevant section:

Example 12-2 : Bézier Surface: bezsurf.c


#include <GL/gl.h>
#include <GL/glu.h>
#include <stdlib.h>
#include <GL/glut.h>

GLfloat ctrlpoints[4][4][3] = {
{{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0},
{0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}},
{{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0},
{0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}},
{{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0},
{0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}},
{{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0},
{0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
};

void display(void)
{
int i, j;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPushMatrix ();
glRotatef(85.0, 1.0, 1.0, 1.0);
for (j = 0; j <= 8; j++) {
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
glEnd();
glBegin(GL_LINE_STRIP);
for (i = 0; i <= 30; i++)
glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
glEnd();
}
glPopMatrix ();
glFlush();
}

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
0, 1, 12, 4, &ctrlpoints[0][0][0]);
glEnable(GL_MAP2_VERTEX_3);
glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
}

Share this post


Link to post
Share on other sites
weasalmongler    205
I''ve got it drawing, but now the textures are incorrectly mapped!!!! I also cannot draw the lightmap for some reason (via multitexturing or multipass multitexturing). THIS IS DRIVING ME CRAZY!!!!

-Weasalmongler

Share this post


Link to post
Share on other sites
CheeseGrater    122
The texture coordinates (and the colors) are a bezier surface as well, so you need to set up a couple more evaluators for them. If you can FTP down that example source, one of the other chapter 12 examples should be doing this.

Share this post


Link to post
Share on other sites
weasalmongler    205
I can apply some textures OK with that technique (which was actually the one I was using anyway), but some of the side parts of the map are incorrectly mapped, so the front is OK, but the side looks like its clamped, with the nasty lines going all down it.

Also, I still can't multitexture the lightmaps on correctly, as I don't think the functions that I am using work with hardware multitexturing.

-Weasalmongler

[edited by - weasalmongler on March 20, 2002 4:41:15 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
to CheeseGrater:

What sense would it make to interpolate the colors ? Until now I did not came across a Q3 patch that needed colors in any way... And I can not imagine that a bezier-curve in RGB space is of any use :-)

skynet

Share this post


Link to post
Share on other sites
CheeseGrater    122
quote:
Original post by Anonymous Poster
to CheeseGrater:

What sense would it make to interpolate the colors ? Until now I did not came across a Q3 patch that needed colors in any way... And I can not imagine that a bezier-curve in RGB space is of any use :-)

skynet


Well, if you want to use the vertex color info, you need to interpolate them some how. Since the texture coords are bezier generated and not linearly interpolated, I just figured that the color space would be the same. Especially since one out of 3 bezier curve control points doesn''t lie on the surface.

Y''know, that''s a good point about colors, though. I don''t think I''ve ever actually used that color information either, but my engine is still capable of displaying it if I ever write a shader that uses it.

I tesselate at load time, so it doesn''t really affect me other than a small memory hit and a slightly longer file load, but someone tesselating in real time might want to leave the colors out if they''re not used.

Weasalmongler: I haven''t seen the clamping problem that you describe, so I''m not certain what''s going on there. All I can say is you''re in for some debugging...

Share this post


Link to post
Share on other sites
weasalmongler    205
Yup, , Thanks for trying though. I''m relatively new to this sort of thing so I am bound to have lots of problems. Its the first time I have ever tried to load a file and render it (except for the ''.RAW'' text file.

-Weasalmongler

Share this post


Link to post
Share on other sites