texture no square surface

Member
Posts: 306
Joined: 2009.03
Post: #1
In opengl es I would like to use a texture, but only have a portion of it drawn.
For example I have a picture of a beach ball and I want to draw only x degrees of it as an arc. Can you fill a non rectangle shape with a rectangluar source image without distorting the image? If this isn't clear, consider the pacman character. He is a circle but not a 360 degree one. He stops short and is really like a 270 degree circle.
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
The short answer is yes.
Depending on what exactly you are hoping to achieve you should investigate how texture mapping works and how blending modes work. In the pacman example you give, I would draw him in a square polygon and use alpha to leave the blank space around him. If you draw a triangle it takes a triangular section out of your texture using the three coordinates you give it. Many triangles can be assembled into any shape you like.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #3
I can't use that option. This is for dynamic arcs. So a picture of pacman, draw arc from 100 degrees to 180 degrees and you would see a yellow pie slice show up. Does that make sense? Unless i could make my texture co-ords be in the arc shape?
Quote this message in a reply
Member
Posts: 339
Joined: 2004.07
Post: #4
kendric Wrote:I can't use that option. This is for dynamic arcs. So a picture of pacman, draw arc from 100 degrees to 180 degrees and you would see a yellow pie slice show up. Does that make sense? Unless i could make my texture co-ords be in the arc shape?

What you want is gluPartialDisk. The spec is here:

http://www.opengl.org/documentation/spec...ldisk.html

And a tutorial is here:

[url="http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=18"]
http://nehe.gamedev.net/data/lessons/les...?lesson=18[/url]

If you don't have access to glu, (like if you're on the iPhone) you can have your circular shape be centered in a texture. Then, when drawing your arc, you could set up a triangle fan from the center of your shape outward. I'd just use sin and cos to get the coords in world space. Similarly, you can use sin and cos to get your texture coordinates (which, in your texture, would contain your circle shape. So the points making a circle of radius 0.5 centered at texture coordinate 0.5, 0.5.)

Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #5
Sounds like you're going to have some serious pinching problems near the center. It's hard to compensate for that distortion accurately. Paul Bourke had a good page on this as it relates to sphere mapping. I had a link bookmarked but he apparently changed the site structure. I think this was the page I started with. You can dig around his site for a bunch more related spherical stuff, but the idea I'd roll with is to come up with a way of (for lack of a better term) "anti-pinching" the texture where you map it on the center of your triangle fan.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #6
Well the pinching thing may be a problem, but I would like to see what this looks like. I tried what was suggested and have this:
-(void) drawGameArcAt:(CGPoint)center radius:(float)radius startArc:(float)startArc endArc:(float)endArc fillIn:(bool)fillIn
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Enable use of the texture
glEnable(GL_TEXTURE_2D);
// Set a blending function to use
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Enable blending
glEnable(GL_BLEND);
//Set the texture to use
Texture *texture=[textures objectAtIndex:1%frames];
[texture bind];
if (endArc < startArc)
{
float temp = endArc;
endArc = startArc;
startArc = temp;
}

glColor4f(1,1,1,1);
//2 for the remainder when we draw the last arc
//2 for the start point since its a triangle fan
int numVertices=(int)(2+2.0f*(endArc-startArc)/ARC_SEGMENT)+2;
GLfloat spriteVertices[numVertices];
//GLshort textureVertices[] =
// {
// 0, 1,
// 1, 1,
// 0, 0,
// 1, 0,
// };
GLfloat textureVertices[numVertices];
float theta;
int i=0;
spriteVertices[0]=center.x;
spriteVertices[1]=center.y;
textureVertices[0]=0.5;
textureVertices[1]=0.5;
i+=2;
float radius2=radius*2;
for (theta = startArc; theta < endArc; theta += ARC_SEGMENT)
{
float x=sinf(theta)*radius;
float y=cosf(theta)*radius;
textureVertices[i]=(radius+x)/radius2;
textureVertices[i+1]=(radius+y)/radius2;
spriteVertices[i]=center.x+x;
spriteVertices[i+1]=center.y+y;
i+=2;
}
if(theta>endArc)
{
float x = (float) sin(endArc) * radius;
float y = (float) cos(endArc) * radius;
textureVertices[i]=(radius+x)/radius2;
textureVertices[i+1]=(radius+y)/radius2;
spriteVertices[i]=center.x+x;
spriteVertices[i+1]=center.y+y;
i+=2;
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer (2, GL_FLOAT , 0, spriteVertices);

glTexCoordPointer(2, GL_FLOAT, 0, textureVertices);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDrawArrays (GL_TRIANGLE_STRIP, 0, i/2);

}

Needless to say it didn't work. I see a semi circle of dots, with a fater triangle on the left side.

I will keep looking at this, if anyone else has a suggestion though please do Smile
P.S The semi circle part is correct, i was rendering only half a circle in my test.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #7
I changed my sprite image and I see a definite effect. The color changed and i see one of the triangle arcs only. So its doing something. If i turn off textures, it looks the same with just white so I am prob doing something wrong in the actual strip and nothing to do with the texture itself.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #8
Yeah!. I was using strip instead of triangle fan. Switched that and it worked. No texture pinch either. Looks exactly like what I wanted.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Want good color interpolation for my square Najdorf 2 3,906 Nov 22, 2009 10:11 PM
Last Post: Najdorf
  Trying to make a square... there's a triangle! TimMcD 4 3,778 Jun 2, 2009 03:41 PM
Last Post: AnotherJake
  surface rendering from data points mc1961 6 4,893 Nov 15, 2007 03:37 PM
Last Post: TomorrowPlusX
  Trouble turning an SDL surface into an OpenGL texture Joseph Duchesne 4 5,634 May 22, 2007 05:14 PM
Last Post: Joseph Duchesne
  Surface/Vertice Normals and Scene Placement Jones 3 2,920 Aug 22, 2006 02:45 PM
Last Post: scgames