PDA

View Full Version : Using multiple code



Alload
03-16-2001, 09:07 PM
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?

chennes
03-17-2001, 06:00 AM
Put the display list code in a function, call it from your main function (or wherever).

Chris

Alload
03-17-2001, 06:58 AM
Okay, but how can I load a fonction located in another file than the main one?

IsaackRasmussen
03-17-2001, 07:00 AM
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);

Alload
03-17-2001, 10:17 AM
I can't manage to get it working by your way. Can you explain a bit more? Please.

WhatEver
03-17-2001, 10:32 AM
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(...);
}

LordKronos
03-17-2001, 10:54 AM
In your main() that should be
callDisplayList(...);
not
void callDisplayList(...);

Alload
03-18-2001, 02:29 AM
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?

Alload
03-18-2001, 06:08 AM
I managed to get the **** working. Thanks for the help.

kieranatwork
03-22-2001, 09:11 AM
Give up programming mate, or you'll end up a nervous reck with your iq.

Don't Disturb
03-23-2001, 11:18 AM
LOL!
Harsh but fair.

PeterK
03-23-2001, 03:21 PM
Everyone has to start somewhere.

Serge K
03-23-2001, 07:29 PM
Originally posted by PeterK:
Everyone has to start somewhere.
Agree.
But WHY in the "advanced" forum??? http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

Alload
03-24-2001, 11:00 PM
Sorry for posting in the advanced forum.

john
03-25-2001, 02:45 AM
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