Mukund

12-01-2010, 02:00 PM

Hello,

i am trying to model the Earth. i am using a .bmp file that consists of the image of the earth, which i am applying onto the

surface of the sphere.

i tried two methods:

1) Just plot each vertex on the sphere using the pixel values.

X_SIZE, Y_SIZE are the width and height of the image.

double x, y, z;

int i = 0, j = 0;

for (double theta = 0; theta <= 360.0; theta += (360.0 / X_SIZE)) {

for (double phi = -90; phi <= 90.0; phi += (180.0 / Y_SIZE)) {

x = sin((3.14 / 180) * theta) * cos((3.14 / 180) * phi);

y = cos((3.14 / 180) * theta) * cos((3.14 / 180) * phi);

z = sin((3.14 / 180) * phi);

glColor3d(buff1[j+2] / 255.0, buff1[j+1] / 255.0, buff1[j+2] / 255.0);

// buff has the raw pixel data

glPointSize(2);

glBegin(GL_POINTS);

glVertex3d(x, y, z);

glEnd();

}

}

2) A texture based method. The sphere is approximated using triangles. i found this on the internet.

TWOPI = 2 * 3.14 and PID2 = 3.14 / 2

// some texture initializations here.

gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,

GL_BGR_EXT, GL_UNSIGNED_BYTE, buff );

// buff has the raw pixel data

int i,j;

double theta1,theta2,theta3;

XYZ e,p;

/* XYZ is a tydefed struct:

typedef struct {

double x;

double y;

double z;

}

*/

for (j=0;j<n/2;j++) {

theta1 = j * TWOPI / n - PID2;

theta2 = (j + 1) * TWOPI / n - PID2;

glBegin(GL_QUAD_STRIP);

for (i=0;i<=n;i++) {

theta3 = i * TWOPI / n;

e.x = cos(theta2) * cos(theta3);

e.y = sin(theta2);

e.z = cos(theta2) * sin(theta3);

p.x = c.x + r * e.x;

p.y = c.y + r * e.y;

p.z = c.z + r * e.z;

glNormal3f(e.x,e.y,e.z);

glTexCoord2f(i/(double)n,2*(j+1)/(double)n);

glVertex3f(p.x,p.y,p.z);

e.x = cos(theta1) * cos(theta3);

e.y = sin(theta1);

e.z = cos(theta1) * sin(theta3);

p.x = c.x + r * e.x;

p.y = c.y + r * e.y;

p.z = c.z + r * e.z;

glNormal3f(e.x,e.y,e.z);

glTexCoord2f(i/(double)n,2*j/(double)n);

glVertex3f(p.x,p.y,p.z);

}

glEnd();

}

Now, i find both methods the same as far as the performance is concerned. But, shouldn't the texture based method be more efficient?

Can anyone please comment as to which method is better and why isn't there any observable difference in the performance?

i am trying to model the Earth. i am using a .bmp file that consists of the image of the earth, which i am applying onto the

surface of the sphere.

i tried two methods:

1) Just plot each vertex on the sphere using the pixel values.

X_SIZE, Y_SIZE are the width and height of the image.

double x, y, z;

int i = 0, j = 0;

for (double theta = 0; theta <= 360.0; theta += (360.0 / X_SIZE)) {

for (double phi = -90; phi <= 90.0; phi += (180.0 / Y_SIZE)) {

x = sin((3.14 / 180) * theta) * cos((3.14 / 180) * phi);

y = cos((3.14 / 180) * theta) * cos((3.14 / 180) * phi);

z = sin((3.14 / 180) * phi);

glColor3d(buff1[j+2] / 255.0, buff1[j+1] / 255.0, buff1[j+2] / 255.0);

// buff has the raw pixel data

glPointSize(2);

glBegin(GL_POINTS);

glVertex3d(x, y, z);

glEnd();

}

}

2) A texture based method. The sphere is approximated using triangles. i found this on the internet.

TWOPI = 2 * 3.14 and PID2 = 3.14 / 2

// some texture initializations here.

gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,

GL_BGR_EXT, GL_UNSIGNED_BYTE, buff );

// buff has the raw pixel data

int i,j;

double theta1,theta2,theta3;

XYZ e,p;

/* XYZ is a tydefed struct:

typedef struct {

double x;

double y;

double z;

}

*/

for (j=0;j<n/2;j++) {

theta1 = j * TWOPI / n - PID2;

theta2 = (j + 1) * TWOPI / n - PID2;

glBegin(GL_QUAD_STRIP);

for (i=0;i<=n;i++) {

theta3 = i * TWOPI / n;

e.x = cos(theta2) * cos(theta3);

e.y = sin(theta2);

e.z = cos(theta2) * sin(theta3);

p.x = c.x + r * e.x;

p.y = c.y + r * e.y;

p.z = c.z + r * e.z;

glNormal3f(e.x,e.y,e.z);

glTexCoord2f(i/(double)n,2*(j+1)/(double)n);

glVertex3f(p.x,p.y,p.z);

e.x = cos(theta1) * cos(theta3);

e.y = sin(theta1);

e.z = cos(theta1) * sin(theta3);

p.x = c.x + r * e.x;

p.y = c.y + r * e.y;

p.z = c.z + r * e.z;

glNormal3f(e.x,e.y,e.z);

glTexCoord2f(i/(double)n,2*j/(double)n);

glVertex3f(p.x,p.y,p.z);

}

glEnd();

}

Now, i find both methods the same as far as the performance is concerned. But, shouldn't the texture based method be more efficient?

Can anyone please comment as to which method is better and why isn't there any observable difference in the performance?