The coordinates of each body (x, y, z) are in the "pos" array.
I try to use glTexCoordPointer with the following display function :
void drawPoints()
{
glEnable(GL_TEXTURE_2D); // Enable texture mapping.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glBindTexture(GL_TEXTURE_2D, texture[0]); // pick the texture.
glLoadIdentity(); // reset the view before we draw each star.
glTranslatef(0.0f, 0.0f, zoom); // zoom into the screen.
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), pos);
glTexCoordPointer(4, GL_DOUBLE, 4*sizeof(double), pos);
glColor4ub(30, 100, 120, 255);
glBegin(GL_QUADS); // Begin Drawing The Textured Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd(); // Done Drawing The Textured Quad
glDrawArrays(GL_POINTS, 0, numBodies);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
}
before this, I call the following function for loading the 2D texture :
// Load Bitmaps And Convert To Textures
void LoadGLTextures(void)
{
// Load Texture
Image *image1;
// allocate space for texture
image1 = (Image *) malloc(sizeof(Image));
if (image1 == NULL) {
printf("Error allocating space for image");
exit(0);
}
if (!ImageLoad("Data/Star.bmp", image1)) {
exit(1);
}
// Create Textures
glGenTextures(3, &texture[0]);
// linear filtered texture
glBindTexture(GL_TEXTURE_2D, texture[0]); // 2d texture (x and y size)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data);
};
My main problem is that only one textured element is displayed at the center of the window (x=0, y=0) ( see figure in attachment).
It seems that I don't use correctly the function glTexCoordPointer . In the above drawPoints() function, I call it with :
glTexCoordPointer(4, GL_DOUBLE, 4*sizeof(double), pos);
where pos is the array of coordinates of each body (x, y, z).
I found another solution for plotting all the bodies with glTranslate in a loop on all the elements :
for(int i=0;i<numBodies;i++)
{
glPushMatrix();
glTranslatef(pos[i],pos[i+1],pos[i+2]);
glColor4ub(30, 100, 120, 255);
glBegin(GL_QUADS); // Begin Drawing The Textured Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd(); // Done Drawing The Textured Quad
glPopMatrix();
}
You can see the expected result on the second image in attachment ( N_Bodies.png).
but I would like to avoid this solution and find a way to draw all the bodies at once (with glDrawArrays)
Any idea ?
Edited by youpi1, 30 October 2012 - 12:27 AM.






