# OpenGL Quake III Map in Direct3D

This topic is 5133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there, for an engine I'm doing I'm using Quake III maps and converting them (using a custom converter) to my own level format and the data itself seems fine, but when rendered in Direct3D it's wayyyy off. (The data and indices and stuff I haven't changed at all yet, so it's essentially the exact same as a Quake III map) I've coded a Quake III map viewer in OpenGL before, but it looks like the primitive drawing functions are very different, here is what I'm using to render the world:
	for( uint Loop = 0; Loop < m_pWorld->m_FaceCount; Loop++ )
m_pDev->DrawPrimitive( D3DPT_TRIANGLEFAN, m_pWorld->m_pFaces[Loop].VertexOffset, m_pWorld->m_pFaces[Loop].VertexCount );


If someone doesn't know the answer to this question, but knows a nice editor I can use, or both [grin], that would be easy to write a converter or exporter for, it'd help me out a lot. Q3Radiant is what I'm using currently with the qbsp map compiler- Too much work involved in coding my own map compiler. - Jordan

##### Share on other sites
Are you sure the Quake III maps have all their data in triangle fans? I saw another Q3 map render, called Titan I think, and I am pretty sure it used triangle strips. I'm not sure though, but give it a go.

##### Share on other sites
Doesn't it use triangle lists?

This package has a Quake 3 level compiler and renderer, which might help you:
http://www.gamedev.net/columns/hardcore/geomorph/Terrain_Src.zip

##### Share on other sites
The coordinate system in Quake3 (and Doom 3 for that matter) is not the one people usually use. Swap the Y and Z coordinate of everything in the bsp-file and you should be fine.

Bsp-files from the original q3map-tool created triangle-fans but new maps do not use triangle-fans and you will get very weird results trying to render them that way. Instead they should be rendered as type 3 surfaces. More information can be found in this thread. It uses OpenGL in the example, but you should be able to figure out how to do it, otherwise just ask and I'll try to explain in more detail.

##### Share on other sites
I've tried using triangle strips, triangle fans, normal triangle lists and all. In the converter I already switched the Y and Z components of the vertex and the components Y and Z components of the normal too. That wouldn't account for the holes I'm getting in the world, I should have been more specific with the errors I'm getting. Some of the primitives are perfect, but others are completely off, with some vertices connect to vertices that aren't even close to be where they should. Whatever I try doesn't seem to work, I think I might have to make up some triangle data in the converter and just use that, rebuild the geometry to be just simple triangle, triangle, triangle, etc.

I'm still looking for another editor if anyone knows any...

- Jordan

##### Share on other sites
From your description it sounds like you are rendering the face incorrectly. Changing from triangle fans to triangles won't work since the list of triangles to draw is not stored in the same way. Look at the post I linked to above or look for a file format desciription that describes how to render type 3 faces and use that for type 1 faces as well. Disregard anything they say about type 1 faces, I have yet to find a file format description describing type 1 faces correctly.

##### Share on other sites
The image he showed as an example of a bad map looks exactly like what I have. Sorry, I didn't see it the first time, I was at school and... I just didn't see it. I should sleep more. [grin]
I'll get back to you guys whether it works or not. [smile]

- Jordan

##### Share on other sites
Well, I still can't get it unfortunately, not only am I used to quake3's old format, I'm new to direct3d, I've been using it about a week now. Here's what I've got right now, it's still rendering wrong though:

	for( uint Loop = 0; Loop < m_pWorld->m_FaceCount; Loop++ )	{		m_pDev->SetStreamSource( 0, m_pWorldBuffer, m_pWorld->m_pFaces[Loop].VertexOffset * sizeof(CVertex), sizeof(CVertex) );		m_pDev->DrawPrimitive( D3DPT_TRIANGLELIST, m_pWorld->m_pFaces[Loop].MeshVertOffset, m_pWorld->m_pFaces[Loop].VertexCount / 3 );	}

VertexOffset = vertex component in Faces list (vertex offset)
MeshVertOffset = offset from the plane-indexed Meshverts lump
VertexCount = n_meshverts in Face list

I would really appreciate any help from someone who's done this in Direct3D or someone who can just help me

##### Share on other sites
The StreamSource-line looks correct, but the drawprimitive-call is what's causing the trouble. You have to create an index buffer out of the Meshverts in the map and then use DrawIndexedPrimitive.

Assuming you've set the meshvert index-buffer as the active one using m_pDev->SetIndices() your loop should look something like this.

for( uint Loop = 0; Loop < m_pWorld->m_FaceCount; Loop++ ){	m_pDev->SetStreamSource( 0, m_pWorldBuffer, m_pWorld->m_pFaces[Loop].VertexOffset * sizeof(CVertex), sizeof(CVertex) );	m_pDev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_pWorld->m_pFaces[Loop].MeshVertCount, m_pWorld->m_pFaces[Loop].MeshVertOffset, m_pWorld->m_pFaces[Loop].MeshVertCount/3);}

I haven't tried this code myself, so it's probably not perfectly accurate. But hopefully it will give you an idea of the data is arranged. The indices are in the meshverts-list and they start at meshvertlist[face->meshvertoffset]. The indices in meshverts for each face begin at 0 so you have to point into the vertex buffer since the indices are not relative to the beginning of the vertex buffer but to vertexlist[face->vertexoffset]. You can either use the parameters in DrawIndexedPrimitive to accomplish this offset in the vertex buffer or you can do it the way you have done it. This might seem trickier than it is. Try making a drawing of it or something, that usually helps in understanding.

If it's not clear please tell me and I'll try to give a better explanation.

##### Share on other sites
(This is Jordan)

I've tried almost everything now with next to no avail, I might retry it again from scratch cuz everything's so messy now, or I might just use another editor. This seems like an awful lot of work, but I probably should know and learn it all, might as well be now. We'll see. I'll post another message later but I'm really getting tired and pissed off at it. I'm gonna play some half-life2 and go to bed, have a good one for now guys.

- Jordan

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013628
×