Simple question

I’ve drawn a circle using the following code:


glBegin(GL_TRIANGLES);  
		for(int i=0;i<=360;i++)
		{
			double angle=(float)(((double)i)/57.29577957795135);   
			double x2=x+(radius*(float)sin((double)angle));
			double y2=y+(radius*(float)cos((double)angle));             
			
			glTexCoord2f(x, y);glVertex2d(x,y); 			            
                        glTexCoord2f(x1, y1);glVertex2d(x1s,y1s);
			glTexCoord2f(x2, y2);glVertex2d(x2,y2);*/
			y1=y2;
			x1=x2;
		}
		glEnd();


And I have a texture that I want to cover the circle. I can get this to work if I set all the variables (x, y, x1, y1, x2, y2, radius) to 0.5 because then it is sitting perfectly inside the texture map (which goes from 0-1 in both directions).

However this is very small on screen so I want to make the radius larger, but when I do this the code doesn’t work because it’s going outside the texture map.

All I need to do is use some kind of scaling equation that simply shrinks it to fit in the texture map. I thought all I would need is to divide the variable (either x1, y1, x2, or y2) by the radius and add 0.5 to it. (I’m keeping the center of the circle at 0.5, 0.5). However this doesn’t work. Any pointers as to what I’m doing wrong - I know its something really stupid but I still cant work it out.

Thanks.

Well, you can use your working values, and simply put a glScale right before the glBegin, to enlarge or shrink the geometry. As texcoords are attached to geometry it will follow.

Simple. You use unscaled values for the texture coordinates (x1,…,y2) and scaled ones for the geometry coordinates (radiusx1,…,radiusy2).

But one thing is completely beyond my understanding - why do people cast intermediate values to (float), like the results of sin and cos in your program, effectively wasting precision? I’ve seen this so many times, and it’s starting to drive me furious. Including math.h does the job.

And let’s not forget the potential nastiness of calling sin/cos in a tight loop to begin with. Could be a recipe for slowness, but it’s not entirely clear what the OP is actually doing, beyond emitting some triangles.