function ccDrawPoly not found in cocos2d - how do I draw a polygon? - cocos2d-iphone

I upgraded to Cocos2D v 3. ccDrawPoly is no longer a function. How do I draw a polygon?
ccDrawingPrimities.m, where the function was, no longer exists.

Related

drawing bezier curves in Cocos2d v3.4.. no more ccDrawQuadBezier

In Cocos2d-iphone 3.4 I want to draw a bezier curve and be able to manipulate it by dragging points on it.
It looks like in previous versions of Cocos2d I would have used: ccDrawQuadBezier
ccDrawCubicBezier
ccDrawCatmullRom
ccDrawCardinalSpline
These don't appear to be available in Cocos2d 3.4

Text Clipping with Qt OpenGL

I'm currently working with Qt5.1 and trying to draw some OpenGL stuff within a QGLWidget:
void Widget::paintGL() {
startClipping(10, height()-110,100,100);
qglColor(Qt::red);
glBegin(GL_QUADS);
glVertex2d(0,0);
glVertex2d(500,0);
glVertex2d(500,500);
glVertex2d(0,500);
glEnd();
qglColor(Qt::green);
this->renderText(50, 50, "SCISSOR TEST STRING");
endClipping();
}
The quad gets clipped correctly but the text doesn't.
I tried three ways of implementing the startClipping method: scissor test, setting the viewport to the clipping area and with a stencil buffer.
None of them worked and the whole string was drawn instead of beeing cut off at the edges of the clipping area.
Now my question is: Is this behavior a bug of Qt or is there something, I missed or another possibility I could try??
After a week of trying around, I suddenly found a very simple way to achieve, what I was looking for.
Using a QPainter and it's methods instead of the QGLWidget's renderText() simply makes text clipping work:
QPainter *painter = new QPainter();
painter->begin();
painter->setClipping(true);
painter->setClipPath(...); // or
painter->setClipRect(...); // or
painter->setClipRegion(...);
painter->drawText(...);
painter->end();
As I understand it, this is by design. According to the documentation ( https://qt-project.org/doc/qt-4.8/qglwidget.html#renderText ):
Note: This function clears the stencil buffer.
Note: This function temporarily disables depth-testing when the text is drawn.
However for the 'xyz version' (overloaded function)
Note: If depth testing is enabled before this function is called, then the drawn text will be depth-tested against the models that have already been drawn in the scene. Use glDisable(GL_DEPTH_TEST) before calling this function to annotate the models without depth-testing the text.
So, if you use the second version (by including a z-value, eg 0) in your original code, I think you get what you want. I think you would want to do this if you do a scene that is 'real' 3D (eg, axis labels on a 3D plot).
The documentation does also mention using drawText.

Scale or resize a sprite with image

The idea is: I have a sprite with rectangle image
CCSprite *sprite = [CCSprite spriteWithFile:#"Rectangle.png"];
When I touch the sprite, 8 red points will appear
Holding a point and drag it to scale(resize) the image like this
Can anyone show me how to do or give me a sample code.
I am not sure about this but you can redraw a texture on that 8 points.
It seems similar to draw texture of soft body. I have implemented that for my game and in that i use 12 points and on that 12 point i tried to draw the texture.
So what you can do is you have to redraw the texture on that points when any of the point dragged. This is a tutorial for soft body,but You can refer this tutorial for reference.
http://www.uchidacoonga.com/2012/04/soft-body-physics-with-box2d-and-cocos2d-part-44/
It's not the same thing what you are looking for but yes using this you can implement.

OpenGL rendering and rasterization of slivers

I am testing some rendering stuff with OpenGL and I noticed that I have some issues with long thin polygons that are forming a plane. So when having two of these long polygons directly next to each other, snapping at the long side, I noticed that some of the pixels at the edge are invisible. These invisible pixels move around when I move the camera.
What I found is that this is because the pixels at the edge of these "sliver" polygons will be invisible because the rasterization thinks that they are not within that polygon at this specific view angle.
What I didn't figure out is how to tell OpenGL to also put pixels on screen that are directly at the edge of that polygon.
If you found my description of the problem a bit weird see http://www.ugrad.cs.ubc.ca/~cs314/Vjan2008/slides/week5.day3-4x4.pdf page 27 and following. That's what I mean.
EDIT: ok i think i have to make clear what my problem is, because i have a feeling that i cant adress it with anti aliasing techniques
aaa|b|cc
aaa|b|cc
aaa|b|cc
^ ^
1 2
- the polygons a, b and c form a plane
- some pixels at edge 1 and 2 are invisible at certain camera angles
What I didn't figure out is how to tell OpenGL to also put pixels on screen that are directly at the edge of that polygon.
In general, you don't. If OpenGL thinks that a part of a triangle is too thin to be rendered for a given resolution, then it's too thin to be rendered. The general form of this issue is called called "aliasing".
The solution is to use an antialiasing technique. For example, multisampling. When you create the context, select a number of samples to use.

CCRenderTexture size and position in Cocos2d-iphone

I was trying to use CCRenderTexture for pixel perfect collision detection, as outlined in this forum posting:
http://www.cocos2d-iphone.org/forum/topic/18522/page/2
The code "as is" works, and I have integrated it with my project
But I am having trouble doing some of the other things discussed:
If I create the renderTexture to be any size less than the screen size, the collision detection doesn't work properly - It seems to show collisions when the sprites are close (<15px) to each other but not actually colliding.
Also I have trouble changing the location of the render texture. Regardless of the position I specify, it seems to go from bottom left (0,0) till the width & height specified. I followed this post:
http://www.cocos2d-iphone.org/forum/topic/18796
But it doesn't solve my problem. I still get bad collisions like specified above. Also, the first post I mentioned on the list contains comments by many users who have resized their textures to 10x10, and repositioned them off screen.
Does anyone have any sample code, so I can see what I am doing wrong? I just use the boilerplate code:
CCRenderTexture* _rt = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
_rt.position = CGPointMake(winSize.width*0.5f, winSize.height*0.5f);
[[RIGameScene sharedGameScene]addChild:_rt];
_rt.visible = YES;
I use cocos2d-iphone 1.0.1
You need to move the sprites you intend to draw into the region of the renderTexture before calling draw or visit. Moving the renderTexture does not change the position of _rt.sprite.
The intersection rectangle must be in the region of the renderTexture, otherwise you get inaccurate collisions.
It seems that you cannot change the position of _rt.sprite.
The solution that I use is to determine the origin (x,y) of the intersection box, and offset both the colliding sprites by that much. This will ensure that the intersection rectangle will have its origin at 0,0. Then I calculate the intersection rectangle again (after ensuring the origin of the intersection rect is 0,0) . Then I follow the instructions in the forum posting.
When determining the dimensions of the render texture, I ensure that they are at least as large as the intersection rectangle, and I ensure that the intersection rectangle is fully inside the render texture. This way there are accurate collisions. If even part of the intersection box is outside the render texture i get inaccurate collisions, so before drawing into the render texture, make sure you move the sprites you intend to visit so that the intersection box is entirely within the render texture.
Remember to move the sprites back after you're done. :)