Avoid importing the same mesh into the scene?

Hi all,
I am very new to opengl.
I managed to import an object but i wish to reuse that MEsh for other instance object in my game… (As there are many of the same geometry mesh in the scene).

How can i do so without keep importing the same mesh into the scene?

Import it only once.
In fact I don’t see why you would do differently.

Or maybe I misunderstood your question ?

I have multiple objects of the same geometry.
And What i did now is that for each objs, when i am in the display() function, i call a loop which loops thru each of the objects and load the geometry.

I find it resources wasteful because the geometry are the same… except that the rotation and translation are different.

Hence, i wish some experts to advice me how i can deal with this?

And draw multiple times. There’s no secret about it.

I can’t store the geometry in a buffer or something and retrieve it and somehow link that geometry object with each of the class objects I have created??

Diskhub,

You can store the common part using glNewList/glEndList and use glCallList after the rotation/translation Display List

how can i do that?
Currently, i have the following a class called Teaport (for example):


class Teaport{
..
void objload(String name, float size, GL2 gl){
  model = new OBJModel(name, size, gl, false);
}

void draw(GLAutoDrawable drawable)
{
System.out.println(model.getDisplayList());
GL2 gl = drawable.getGL().getGL2();
gl.glPushMatrix();
gl.glTranslatef(25, 5, 25);
gl.glRotatef(-90.0f+spin, 1.0f, 1.0f, 1.0f);
	[b]model.draw(gl);[/b]
gl.glPopMatrix();
spin+=2;
}
..
}

the model.draw method will draw the teaport in the scene.
I have also used glNewList/glEndList and glCallList in my draw method in the objloader.

Now the problem is:
I wish to have mulitple teaport in the scene.
Which means i have to initialise my teaport object like the following:


for(int i=0; i<8; i++){
Teapot temp = new Teaport();
arraylist.add(temp);
}

but i do not wish to do this for my draw and load:


for(int i=0; i<8; i++){
arraylist.get(i).objload('..');
}

how can i achieve this?
Sorry, I am still quite lost.

I wish to have mulitple teaport in the scene.
Which means i have to initialise my teaport object like the following:

“have to”? It’s your code; you don’t “have to” anything.

This is a trivial software engineering problem. Your problem is that your “Teapot” object represents not only a mesh, but the position and orientation of that mesh in the world. Separate these two concepts.

You need a “mesh” object that represents a particular set of vertex data. And you need an object that represents the position and orientation of something in the world.

but i do not wish to do this for my draw and load:

Then don’t. Make a separate function that loads a model one time. Then give references to that model to the objects that need them. Your “Teapot” constructor should be given a model; it should neither own or load it.

thanks for enlightening me!
I will give it a try :smiley: