texture no square surface - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: texture no square surface (/thread-1581.html)
texture no square surface - kendric - Mar 20, 2009 09:11 AM
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.
texture no square surface - backslash - Mar 20, 2009 11:57 AM
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.
texture no square surface - kendric - Mar 20, 2009 12:51 PM
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?
texture no square surface - JustinFic - Mar 20, 2009 01:03 PM
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:
And a tutorial is here:
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.)
texture no square surface - AnotherJake - Mar 20, 2009 01:10 PM
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.
texture no square surface - kendric - Mar 20, 2009 03:17 PM
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
// Set a blending function to use
// Enable blending
//Set the texture to use
Texture *texture=[textures objectAtIndex:1%frames];
if (endArc < startArc)
float temp = endArc;
endArc = startArc;
startArc = temp;
//2 for the remainder when we draw the last arc
//2 for the start point since its a triangle fan
//GLshort textureVertices =
// 0, 1,
// 1, 1,
// 0, 0,
// 1, 0,
for (theta = startArc; theta < endArc; theta += ARC_SEGMENT)
float x = (float) sin(endArc) * radius;
float y = (float) cos(endArc) * radius;
glVertexPointer (2, GL_FLOAT , 0, spriteVertices);
glTexCoordPointer(2, GL_FLOAT, 0, textureVertices);
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
P.S The semi circle part is correct, i was rendering only half a circle in my test.
texture no square surface - kendric - Mar 20, 2009 03:34 PM
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.
texture no square surface - kendric - Mar 20, 2009 05:26 PM
Yeah!. I was using strip instead of triangle fan. Switched that and it worked. No texture pinch either. Looks exactly like what I wanted.