How to make nice openGL blended lines in cocos2d? - objective-c

i've written an algorithm to create electricity using ccDrawLine function in cocos2d for iphone. Currently, the ccDrawLine is a simple wrapper method for drawing openGL lines on the fly.
My algorithm is sound and works as I want. But the problem is with the appearance of the electricity in general.
I have little openGL programming knowledge(hence the use of the wrapper) and I require the ccLines to be blended nicely and look like either lasers or electricity.
How can I go about doing this avoiding the use of openGL programming if possible, otherwise i'll need to learn it.

you sample the surrounding pixels for each pixel of the area and average it out. This is the most basic way i know but it is not very fast so you could blend in 2x2 squares instead of 1x1 or even 4x4 and move over every iteration because for a nice effect you would do maybe 3 times.

Related

Obj-C method to assign colours to pixels directly?

Currently, I am using SKSpriteKit in order to do all of my graphics stuff in any of my programs. Recently, I’ve been interested in drawing things like the Mandelbrot set, Bifurcation curve, etc.
So to draw these on my screen, I use 1 node per pixel… obviously this means that my program has very low performance with over 100000 nodes on the screen.
I want to find a way of colouring in pixels directly with some command without drawing any nodes. (But I want to stick to Obj-C, Xcode)
Is there some way by accessing Core graphics, or something?
Generally you would use OpenGL ES or Metal to do this.
Here is a tutorial that describes using OpenGL ES shaders with SpriteKit to draw the mandelbrot set:
https://www.weheartswift.com/fractals-xcode-6/

Would using cocos2d be easier for a drag and match game?

I am pretty new to making games, but I am pretty familiar with programing iOS. I am creating a shape matching game, so there would be an array of different shapes and the user would drag the shape to the correct corresponding shape if they get it right it would stay and if they get it wrong it would shoot back. Now my question is would that be easier using cocso2d or any game engine or would it be just as easy not using one, just using a touch event?
Since the game you are describing is not graphically intense - I would recommend using UIKit. Couple of reasons why I would use UIKit over cocos2d:
Interface builder / Storyboards are awesome. You can lay out your
screens and game elements on screen. (I know tools exist to do this
using cocos like CocosBuilder, but IMO they just don't compare to
working directly in XCode)
UIKit animations couldn't be easier and you can do some pretty powerful things with minimal code.
You have direct access elements such as UITableView, UICollectionView, UIScrollView, etc. There are cocos nodes that mimic these, but they don't match up in terms of response and behavior.
For more graphically intense games I would still use cocos2d hands down. Some scenarios when you would use it:
You have a large number of sprites with a large number of animations (opengl is fast)
You want to use opengl based effects like particles, lighting, etc.
You need a physics engine
You want to work off a prebuilt game engine (there are tons such as levelsvg, kobold2d, line starter kit, etc)
Hope this helps you.

Correctly implement the blocks in the drawing view

How to correctly implement the blocks in the drawing view, so that when they could cut the line in two parts. Using UIImageView or UIImage?
After the cut blocks should fall under the influence of physics.
First, how many cuts could happen in total? How many independent pieces of block could result? 10? 100? Before implementing any of these, test moving that number of objects around on an iPhone or iPod touch. Just because it works on the simulator does not mean it will be fast enough on the actual device.
Second, as already noted, there are libraries for game graphics and physics that may do a lot of the work for you. Cocos2D appears to be a popular option, combining OpenGL drawing with relatively easy access to physics libraries.
Anyway, to do your own drawing, here are the choices:
Move all the graphics into OpenGL. This should not be undertaken lightly - you lose a lot of the ease of working in Cocoa Touch. You also have maximum control over your graphics and animation, and can achieve the smoothest performance if you take the time to optimise it.
Have a single UIView, adding CALayer sublayers to its main layer for every independent block. CALayers are designed for rapid moving and compositing. However, if you're running a physics simulation, your first step will be to remove their animation behavior. This tutorial series may be useful.
Have a separate UIView for each block. This will have similar performance to using CALayers, as UIViews are actually drawn with CALayer. This option will use up more memory, (you have at least as many layers and more views than before), but you have all of the power of CALayers plus a few drawing options that are easier on views.
Have a single UIView, and draw every block during its drawRect method. This may look easy to implement, but it will almost certainly be too slow.
If at all possible, test each of these. Before you continue with the cutting and physics parts, how many blocks can you animate across the screen before it slows down too far? Can you make a game with that Remember that your physics system will slow the game down when it does work.

Motion Blur Emplementation on OpenGL ES

I'm a novice in OpenGL ES 1.1(for IOS) texturing and I have a problem with making the effect of motion blur. During googling, I found that I should render my scene in different time moments to several textures and then draw all these textures on the screen with different alpha values. But the problem is that I don't know how to implement all this!So,my questions are:
How to draw a 2D texture on the screen? Should I make a square and put my texture on it?Or may be, there is a way to draw a texture on the screen directly?
How to draw several textures(one upon another) on the screen with different alpha values?
I've already come up with some ideas, but I'm not sure if they are correct or not.
Thanks in advance!
Well, of course the first advice is, understand the basics before trying to do advanced stuff. Other than that:
Yes indeed, to draw a full-screen texture you just draw a textured screen-sized quad. An orthographic projection would be a good idea in this case, making the screen-alignment of the quad and its proper sizing easier. For getting the textures in the first place (by rendering into them), FBOs might be of help, but I'm not sure they are supported on ES 1 devices, otherwise the good old glCopyTexSubImage2D will do, too, albeit requiring a copy operation.
Well, you just draw multiple textured quads (see 1) one over the other. You might configure the texture environment to scale the texture's color with the quad's base color (glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)) and give your quads a color of (1, 1, 1, alpha) (of course lighting should be disabled). Additionally you have to enable alpha blending (glEnable(GL_BLEND)) and use an appropriate blending function (glBlendFunc(GL_SRC_ALPHA, GL_ONE) should do).
But if all these terms don't tell you anything, you should rather first learn the basics using a good learning resource before delving into more advanced effects.

How can i draw a set of lines and areas in Objective-C?

I need to make a program for iPad. This program has to manage a planimetry.
In your opinion, what's the best way to draw a planimetry (made in xml by a set of tag line with x and y coordinates) by assuring a good performance?
You have to consider that each planimetry is composed by thousand lines. Since pinching and translating can ruin performance (maybe), do you think that the best way to do that is to use a particular render (2d/3d)?
Can OpenGL help me? I wish manipulation of planimetry (traslation, rotation, zoom) is fluid. No jumps.
Quartz / CoreGraphics seems to be the best solution for 2D. I think it's HW accelerated.
Apple Documentation