Using SDL2 with iOS native objects |
leadro
|
Anybody help me, please!!!
|
|||||||||||
|
DLudwig
|
How, and more importantly, when (relative to SDL's window + renderer creation calls), are you adding the UIKit controls?
|
|||||||||||
|
Re: Using SDL2 with iOS native objects |
msturner
|
The short answer is you don't. If you want to use UIKit, you may as well ditch SDL and just use UIKit. Are you concerned about portability or just focusing on the iOS platform? |
|||||||||||||
|
Using SDL2 with iOS native objects |
Maxim Tartachnik
Guest
|
Hi all,
I'm try to using SDL 2 for iOS application. I'm build the libSDL2.a and add it to the my project. Also I'm add an all headers to application project. For initialization I'm use next code: /* initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { fatalError("Could not initialize SDL"); } window = SDL_CreateWindow(NULL, 0, 0, m_curScreenResolutions.deviceScreenResolution.size.height, m_curScreenResolutions.deviceScreenResolution.size.width, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS); renderer = SDL_CreateRenderer(window, -1, 0); and then for drawing my images I sue next code: struct displayImage { float x, y; SDL_Texture *texture; long width, height; }; SDL_Rect srcRect; SDL_Rect dstRect; for (int i = 0; i < [m_imagesForDisplaying count]; i++) { NSValue *value = [m_imagesForDisplaying objectAtIndex:i]; displayImage preImage; [value getValue:&preImage]; srcRect.x = 0; srcRect.y = 0; srcRect.w = preImage.width; srcRect.h = preImage.height; dstRect.w = preImage.width; dstRect.h = preImage.height; dstRect.x = preImage.x; dstRect.y = preImage.y; SDL_RenderCopy(inputRenderer, preImage.texture, &srcRect, &dstRect); } /* update screen */ SDL_RenderPresent(inputRenderer); Pictures draw perfectly, but after drawing I do not see any iOS native objects (UIView, UIButton, ect.) no the application UI, even if I add this objects programmatically. Can any body explains me how I can use SDL with iOS native objects? Thank you. -- Maxim Tartachnik |
|||||||||||
|
leadro
|
Hello, I'm try to add the UIKit controls after SDL's window + renderer creation. For adding UIKit controls, for example UIView, I'm use next code:
Also I try to add the UILable to the current view via next code:
|
|||||||||||||||||
|
Re: Using SDL2 with iOS native objects |
leadro
|
Hello, I need to integrate the SDL features for drawing images into iOS application. But, as I say previously, I have a problem with showing UIKit controls over SDL_Window + SDL_Renderer |
|||||||||||||||
|
DLudwig
|
In the above bit of code, what is 'self'? Is it a UIViewController, or a subclass of one? SDL2, as of this writing, has its own subclass of UIViewController. Assuming you're creating everything in one UIViewController, then trying to display SDL's view controller (via SDL_RenderPresent), SDL's view could end up being overlaid on top of yours. In my experience, it's possible to overlay UIKit controls on top of SDL's in either of two ways: 1. by getting a pointer to SDL's view controller, getting its view, then adding new controls as subviews. I've done this in the past to overlay a UIKit text field onto an SDL app, in order to get use of iOS' cut, copy, paste, and deletion controls. 2. by getting a pointer to SDL's view controller, creating a new view controller, then displaying it modally over SDL's view controller. This can be used to display a Game Center view controller, or a score-sharing view controller, for example. Here is one way to get SDL's view controller: create your window, create the renderer (using the OpenGL ES based renderer, not the software-only one), use SDL_GetWindowWMInfo to get a pointer to the app's UIWindow, then use the 'rootViewController' method on the UIWindow to get the view controller. Here's some extremely rough example code:
With this, one or more UIKit controls could then be added to the screen as such:
UIKit is very much capable of drawing images. :-) Is there some feature that SDL has that UIKit doesn't have, outside of platform-independence, that you're looking for? The code you posted looks fairly iOS-centric and non-portable. I'm wondering if you wouldn't just be happier and/or better off using UIKit instead of SDL for the time being. |
|||||||||||||||||||||
|
Using SDL2 with iOS native objects |
Vittorio Giovara
Guest
|
You can also subclass SDL_UIKitAppDelegate and have pure objective-c code before launching the sdl view.
http://code.google.com/p/hedgewars/source/browse/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m Vittorio On Fri, Jan 4, 2013 at 6:32 PM, DLudwig wrote:
|
|||||||||||||
|
Re: Using SDL2 with iOS native objects |
DLudwig
|
Neat! This looks like a remarkably useful technique, especially given iOS' close ties to app delegates. Thanks for the info! -- David L. |
|||||||||||||
|
leadro
|
Hello, thank you for your answer, I try this code, but I have a problem with initialization SDL_SysWMinfo. I'm share a screenshot of this problem: https://docs.google.com/open?id=0B1IEde1HB7cUSVE1NGpVNDRHTUU
I know that the UIKit a very powerful for drawing images. But I have a very specific task and UIKit can't do some image processing[/img] |
|||||||||||||||||
|
DLudwig
|
I'm not entirely sure what's happening here. Maybe try #include'ing <SDL_syswm.h> ? There is a small error in the code I posted before. It's on a different line, specifically one that declares and sets 'appWindow'. Here's a modified version:
|
|||||||||||||||
|
leadro
|
I'm already included <SDL_syswm.h>, but nothing changes... May be anybody have any idea, what is happening? |
|||||||||||||||||
|
leadro
|
Also, maybe I have a problem with library,
DLudwig, can you send me, please, your variant of library and I try this code with your library. Or maybe you can guide me how I can build SDL library (or framework). |
|||||||||||
|
DLudwig
|
While I usually use a variant of SDL in whatever project I'm working in, the code sample I listed does work in stock SDL 2.x, as far as I can tell. I tried it with a fresh snapshot of SDL 2.x code from hg.libsdl.org created yesterday afternoon. |
|||||||||||||
|
leadro
|
Hello, I'm also try to use base variant of SDL from hg.libsdl.org. And I cloned it 2-3 hours ago and build it, but I steel have a problem with initializing SDL_SysWMinfo member Maybe it's problem with project... What I did: 1. Create in the Xcode "Single View Application"; 2. Add to this project libs: libSDL2.a and libSDL2main.a; and headers: All SDL headers after building; 3. Into method -(void)viewDidLoad I add code for initialization SDL:
4. Then try to add native UIKit controls. Maybe I'm do something wrong..... Most likely I'm doing something wrong, but I don't know what... Can you help me? Thank you. |
|||||||||||||||||
|