PDA

View Full Version : what's lacking for non-Escher-like appearance?



kurono
01-31-2009, 02:11 PM
I get this:
http://img207.imageshack.us/my.php?image=picture9uz1.png

my "prepare" function looks like this:


double t; int i;
double dt = (2*M_PI)/numberOfColorStrips;

vertexArray = calloc(4*numberOfColorStrips, 3*sizeof(double));
normalArray = calloc(4*numberOfColorStrips, 3*sizeof(double));
colorArray = calloc(4*numberOfColorStrips, 3*sizeof(double));

first = calloc(numberOfColorStrips, sizeof(int));
count = calloc(numberOfColorStrips, sizeof(int));

for ( i=0; i<numberOfColorStrips; i++ ){
count[i] = 4;
}

BOOL up = YES;

for ( t = 0, i=0; t <= 2*M_PI; t += dt, i+=6) {
if ( up ){
vertexArray[i] = sin(t);
vertexArray[i+1] = -h;
vertexArray[i+2] = cos(t);

vertexArray[i+3] = sin(t);
vertexArray[i+4] = +h;
vertexArray[i+5] = cos(t);

up = NO;

} else {
vertexArray[i] = sin(t);
vertexArray[i+1] = +h;
vertexArray[i+2] = cos(t);

vertexArray[i+3] = sin(t);
vertexArray[i+4] = -h;
vertexArray[i+5] = cos(t);

up = YES;

}


colorArray[i ] = colorArray[i+3] = (random()%256)/256.0;
colorArray[i+1] = colorArray[i+4] = (random()%256)/256.0;
colorArray[i+2] = colorArray[i+5] = (random()%256)/256.0;


double d1[3], d2[3];
d1[0] = vertexArray[i] - vertexArray[i+3];
d1[1] = vertexArray[i+1] - vertexArray[i+4];
d1[2] = vertexArray[i+2] - vertexArray[i+5];

d2[0] = vertexArray[i] - vertexArray[i-3];
d2[1] = vertexArray[i+1] - vertexArray[i-2];
d2[2] = vertexArray[i+2] - vertexArray[i-1];

normcrossprod(d1, d2, &amp;normalArray[i]);
normcrossprod(d1, d2, &amp;normalArray[i+3]);



first[i/6] = (i/6)*2;

}




my drawRect functions looks like this:


glClearColor(0.2, 0.2, 0.2, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

// glEnableClientState(GL_INDEX_ARRAY);


glVertexPointer(3, GL_DOUBLE, 0, vertexArray);
glColorPointer(3, GL_DOUBLE, 0, colorArray);
glNormalPointer(GL_DOUBLE, 0, normalArray);
// glIndexPointer(GL_INT, 0, indexArray);

gluLookAt(-4.5, 4.0, -3.0,
0.0, 0.0, 0.0,
-2.0, 1.0, 0.0);


// glDrawArrays(GL_QUAD_STRIP, 0, 2*numberOfColorStrips);

glMultiDrawArrays(GL_QUADS, first, count, numberOfColorStrips);


glFlush();


Thanks a lot, I'm stuck at this.

zeoverlord
01-31-2009, 03:26 PM
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

kurono
01-31-2009, 03:34 PM
thanks a lot!