Yes so that, for example, I could read one file and store the in 'object1' and then read another file and store that data in 'object2'.

I've attached all of the files that I utilise but 'project' is the main file that contains all of the discussed code

What exactly is the state of the program at the moment? Is it running properly, except for not being able to read in multiple files of objects?

BTW, you could have put all the files in ONE zip file. :)

Ye it's working fine at the moment, theres lots of things that I still want to tweak and add in but it works :)

Reading multiple files and then storing that data into individual object structures that can then be manipulated is basically the main thing that I'm trying to implement however.

You didn't post myMath.h.

Oops, sorry :s

It would be easier if I could run this thing, but I'm getting linker errors and cannot (easily) resolve them. Anyway, here's a rewrite of the data structure to enable loading mutiple scene files into a scene array. I've renamed a couple of functions, etc., as well. See if it runs and look through it carefully to understand the changes. Overall, it's simpler than before.

Theres quite a few errors in the code at the minute but I'm working through them now so hopefully I'll be able to get it up and running.

Ok I have come across a slight confusion.

void drawScene( Scene *scene )     // was "shape"
{
	int i;
	for( i = 0; i < scene->nObjects; i++ )
		drawObject( scene[ i ] );
}

void drawObject( Object *object ) // was also part of "shape"
{
	int i;
	for( i = 0; i < object->nFacets; ++i )
		drawPolygon( object, i );
}

In the first method a 'scene' is passed to it but would this not have to be an 'object' as it is an object that is required to be passed into drawObject. Having said that I realise that scene needs to be passed in order to find the number of objects to draw (nObjects).
Should i replace 'drawObject( scene[ i ] );' with 'drawObject(scene->objects; )'?

Yes, that's the right thing to do there. And I forgot to change the call to "shape" in display to a call to drawScene.

Hmmm, I'm a bit stuck now so perhaps you'll understand the errors better than me. I'll attach the code for you and post the errors that are occuring and in which places. I've only made a few minor changes to your code to correct syntax (e.g. missing ';') errors so it'll be hard to notice any changes.

code: (main method)
scenes = malloc( 1 * sizeof( Scene ));
error:
cannot convert from 'void*' to 'Scene*'

code: (main method)
loadScene( scenes[ nScenes++ ], "scene.ASE" );
error:
cannot convert parameter 1 from 'Scene' to 'Scene*'

code: (drawScene method)
drawObject(scene->objects); //this line
error:
cannot convert parameter 1 from 'Object' to 'Object*'

code: (in drawPolygon method)
Facet *facet = object->facets[ iFacet ];
error:
cannot convert from 'Facet' to 'Facet(*)'

code: (drawPolygon Method)
glVertex3fv(object->vertices[facet]);
error:
illegal index, indirection not allowed

code: (loadScene method)
scene->nObjects = initScene( scene, fullFile );
error:
cannot convert from 'void' to 'int'

code: (display method)
drawScene( scenes[ selectedScene ]);
error:
cannot convert parameter 1 from 'Scene' to 'Scene*'

Mostly it was missing ampersands (to take addresses instead of values). And I forgot to return the size from initScene. Try it now.

Ok theres just one error now but I don't understand why it occurs because it looks fine to me.

code: (drawPolygon method)
glVertex3fv(object->vertices[facet]);
error:
illegal index, indirection not allowed

Try this (yet another ampersand): glVertex3fv(&object->vertices[facet[i]]);

It still gives the same error as before :(

I believe this works.

void drawPolygon( Object *object, int iFacet )
{
	int i;
	int *facet = &object->facets[iFacet][0];

	glBegin( GL_POLYGON );
	glColor3ub( 128, 64, 0 );

	for( i = 0; i < 3; ++i )
		glVertex3fv(&object->vertices[facet[i]]);

	glEnd();
}

Ok this one is a little bit weird but the program is now compiling and running but the the objects contained acquired from file aren't being displayed/visible :s (everything else is displaying fine though)

Try this. ;) But it's the essentially the same. Attach your project.c file if it's still not working.

void drawPolygon( Object *object, int iFacet )
{
	int i;
	int *facet = object->facets[iFacet];

	glBegin( GL_POLYGON );
	glColor3ub( 128, 64, 0 );

	for( i = 0; i < 3; ++i )
		glVertex3fv(&object->vertices[facet[i]]);

	glEnd();
}

It throws an error when I do that for some reason :s " Error 1 error C2664: 'glVertex3fv' : cannot convert parameter 1 from 'Vertex (*)' to 'const GLfloat *' "

I've attached my file :)

Oops! Remove the ampersand from that one. So it should be: glVertex3fv(object->vertices[facet[i]]); Also, you might want to use atoi instead of atof in the line given below since you're reading an integer (the line is in loadScene): curObj->facets[f][i] = atof( strtok ( NULL, delim )); Let me know if it displays the scene or not.

No it's still not quite working, it gave a strange error this time though. It said: " Windows has triggered a breakpoint in temp.exe.

This may be due to a corruption of the heap, which indicates a bug in project.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while temp.exe has focus.

The output window may have more diagnostic information. " and then after clicking break "No symbols are loaded for any call stack frame. The source code cannot be displayed." I have no idea what that means :s I just assume that there is some kind of error either writing data or retrieving it

That is strange. I finally got it to run just now. There's a black-and-white checkerboard "floor", a blue "sky", and a box and a pyramid floating in the sky.

You could simplify your whole Keyboard() function to a few if else conditions.

MF: We've got bigger fish to fry! But that's definitely a good idea.

caged_fire: I've created a opengl-free version to just read and print the data structure and I'm getting errors with it! I probably won't be able to take a good look at it until tomorrow, though. I'll get back to you.

Turns out the data structure was okay after all (it only crashed because I had forgotten to allocate space for the scene in my test program).

But I found the problem. It had to do with passing fullFile to initScene, you know that problem. For some reason it just doesn't work, and you tried to change it back (to reading the file a second time) but forgot a couple of things. I only change perhaps 2 lines.

So I think it's working. A table shows up now!

Does the table fully display when you run it? Everything seems to be working, even when I try loading and displaying more than one scene at a time. The only problem is that not all of the polygons of the loaded objects/scenes are being displayed i.e. the table looks like it has a big crack through the middle and you can only just see the legs :s
Other than that everything works fine though :)

That's how it looks to me too. If you rotate the pyramid it will actually disappear at one point. I don't know if that's a related problem or if that's how it always worked. Test out rotating the pyramid. If it's not working the way it used to then it must be something with the opengl part of the program and not the data structure since the pyramid is hard-coded.

P.S., I figured out what was wrong with passing fullFile to initScene. Basically, it needs its own copy of fullFile because strtok leaves the nulls in the string. I was under the mistaken impression that strtok would remove the previous null before it scanned to place the next one, so that when all was said and done the string would be back to its initial state. (Which is stupid because I recall writing a program a few years ago that depended on the nulls being left in.)

There WAS a problem in reading in the data. I don't know if I did it or you, but the extra strtok (to get rid of the letters A, B, C in the data) needs to be inside the loop. So change the code as follows:

if( strcmp( pch, "MESH_FACE" ) == 0)
		{
			int i, f;
			f = atoi( strtok( NULL, delim ));
			for( i = 0; i < 3; ++i )
			{
				strtok( NULL, delim );
				curObj->facets[f][i] = atoi( strtok ( NULL, delim ));
			}
		}
commented: man, you really slugged this one out. truly a herculean effort. +8

Yep thats done it, the problem is now officially solved :)
Over the summer I'm going to spend a lot of time improving my programming skills, particularly OpenGL and c/c++, so if I need any help I'll give you a shout.

Thanks so much for all your help, I'll let you know how I get on with my assignment ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.