3D Mesh rendering stops back buffer from working?

So I have 2 weeks to come up with a game in C++, in a windows application, and I've written a few classes that let me render 3D meshes. I wrote an OBJ file reader that saves a vector of all the vertices and a vector of indices indicating how to connect the vertices to form the polygons that compose the mesh.

I also wrote a perspective projection function that, given a camera (position, direction, field-of-view angle and aspect ratio) converts each of those vertices (x, y, z) into a vector of screen coordinates (x, y).

Then, I run through my vector of indices, connecting sets of vertices by saving them in a small array and passing them to the Polygon() function. This effectively (removing back-facing an off-screen polygons) draws any mesh I can make in 3D Max in my windows app.

Ok, I wanted to explain that since it must have something to do with this... my teacher showed the class how to get a back buffer working (we draw to a memory DC and then BitBlt() it each frame onto the screen to "Present" it) and right now, when I start up my application, it's as if the back buffer can only handle X-number of polygons - what I mean is, after a certain amount of time, suddenly the back buffer stops presenting and the game just freezes, and the more complex my shape is, the faster it happens (2-3 seconds for something like a sphere, a whole minute for a cube).

I've tested this to prove that my mesh is still updating - the arrow keys move it around in 3D space, and after the screen freezes, the position of the mesh continues to update, but not draw. Also, if I change which DC I use and draw directly to the screen, it looks all messed up at first (since the back buffer is constantly drawing over it) but right on cue, the back buffer stops working and suddenly I'm drawing right on screen.

So all that said, I'm not sure what to post out of my code, so just ask if you want to see something, like the back buffer code or my mesh drawing. I've been playing with this for a while now and I just don't understand how my calling the Polygon function X-number of times would possibly cause the back buffer to stop working - and all the code is still executing (confirmed by break points).

Any and all help appreciated!
Last edited on
Well, here's the code from my draw function, and again, the more complex the shape (so the more times I call Polygon() ) the faster the screen freezes.

I'm not necessarily looking for complete answers but just ideas - I really can't even imagine what would possibly be causing my back buffer to stop drawing, as they are completely separate components of my program. Again, all help appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void Mesh::draw(HDC hdc)
{
	vector<unsigned int> next;

	for (unsigned short polygon = 0; polygon < polygonList.size(); polygon++)
	{
		// Get the next polygon indices
		next.clear();
		next = *polygonList.at(polygon);

		// Create an array to pass to Polygon()
		pt = new POINT[next.size()];

		// Fill the array with points from pointList based on the indices in 'next'
		for (unsigned short point = 0; point < next.size(); point++)
			pt[point] = *pointList.at(next.at(point) - 1);

		if (IsFacingCamera(pt))
			Polygon(hdc, pt, next.size());

		delete[] pt;
		pt = NULL;
	}

}
Topic archived. No new replies allowed.