glColorpointer

I am using glcolorpointer to show the color fading

It is working fine in vc++. But i am getting some unexpected results when i port the same coding in Linux Os.

I am attaching the code .

CODING

              float v3,v4,v5,v6;
              float sweepvertexarray[5000];
              float intensityarray[5000];
              float myintensity=1.0;
              float myalpha=1.0; 
              int k=0;
              int indices1;
	  for(float cpi=(6.28);cpi>0;cpi=cpi-0.0157)
 	           {
	     v3=0.0f;
	     v4=0.0f;
	     v5=8*0.252*sin(cpi);
	     v6=8*0.252*cos(cpi);
	    sweepvertexarray[(k*4)+0]=v3;
	    sweepvertexarray[(k*4)+1]=v4;
	    sweepvertexarray[(k*4)+2]=v5;
	    sweepvertexarray[(k*4)+3]=v6;
	   intensityarray[(k*4)+0]=0.0f;
	  intensityarray[(k*4)+1]=myintensity;
	  intensityarray[(k*4)+2]=0.0f;
	  intensityarray[(k*4)+3]=myalpha;
	  myalpha=myalpha-0.0025;
	  myintensity=myintensity-0.0025;
	  k++;
	  indices1=k*2;
	  }

	  //glColor4f(0.0f,1.0f,0.0f,1.0);
	 
          
      glEnableClientState(GL_COLOR_ARRAY);
          glEnableClientState(GL_VERTEX_ARRAY);
      glColorPointer(4, GL_FLOAT,8, intensityarray);
          glVertexPointer(2, GL_FLOAT,0,sweepvertexarray);
          glDrawArrays(GL_QUAD_STRIP,0,indices1);
          glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);

Janani

  1. never ever do a for loop that rely on a float value to fill in an array.

  2. be more specific to describe what is wrong : “getting some unexpected results” is very imprecise. Does the colors gets messed up ? All the same ? A part is good, a part is messed ? Or the wrong color ? If you can’t describe, post a screenshot.

  3. the stride value is wrong, stride specifies the byte stride from one color to the next, read manual for glColorPointer

  4. rewrite your loop this way :


float cpi = 6.28
for(int k=0; k<5000 ; k++) {
cpi=cpi-0.0157
...
glColorPointer(4, GL_FLOAT,0, intensityarray);
...
// remove k++ at the end
}

I am getting the whole circle filled with black color.

When i change the stride to 8, color gets messed up.

In vc++ when i gave stride 0 i was not getting proper , when i changed to 8 it was okay.

is there any difference in color mapping.

Janani