Vertex Arrays in Quake 2

Discuss programming in the QuakeC language.
Post Reply
ArchAngel
Posts: 37
Joined: Fri Jun 03, 2011 7:33 pm

Vertex Arrays in Quake 2

Post by ArchAngel »

Ok, what's wrong here. I'm trying to replace some of the direct drawing code to use vertex arrays in Quake2. Here's the original code:

Code: Select all

v = p->verts[0];
				qglBegin (GL_POLYGON);
				for (i=0 ; i< nv; i++, v+= VERTEXSIZE)
				{
					qglMultiTexCoord2f( GL_TEXTURE0, v[3], v[4]);
					qglMultiTexCoord2f( GL_TEXTURE1, v[5], v[6]);
					qglVertex3fv (v);
				}
				qglEnd ();
And here's what I'm trying to replace it with... these should be equivalent as far as I'm aware but it's not working.

Code: Select all

qglEnableClientState(GL_VERTEX_ARRAY);
				qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
				qglVertexPointer(3, GL_FLOAT, VERTEXSIZE*sizeof(float), p->verts[0]);
				qglActiveTexture(GL_TEXTURE0);
				qglTexCoordPointer(2, GL_FLOAT, VERTEXSIZE*sizeof(float), p->verts[0]+3);
				qglActiveTexture(GL_TEXTURE1);
				qglTexCoordPointer(2, GL_FLOAT, VERTEXSIZE*sizeof(float), p->verts[0]+5);
				qglDrawArrays(GL_POLYGON,0,p->numverts);
				qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
				qglDisableClientState(GL_VERTEX_ARRAY);
Any thoughts?[/code]
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

first thing I notice is that you're not enabling texturecoord arrays on tmu 1, and specifying tmu0's texture array twice.

you need to use glClientActiveTexture to switch client tmus separately from server tmus, as well as to specify which units have texture coord arrays enabled.
ArchAngel
Posts: 37
Joined: Fri Jun 03, 2011 7:33 pm

Post by ArchAngel »

Thanks Spike, didn't realize the Array was per client TMU, I've not played with any multi-texturing in Arrays before.

I now need to figure out a way of moving the scrolling textures over to vertex arrays... not quite sure how to go about that.

Mods: Just spotted that I've posted this in the QuakeC forum rather than Engine or OpenGL... feel free to move it.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

texture matrix, vertex program, or preprocessing it in C.

If you're not using VBOs (which you probably should, tbh) then a simple loop in C to add X to a skin coord is not really a problem.

Small notes:
Nvidia docs say to call glVertexPointer last.
You will want to reduce the number of state changes you make. Thus store all similar polys in a list, and use the same array setup to draw all polys without reconfiguring the arrays (using base verticies).
You should avoid the use of GL_POLYGON - its typically not directly supported by the hardware. GL_TRIANGLES is typically the one to use on PC hardware, though consoles may prefer triangle strips.
You will also want to reduce the number of calls you make to glDrawArrays. Again, GL_TRIANGLES can be used to combine them (using glDrawElements/glDrawRangeElements and a dynamic element array).
Post Reply