IOS GLKit Textures for Cube - ios

new to IOS OpenGL programming. I have worked through a few tutorials that talk about the basics of OpenGL ES and been able to create a small demo program that draws cubes in a scene at positions I want. Id like to apply a texture to the faces of the cube but for some reason this seems to be a near impossible task to figure out. Im using GLKit , Ive searched all over and can't find a dead simple tutorial on how to do this without a lot of other fluff. Can anyone point me in the correct direction or have a tutorial on this? It doesn't seem like this should be hard thing to do. I must be missing something..

Go here for many tutorials bout this http://www.raywenderlich.com/
or here
http://www.raywenderlich.com/5223/beginning-opengl-es-2-0-with-glkit-part-1
this one explains about textures in detail:
http://db-in.com/blog/2011/02/all-about-opengl-es-2-x-part-23/
Id recomend not to use glkit directly (maybe some helper methods) since even tho it is easier as it works like opengl 1 most of the tutorials for gl es 2.0 wont use it and you will get confused.
Use this one for glkit to load textures
https://developer.apple.com/library/ios/#documentation/GLkit/Reference/GLKTextureLoader_ClassRef/Reference/Reference.html#//apple_ref/doc/uid/TP40010922
Try google with something like glkit texture example
this is what i got :
https://github.com/jlamarche/iOS-OpenGLES-Stuff/blob/master/GLKit%20Stuff/GLKBaseEffect%20Drawing%20Example%20with%20Texture/blah/MCViewController.m
around line 119 you can see how to use the texture, i havent checked it but it seems valid. I usually prefer to just use normal opengl since even when you have a simple program the shader file is ridiculously simple, (like less than 10 lines).

Related

iOS - Displaying text with OpenGL ES 2.0

I'm surprisingly struggling a lot to display text with OpenGL ES 2.0. There are a ton of posts on stackoverflow, debating the subject, showing a few lines of code, or showing links from 2010 but working with OpenGL ES 1.x (not compatible).
But they are quite vague, and to my knowledge there is not complete code or convenient way to display text with version 2.
Do you know if there is a modern way to display text ? Like just adding a pod and writing something like this ?
[font drawText:#"This is a text" size:#12];
Thanks a lot in advance, any help would be very much liked.
EDIT 1 : I have to use OpenGL 2.0, and I can't use something else, for internal reasons.
EDIT 2 : I've found two libraries that do it :
FTGLES : It crashes at runtime when I try to use it
https://github.com/chandl34/public/tree/master/personal/c%2B%2B/Font
This one is simple but written for ES1, so I need to port the code to ES2.
EDIT 3 : ES1 and ES2 are different : ES2 works with shaders.
Since you are targeting ES2 and shaders are supported it might be a bit hard to create a tool that does this for you. But if you find such a tool it might be conflicted with your flow in many ways such as binding its own shaders and buffers, using settings on blending, depth buffer... Then if it would do that you are having trouble as you may not have a good control over how and where the text is drawn (on a 3D rotating box for instance).
But from your question (it's snippet) it seems more like all you want to do is add some 2D overlay with text which would look exactly like using an UILabel. If this is the case then I suggest you to actually use UILabel to draw these texts. You can add all of these views easily on your view that shows openGL content.
In the other case where you still need to draw text on a 3D object and want to do it very easily I suggest you to still use UILabel but create its screenshot and push it to a new (or atlas) texture. Then you can draw it as any other object. UILabel will then handle all fonts, alignments, colors, multiline and text wrapping, font size adjustments... So if you already have a system to draw a texture in the scene you should not be too far from creating yourself a tool that draws some text on the screen since you use a texture to transfer the data.
Nothing has changed since OpenGL ES1. Usually text is displayed in planar projection and created quads that are textured using font texture. There are many tutorials on this topic.
One example how to do it.
However, this is quite a lot of work when you started from scratch.
There might be better way, but depending on what you plan to do might not be suitable. You may mix UIKit with OpenGL view, having text drawn with UIKit as overlay. (UILabel, UIButton..etc.)

How do I program Open GL without only Coordinate Geometry

I'm starting to teach myself Open GL. I'm learning it for a pretty large iOS project. From what I can see so far, the way I'd program the graphics in my app is just a ton of coordinate geometry and meticulously typing out numbers. I'd like to use a graphics generator such as Blender to make some of these images. Can I use Blender for something like this in order to minimize the amount of annoying math necessary or am I restricted to vaguely picturing something in my mind and hoping I'm good enough at math to draw it? If it's the ladder, what other alternatives to Open GL can I find that would work for iOS?
Yes, you can use a tool like Blender to create your models and then write code to load them in OpenGL. Here's some sample code and it even uses Blender. This was the first thing that came up when I did a web search for "loading obj files in OpenGL".

up-to-date simple OpenGL ES tutorial / template for iOS

At the moment i can draw a route on a map.
On the map i can zoom and i can pan. If the route is very big it goes really slow.
Therefor i want to do it with OpenGl.
From the map i can convert coordinateToPixel and get the current zoom.
I thought it would be the best to base the translation and zoom on that for the transformation matrix.
I never worked with OpenGL before. I have been reading stuff for the last few hours but most stuff i read is outdated or goes into things i don't care about for now like shaders.
Can someone provide me with resources for simple stuff like on the image?
I never worked with OpenGL before.
You are asking a lot, and I do mean a lot, of work from yourself if you want to switch from using native iOS drawing methods to using an advanced real-time rendering system that you don't even know yet.
I agree with Brad Larson that you are going to go much further and faster by leveraging the tools in iOS for your purpose. However, that does not mean you can't improve performance while using them.
I have found that when using Core Graphics for complicated drawing, you can dramatically reduce the time it takes to render a drawing by drawing it on a background thread. And Apple makes it much much easier to learn and use Grand Central Dispatch than the time it would take you to do all of this in OpenGL.
I learned how to use dispatch queues also for the single purpose of making drawing go faster. The simple technique is to render in the background, then take the results to the main thread for displaying them. Since you already have your drawing code figured out, you won't have to do much extra work to take this extra step, and I think you will be impressed with the performance.
I saw an improvement of at least 5 - 10 times in drawing speed when I implemented Core Graphics drawing with dispatch queues. They are really awesome.

Graphics for a iOS 2D Game

I've already published a 2D game on the App Store, but I've noticed that when I add too many objects, the fps drop down, and it's a quite simple game, so I believe it shouldn't happen.
So I think that I'm not rendering the graphics properly.
What should I use, OpenGL ES, Quartz 2D, ...?
I've been reading Apple's documents about OpenGL ES for iOS, but they hardly ever mention 2D, so I'm not sure if it can be used for this.
I'm now using Quartz 2D, (I guess it's UIView, UIImages, UIImageViews), but in fact, I'm not using the drawRect method of the views, ever. I create the images or graphics within the init function of the view, and a save them into a variable if I need to modify their properties later.
Any suggestion, recommendation, pdf would be highly appreciated! :)
PS: Here's a link to the game, if you want to have a better idea about it: http://itunes.apple.com/es/app/kipos/id494638587?mt=8
I recommend you use Cocos2D. Its features will make game development a lot easier for you. If you think you're up for a challenge, try OpenGL ES. I'll warn you though: it has a very steep learning curve.

Drawing custom shapes in an iOS game built upon cocos2d

I'm looking to draw a custom shape (say, a solid rectangle) using openGL ES in an iOS game built upon the Cocos2d framework. In another StackOverflow question, I saw a suggestion to use [CCDirector sharedDirector].openGLView; however, I am unsure as to how to go about this. Perhaps someone can provide an example or point me to some sample code?
Thanks in advance!
There are two tutorials I can recommend for doing this, depending on what exactly you are trying to achieve.
Generating Textures using CCRenderTexture - here
Generating Textures using OpenGL - here

Resources