#164709 - quip - Sat Nov 15, 2008 5:56 am
I know simonjhall has done a lovely quake 1 release for the ds.
So I was wondering what I am I doing wrong here in rendering the faces.
Particularly I'm having trouble with the edges.
Right now I"m just trying to get it to render properly.
Code: |
v16 verts[3][16];
for(int x = 0; x < bsp->numFaces; ++x){
glColor3b( x & 255, x & 255, x&255); // just colors for now
glBegin(GL_TRIANGLES);
int numEdges = bsp->faces[x].numEdges;
for(int i = 0; i < numEdges; i++){
int index = listOfEdges[ bsp->faces[x].firstEdge + i ];
int vertex;
if( index > ){ // Normal order
vertex = edges[ index ].v[0];
verts[0][i] = vertices[ vertex ].x;
verts[1][i] = vertices[ vertex ].y;
verts[2][i] = vertices[ vertex ].z;
} else {
vertex = edges[ -index ].v[1];
verts[0][i] = vertices[ vertex ].x;
verts[1][i] = vertices[ vertex ].y;
verts[2][i] = vertices[ vertex ].z;
}
glVertex3v16(verts[0][i], verts[1][i], verts[2][i]);
}// endfor i
glEnd();
}//end for x
|
Last edited by quip on Sat Nov 15, 2008 8:31 pm; edited 1 time in total
#164710 - Dr Salvador - Sat Nov 15, 2008 7:04 am
only problem with quake ds i ever get is the framerate
#164712 - elhobbs - Sat Nov 15, 2008 3:21 pm
the faces are polygons. not triangles.so, you need to manually treat it like a triangle fan.
pseudo code
glBegin(GL_TRIANGLES);
for(i=2;i<numverts;i++)
{
glVertex(vert[0]);
glVertex(vert[i-1]);
glVertex(vert[i]);
}
glEnd();
If you have not already done this - you will need to scale all of the quake float vertices to fit into the ds fixed point vertex format. I used float*2 - that keeps the quake vertices within the ds range of -8 to 8 in 4.12 fixed point format.
you can download the source code for quakeds,cquake, or even the original id software release. that would answer most of your questions.
this will be way too many triangles for the ds. you need to use the visibility info to reduce the visible set.
#164714 - silent_code - Sat Nov 15, 2008 3:36 pm
Welcome to the scene. :^)
Please post some images, so that we can take a look at your edge problem. Thanks.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#164739 - quip - Mon Nov 17, 2008 2:05 am
Thank you. Always nice to enter a new scene. :)
@elhobbs, my map is very simple right now. Just one cube! so I'm ignoring PVS for now. :), also in the quake source they rendered it like this, so I think I'm doing it correctly. I also implemented your way of triangle fan as well as my way. (I'm not sure my way is correct tho).
Quake 1:
Code: |
pedges = currententity->model->edges;
lnumverts = fa->numedges;
vertpage = 0;
for (i=0 ; i<lnumverts ; i++)
{
lindex = currententity->model->surfedges[fa->firstedge + i];
if (lindex > 0)
{
r_pedge = &pedges[lindex];
verts[0][i] = r_pcurrentvertbase[r_pedge->v[0]];
}
else
{
r_pedge = &pedges[-lindex];
verts[0][i] = r_pcurrentvertbase[r_pedge->v[1]];
}
}
|
My triangle fan:
Code: |
void triangleFan(BSPFVertex *vertices, int tris){ // tris should be numverts - 2
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
for(int x = 0; x < tris; ++x){
glColor3b(x & 255, x & 255, x & 255);
glBegin(GL_TRIANGLES);
glVertex3v16(vertices[0].x, vertices[0].y, vertices[0].z); // We'll use the first one as the reference
glVertex3v16(vertices[x * 4 + 1].x, vertices[x * 4 + 1].y, vertices[ x * 4 + 1].z); // We'll use the first one as the reference
glVertex3v16(vertices[x * 4 + 2].x, vertices[x * 4 + 2].y, vertices[ x * 4 + 2].z); // We'll use the first one as the reference
glEnd();
}
}
|
Also here are screenshots of the result.
The first image is the rendering using elhobbs' triangle fan way.
The second is usingmy triangle fan way.
And the last is what it should look like(i obviously drew that one in :P).
The Cube is pretty much 9 quads to one side with six sides.
[Images not permitted - Click here to view it]
#164740 - elhobbs - Mon Nov 17, 2008 2:38 am
the code that I gave you does not need to be broken down into triangles. all of the polygons in quake 1 are convex. this means that for an n vertex polygon it can be rendered as n-2 triangles such that each triangle uses the vertices 0,i-1,i for i =2 to i = n-1
here is an image to sort it out
this quad can be rendered as two triangles
0,1,2
and
0,2,3
I know this method works as it is the method I used in cquake. this probably is not the optimal way to do it but it is the easiest way that does not require storing the bsp data in a different format. one issue that it does not address is tjunctions, but it does not cause a problems for the most part. in case you are not familiar - tjunctions are colinear vertices that are added to prevent seams in adjacent polygons that share partial edges.
#164741 - quip - Mon Nov 17, 2008 2:55 am
@elhobbs
Interesting. You method and mines give the same result but I'll just use yours. I'm guessing maybe the way I'm plotting the vertices is wrong?
I made a PC version and with lines, it's correctly drawn, but with GL_POLYGON, it also looks incorrect, same as with the ds version.
Do you see anything wrong in the way I get the vertices?
#164749 - elhobbs - Mon Nov 17, 2008 9:19 am
here is some code pulled directly from BuildSurfaceDisplayList in gl_rsurf.c
Code: |
medge_t *pedges, *r_pedge;
float *vec;
pedges = currentmodel->edges;
lnumverts = fa->numedges;
for (i=0 ; i<lnumverts ; i++)
{
lindex = currentmodel->surfedges[fa->firstedge + i];
if (lindex > 0)
{
r_pedge = &pedges[lindex];
vec = r_pcurrentvertbase[r_pedge->v[0]].position;
}
else
{
r_pedge = &pedges[-lindex];
vec = r_pcurrentvertbase[r_pedge->v[1]].position;
}
}
|
I am assuming that this level loads correctly on the original pc version of quake, yes?
are you sure you are loading the data correctly?
you may also want to try and draw it as lines. since the ds does triangles and quads only, you need to render each line as a triangle with the second and third points the same.
how did you convert the quake float vertices to ds format? floattov16 and floattof32 (or most likely any libnds macros) will not provide usable results as the they will overflow.
do you have your code someplace where I can look at it as a whole?
#164785 - quip - Fri Nov 21, 2008 6:40 am
I for one am an idiot!
Instead of just using the bspfile.h from the quake source, I defined the types by looking at online documentation.
And after looking @ it a little while more, I realized the Surfaces edges were int s not short s like i had.
Silly errors, but problem solved.
Thanks all and especially thanks elhobbs. :D