Draw a large amount of textured 3D Primitives in OpenGL

Hi !

I need to draw a lot of textured cubes and spheres for a project (~3000).
I’m using glutSolidCube() and gluSphere() which let me draw all my primitives in 60 fps (VboMesh returns me 30 fps), but I can’t texture them…

I tried to bind an image with myImage.getTextureReference().bind(); but it doesn’t work.

Also, I’ve tried this solution :

But I get the same result, a black sphere/cube :

in setup :

ofImage myTexture;  

in draw :

unsigned char* pixels = myTexture.getPixels();  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0,GL_RGB, GL_UNSIGNED_BYTE, pixels);
glEnable(GL_TEXTURE_GEN_S); //enable texture coordinate generation
glBindTexture(GL_TEXTURE_2D, myTexture);
glDisable(GL_TEXTURE_GEN_S); //enable texture coordinate generation

It get the same thing if I manually draw my cube like :

glBegin(GL_QUADS);                /
// Top face (y = 100.0f)
glVertex3f( 100.0f, 100.0f, -100.0f);
glVertex3f(-100.0f, 100.0f, -100.0f);
glVertex3f(-100.0f, 100.0f,  100.0f);
glVertex3f( 100.0f, 100.0f,  100.0f);

// Bottom face (y = -100.0f)
glVertex3f( 100.0f, -100.0f,  100.0f);
glVertex3f(-100.0f, -100.0f,  100.0f);
glVertex3f(-100.0f, -100.0f, -100.0f);
glVertex3f( 100.0f, -100.0f, -100.0f);

// Front face  (z = 100.0f)
glVertex3f( 100.0f,  100.0f, 100.0f);
glVertex3f(-100.0f,  100.0f, 100.0f);
glVertex3f(-100.0f, -100.0f, 100.0f);
glVertex3f( 100.0f, -100.0f, 100.0f);

// Back face (z = -100.0f)
glVertex3f( 100.0f, -100.0f, -100.0f);
glVertex3f(-100.0f, -100.0f, -100.0f);
glVertex3f(-100.0f,  100.0f, -100.0f);
glVertex3f( 100.0f,  100.0f, -100.0f);

// Left face (x = -100.0f)
glVertex3f(-100.0f,  100.0f,  100.0f);
glVertex3f(-100.0f,  100.0f, -100.0f);
glVertex3f(-100.0f, -100.0f, -100.0f);
glVertex3f(-100.0f, -100.0f,  100.0f);

// Right face (x = 100.0f)
glVertex3f(100.0f,  100.0f, -100.0f);
glVertex3f(100.0f,  100.0f,  100.0f);
glVertex3f(100.0f, -100.0f,  100.0f);
glVertex3f(100.0f, -100.0f, -100.0f);

Does anyone know how I could texture them ?

Thanks !

ofVboMesh should be at least as fast as gluSphere, if you are using ofMesh::sphere() it creates texture coordinates, normals and vertices which gluSphere probably doesn’t that might account for the difference in performance but without texture coordinates you can’t use textures.

also if you are drawing lots of copies of the same geometry the fastest way to do it is to use instanced drawing.

Hi Arturo,

I tried vboMesh, but I still get ~8 fps with it.

Here is the example with glutSolidCube and VboMesh for 0.8.4 :

glutSolidCube.zip (70,4 Ko)

vboMeshTest.zip (70,1 Ko)

I’ll take a look a the instanced drawing .