draw texture with polygon shape - cocos2d-iphone

I am trying to draw the texture with polygon shape. What is the logic and how will i draw texture in polygon shape with dynamically?
I am working on cutting the rectangle, going to apply the texture in sliced shape(it may any shape).
Can any one assist me?

Don't think you can achieve it only using cocos2d classes. You need to draw with openGL. You already have polygon vertices, triangulate your polygon(here is an example) and set your texture to draw it.

You can also use LevelHelper (unfortunatelly - not free :( ) which has a built-in cutting engine : link

Related

Qt3D C++ How to shape outline?

Does anyone know how to outline a shape in Qt3D using C++ (not QML).
For example using a cuboid mesh and make it transparent but outline the edges of the shape. Please see pictures attached on what I mean.
To draw the outline of a shape, you can follow these steps:
Draw everything as normal.
Draw only the outline of the selected object.
When drawing the outline, you need to use an outline effect, which can be implemented in two render passes:
Render the geometry to a texture using a simple color shader.
Render to screen using a shader that takes each pixel in the texture and compares the surrounding pixels. If they are equal, we are inside the object and the fragment can be discarded. If they differ, we are on the edge of the object and we should draw the color.

How do I map a texture correctly onto a convex polygon in SFML or OpenGL?

I want to represent my Objects as textured convex Polygons. For the most part those will just be rotated rectangles but i want to support convex shapes too and thats where the problems arise.
I worked with Blender a while ago and there you could unwrap the 3D-Objects and explicetely tell Blender which vertex of the Shape has which Position on the Texture.
Would it maybe be better to just request the Texture to have the size of the bounding Rectangle of the Shape so I can just apply the texture with SFML?
PS: Im sorry i cant post pictures to clarify my question.
or OpenGL
In OpenGL, typically you'll have two (or more!) vertex attributes: position and texture coordinate. That's basically saying which vertex of the Shape has which Position on the Texture.
That's what SFML has to be doing internally, and since its Open-Source, you might just peek inside and see if your "bounding rectangle" idea has a chance of working (my guess is that it indeed does).

how to draw polygons in OpenGL that have an outline drawn with a black pen and another fill color

How can I draw a shape like this in OpenGL?
I mean, I know how to draw polygons in OpenGL. I want to know how to make the outline black and the fill color ( for example ) yellow?
You have 5 vertices. Draw a GL_POLYGON with them and then then a GL_LINE_LOOP.
Note that GL_POLYGON is only valid for convex polygons.
I would cheat. I would create the polygons in a 3d suite as meshes, and create different meshes for the borders. And then draw first the polygon and then the border, using the same transforms, with glDepthFunc(GL_LEQUAL).
In this way you can also give the border a nice outfit: you could make them look as if they were drawn by a pen, or sketched with a pencil or whatever. Also, this solution is good to go with modern OpenGL, while using GL_POLYGON is not .

Drawing textured triangle with directx

I'm making a 2D game that uses directx. Currently, I have a background texture (with more to come) that I draw to the screen. However, I only want a portion of the texture drawn to the screen. I know that I could use a rectangle with the draw function, but I need a greater degree of control. Is there a way to draw several triangles (using custom vertices) to the screen from my drawing? I've looked around the internet and this site, but I just can't seem to find what I want. I can give more information/code if needed. Thank you!

Circle on non plane surface in opengl

I need to draw a circle on some arbitrary non plane surface, but this circle should lay on surface and follow surface's irregular form. In other words ( that is actuially can be one of possible solutions) want to have a "shadow" like projection on non plane surface near the mouse pointer. Do I need to create in memory a sphere and project it on the surface ? Are there some other techniques to achieve the same goal?
Thank you in advance.
There are two ways to do this. First would be, to create a cylinder and intersect it with the surface, get the intersection segments, and draw them. If you already have a math library which you can leverage, and if you don't have to do intersections every frame, then this might be a good idea. You will get accurately what you want.
The other option, as you already suggested would be to use a projection. I am not sure though that, you will be able to see clearly the shadow of a circle on a surface. If however, you have parametric texture coordinates for your surface, you can create a texture with the circle imprinted on it, and apply this texture to the surface.