Using multiple code

I’d like to know if it’s possible to have two C++ files with one which contains the main code and the other wich contains the display lists. If it’s possible, how can I load the display lists in the main file?

Put the display list code in a function, call it from your main function (or wherever).

Chris

Okay, but how can I load a fonction located in another file than the main one?

This is getting a bit offtopic.

Anyway, to call a funtion from another file, you need to declare it “extern” in the file that you are calling it from.
Like this

extern void callDisplayList(GLint id);

Now you can call,

callDisplayList(1);

I can’t manage to get it working by your way. Can you explain a bit more? Please.

extern on a function? Is that a C thing?

all you need to do is make a cpp file with your list in it like so:

some.cpp
void callDisplayList(GLint id)
{
blah…
}

some.h
void callDisplayList(GLint id);

main.cpp
#include “some.h”

void main()
{
void callDisplayList(…);
}

In your main() that should be
callDisplayList(…);
not
void callDisplayList(…);

Here’s the code which I want to put in another file than the main one:

static BYTE face_indicies[12][3] = {
// Box01
{0,2,3 }, {3,1,0 }, {4,5,7 }, {7,6,4 }, {0,1,5 }, {5,4,0 }, {1,3,7 },
{7,5,1 }, {3,2,6 }, {6,7,3 }, {2,0,4 }, {4,6,2 }
};
static GLfloat vertices [8][3] = {
{-0.5f,-0.451219f,-0.27439f},{0.5f,-0.451219f,-0.27439f},{-0.5f,0.451219f,-0.27439f},
{0.5f,0.451219f,-0.27439f},{-0.5f,-0.451219f,0.27439f},{0.5f,-0.451219f,0.27439f},
{-0.5f,0.451219f,0.27439f},{0.5f,0.451219f,0.27439f}
};
GLint cube()
{
int i;
int j;

GLint lid=glGenLists(1);
glNewList(lid, GL_COMPILE);

glBegin (GL_TRIANGLES);
  for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
   {
   for(j=0;j<3;j++)
    {
      int vi=face_indicies[i][j];
       glVertex3f (vertices[vi][0],vertices[vi][1],vertices[vi][2]);
    }
   }
glEnd ();

glEndList();
return lid;
};

Can you explain me exactly what to do to get the thing working?

I managed to get the **** working. Thanks for the help.

Give up programming mate, or you’ll end up a nervous reck with your iq.

LOL!
Harsh but fair.

Everyone has to start somewhere.

Originally posted by PeterK:
Everyone has to start somewhere.

Agree.
But WHY in the “advanced” forum???

Sorry for posting in the advanced forum.

yer, but i think the point that has been made (and one i alluded to in another post i wrote elsewhere here, tonight) is that the opengl forum is NOT intended for people to learn how to PROGRAM. its for people who want help on opengl, and nothing more.

knowing what the extern keyword in C means has FA to do with opengl (which is, by its very nature, language independent). There are even opengl bindings for fortran and ada (and god knows whatelse). do you really want to see the forum populated by people asking what "with text_io; use text_io; means in an Ada program? or how to give hints in a high-performance fortran program to distrbute a for-loop to a number of nodes? the answer should clearly be no: that these are LANGUAGE issues and NOT opengl issues.

people should really, REALLY know how to program first before they start trying to learn too many things all at once (such as linear algebra, syntax and semantics of a language, algorithm design AND opengl specifics).

feh.

cheers,
John