parsing quake 3 map

Hello everyone.

I’m working on a quake 3 map engine, it might have to do with a game in the future, but for now it’s just a experiment.
So far I’ve got a lot set up, I’ve followed these guides:

http://graphics.cs.brown.edu/games/quake/quake3.html
http://graphics.stanford.edu/~kekoa/q3/
http://www.devmaster.net/articles/quake3collision/
http://www.flipcode.com/articles/article_q2bsp.shtml
http://www.oracledbaexpert.com/BSPTrees/BinarySpacePartitioningTrees.html

Those links should be helpful to anyone else trying to do what I’m doing.
So far I don’t even have rendering set up, but I’ve got quite a bit done. I’ve
set up a RandomAccessFile parser and am swapping the bytes cause
their in little endian format. I’ve got a function that gives the leaf the camera
is in and I find that leafs cluster and use the pvs to find the other visible
leaves by looping through the leaves and seeing which cluster is visible
from the cluster the camera is in. I have a frustum set up that takes the
opengl modelview matrix and projection matrix, multiplies them and extracts
the transformed frustum planes. I also have a render loop set up and it’s working
pretty well.

So what’s stopping me from just trying testing out how this all works? I’m
confused about how quake 3s multi-levels of indirection to the find vertexes
and indexes when starting from the leafs. I’m also confused about what
approach to take to render these? I’m thinking of using vertex arrays and
recreating them each time I loop, I could also have a display list for each
leaf but that might not be good for big maps. Another problem is that
all the textures are in jpeg and I’m not sure how to load those with
devil.

If anyone has any knowledge regarding this, I’d be extremely
grateful for any help. I’m very excited about this project and I think if
I know a few more simple things I might be able to get it working. Also
any more links you could give me regarding the specs for quake 3
would also be extremely helpful!

Thanks for help, also thanks for LWJGL!! :slight_smile:

I suggest that you download the official quake 3 source code. It should contain plenty usefull informations.
You can get it from IDs download page.

I think it contains all game related source code except the part I need which is about rendering.
Still useful, would be more useful if I knew c++ :slight_smile:

Hello everyone, I’ve found something pretty helpful:

http://www.paulsprojects.net/opengl/q3bsp/q3bsp.html

So I think I know how to render the polygons and I’ve been able to load in a jpeg texture,
my texture loading code is almost boiler plate but it seems that when I load the jpeg texture
it puts opengl in some bad state where it crashes at the render-loop.

This is my texture loading code:

package game.util;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.util.HashMap;

import org.lwjgl.LWJGLException;
import org.lwjgl.devil.IL;
import org.lwjgl.opengl.GL11;

public class TextureManager {

private static HashMap textures = new HashMap();

/**
 * Texture loading using DevIL Example created by Mark Bernard
 */
public static Texture loadTexture(String path) {
	if (textures.containsKey(path)) {
		return (Texture) textures.get(path);
	}

	// Create a 4 byte ID
	IntBuffer image = ByteBuffer.allocateDirect(4).order(
			ByteOrder.nativeOrder()).asIntBuffer();

	// Generate a name for a image
	IL.ilGenImages(image);

	// Bind an image to the name
	IL.ilBindImage(image.get(0));

	String path2 = path.trim();
	if (path2.endsWith(".tga")) {
		IL.ilLoadFromStream(TextureManager.class.getClassLoader()
				.getResourceAsStream(path), IL.IL_TGA);
	} else if (path2.endsWith(".bmp")) {
		IL.ilLoadFromStream(TextureManager.class.getClassLoader()
				.getResourceAsStream(path), IL.IL_BMP);
	} else if (path2.endsWith(".png")) {
		IL.ilLoadFromStream(TextureManager.class.getClassLoader()
				.getResourceAsStream(path), IL.IL_PNG);
	} else if (path2.endsWith(".jpg")) {
		IL.ilLoadFromStream(TextureManager.class.getClassLoader()
				.getResourceAsStream(path), IL.IL_JPG);
	} else {
		throw new RuntimeException(
				"Can't load that file format, must be (tga, bmp, png)");
	}

	// Convert to RGB with Alpha
	IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);

	// Create a buffer to copy the image into
	ByteBuffer scratch = ByteBuffer.allocateDirect(IL
			.ilGetInteger(IL.IL_IMAGE_WIDTH)
			* IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4);

	// Copy image into buffer
	IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL
			.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGBA, IL.IL_BYTE,
			scratch);

	// Create memory for a name in opengl
	IntBuffer buf = ByteBuffer.allocateDirect(4).order(
			ByteOrder.nativeOrder()).asIntBuffer();

	// Generate a name
	GL11.glGenTextures(buf);

	// Bind the name
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));

	// Set parameters, linear filtering
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
			GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
			GL11.GL_LINEAR);

	// Pass the image data to opengl
	GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, IL
			.ilGetInteger(IL.IL_IMAGE_WIDTH), IL
			.ilGetInteger(IL.IL_IMAGE_HEIGHT), 0, GL11.GL_RGBA,
			GL11.GL_UNSIGNED_BYTE, scratch);

	
	Texture t = new Texture(buf.get(0), GL11.GL_TEXTURE_2D, IL
			.ilGetInteger(IL.IL_IMAGE_WIDTH), IL
			.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, 1);
	textures.put(path, t);
	return t;
}

}

Any ideas how to fix this? I noticed that for every texture structure in the map file there’s also a integer called flags and another called contents,
perhaps I need to specify these to devil somehow?

If anyone has any ideas, that would be great! :slight_smile:

I’m loading a ton of images and it turns out that it’s a problem with only a few of them, I guess the jpegs
that didn’t load had slightly different configuration that devil has a trouble with loading.

Not all of the textures in Q3 has power of two dimensions. If there is only a few images that don’t load you might want to check that out.

The entire source for the entire game, including the renderer, was released last year under the GPL.

Thanks for the help everyone.

I think I have it rendering mostly everything now, including curved architecture. It’s pretty fast
because I use vbos and I sort the texture binds.

Thank you for the help. I think I’ll try to start working on collision detection :slight_smile: