Advertisement Jump to content
Sign in to follow this  

OpenGL:: Loading Quake 3 BSP, finally stuck and exasperated.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I finally gave up trying to solve this problem on my own and, since I haven't found any information that's fixed my problem and you all seem pretty knowledgeable, I decided to join and see if any of you fine gents would tell me what I'm doing wrong. So, without further adeiu, here's my source (please excuse the commented out lines, they're there to show you some of the solutions I've tried):
tBSPVertexes *loadVertices;

FILE * pFile;

bool LoadVertices()
  //cout << "Loading Map Vertices: ";
  int numVertices = header.lumps[kVertices].length/sizeof(tBSPVertexes);
  loadVertices= new tBSPVertexes[numVertices]();	
  fseek(pFile, header.lumps[kVertices].offset, SEEK_SET);
  arrayvertexes = new GLfloat[numVertices*3];
 for(int i=0; i<numVertices; i++)
  arrayvertexes[(i*3)] = loadVertices[i+1].vPosition[0];
arrayvertexes[(i*3)+1] = loadVertices[i+1].vPosition[1];
arrayvertexes[(i*3)+2] = loadVertices[i+1].vPosition[2];
  //cout << "Ok." << endl;
	//vertices=new tGLBSPVertices[numVertices]();
	//for(int i=1; i<numVertices; i++)
		//swap y and z and negate z
	//	vertices[i-1].vPosition.x=loadVertices.vPosition.x;
	//	vertices[i-1].vPosition.y=loadVertices.vPosition.y;
	//	vertices[i-1].vPosition.z=loadVertices.vPosition.z;
		//scale down
	//	vertices[i-1].vPosition/=64;
//  test = new GLFloat[numVertices];

  return 1;

int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
		glVertexPointer(3, GL_FLOAT, 0, &arrayvertexes);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer


		glColor3f(1.0f,0.0f,0.0f);			// Set The Color To Red
	//	glVertex3f(arrayvertexes[1],0.0, 1.0);			// Move Up One Unit From Center (Top Point)
	//	glColor3f(0.0f,1.0f,0.0f);			// Set The Color To Green
		glVertex3f(-1.0f,-1.0f, 0.0f);			// Left And Down One Unit (Bottom Left)
	//	glColor3f(0.0f,0.0f,1.0f);			// Set The Color To Blue
		glVertex3f( 1.0f,-1.0f, 0.0f);	
return TRUE;										// Everything Went OK

and my bsp.h file:
GLfloat *arrayvertexes;

struct tBSPVertexes
    GLfloat vPosition[3];      // (x, y, z) position. 
    //VECTOR3D vPosition;
	float vTextureCoord[2];  // (u, v) texture coordinate
    float vLightmapCoord[2]; // (u, v) lightmap coordinate
    int vNormal[3];        // (x, y, z) normal vector
    int color[4];           // RGBA color for the vertex 

Sorry, my coding and formatting is a little off in those files, but each time I make progress, I clean it up. However, after the loading of the vertices, my progress stopped for about a good week (yeah, I've been trying solutions for that long). So far, I get the same error no matter what I do (I've even tried solutions I don't understand, as you'll see in the entire block of commented code for tGLBSPVertices). I've tried vectors (I think the code for that is still commented out). My error happens in one of two spots: 1.) glDrawArrays gives me an error in atioglxx.dll 2.) Passing a vertex from an array to glVertex3f gives me an error in BSPLoader.exe As I said, I've had this problem now for about a week and I've finally gotten frustrated with it. If you decide to help me then thank you very much and good luck. If not, I understand. -Sarepean [Edited by - Sarepean on January 21, 2006 9:21:18 AM]

Share this post

Link to post
Share on other sites
I took a quick look, but wasn't quite able to figure out what was going on. Here are a couple of suggestions though:

1. Post the exact errors that you're getting
2. Post only the code block where the error is occuring, so it's easier for us to find and look at
3. Try just drawing a single triangle or something in OpenGL without the Q3 stuff, and see if that works
4. If it does, start adding things in and see where the error is introduced

I also noticed that your vertex normals and colors are arrays of ints, which seems a little unusual; don't know if that's related to your problem.

Anyway, maybe someone else will be able to spot the problem, but for me that's quite a bit of code to sort through. If you can provide more details and just the relevant bits of code, it might be easier to find the problem.

Share this post

Link to post
Share on other sites
Ah, sorry, the reason I've included so much code is that I'm not quite sure what is causing the error, but I do know this much:

If you'll search my first huge block of code, you'll find a commented out line with the statement glDrawArrays(3, GL_FLOAT, 0, &vertices); or very similar. No matter what kind of variable I pass to it (and right now, I'm either passing a GL_FLOAT or Vector since I'm only binding my vertexes, as described by my tBSPVertexes structure), my code crashes while in the file atioglxx.dll (It's not actually getting as far as the glDrawArrays. I say this because when I was having problems before, there was a green arrow that showed me what line, and the green arrow is now completely gone). When I remove glDrawArrays, it works, but doesn't draw anything. I suspected maybe something was wrong with the way I was trying to access the arrays, so I tried to pass a single variable (loadVertices[1].vPosition[1]) to a glVertex3f statement and it crashes on that code.

Last night, after I posted this, I went ahead and downloaded a few open source engines and have been looking through them. I still don't see what I've done wrong, but I've seen the same thing I'm trying to do done in a multitude of ways.

The specific error is like a 0xC000000005 error or something. Depending on how many variables I pass to a glVertex3f statement, it crashes on access violation 4, 8, or 12. My glDrawArrays always crashes with an unhandled exception on access violation at address 0x000000010 (not sure about the number of 0's in any of those statements, but the main information is the same). I'm editing my original post to cut down the code.

EDIT:: The code is much shorter now in my original post. Also, even though you won't see an EnableClientState(GL_VERTEX_ARRAYS);, it's in the code, just not in the code posted above (I originally called the statement during the GL_INIT)

Thanks again for everyone's help!

Share this post

Link to post
Share on other sites

I'm kind of new to debugging, but I figured out how to work Breakpoints in Visual Studio .NET 2003. When I checked my variable values, I ended up finding out that all of my pointers were turning into bad pointers somehow. I don't know exactly what I did to fix it (it actually seemed to fix itself), but it is working now.

Thank you jyk for looking and trying to help.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!