Dialog boxes with SDL + OpenGL

Member
Posts: 156
Joined: 2002.10
Post: #1
Has anyone yet come up with a decent way to display a dialod box (for example to accept input text, or for control configuration) using SDL and OpenGL. As I understand it, SDL is written in Cocoa, so I would hope to be able to design the windows using IB, but how to connect that up to my SDL event loop I don't know.

Has anyone ever done or seen anything like this. Especially if you had any example code that would be great. Did any of the uDG 04 entries with SDL use dialog boxes (or any Aqua widgets for that matter)?

Cheers

- Iain
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #2
I posted this up a while back, but have eventually got around to solving my own problem. IIRC there were a few other people interested in the solution,so I'll outline it here.

Create a new NIB file with your dialog window in it, and set up all the widgets that you need. Subclass NSPanel, and add Outlets for every widget that you want to read data from, e.g. textFields, etc. to the subclass. Also add actions for each of the buttons. Connect up all the outlets & actions, and then generate the classes and add them and the NIB to your project.

To show your window, I simply created an NSWindowController, calling initWithWindowNibName, and then [NSApp runModalForWindow:]

Make sure to put [NSApp stopModal] in each of the button actions that can close the window.

When control returns you can then call [winCon close] to close the window, and then read any data you want out of the data fields. of the NSPanel subclass.

Anyway, I thought I might write up a tutorial on this, with code snippets and IB pictures, so what format would this want to be in? XHTML? textile?

Hope this is useful to folks - any questions, just ask!

Cheers

- Iain
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #3
or you could just put, in the source file (not the header file, it might conflict with some symbols!)

Code:
#ifdef __APPLE__
#include <Carbon/Carbon.h>
#elif defined WIN32 //if you want to have windows dependability
#include <windows.h>
#endif

then in, perhaps a dialogue function:
Code:
void ErrorDialogue(char *cmsg)
{
#ifdef __APPLE__
    Str255 msg;
    c2pstrcpy(msg, cmsg);
    StandardAlert(kAlertStopAlert, "\pError", (ConstStr255Param)msg, NULL, NULL);
#elif defined WIN32
MessageBox(NULL, cmsg, "Error", MB_ICONERROR | MB_OK);
#else
printf("ERROR: %s\n", cmsg);
#endif
}

It's not magic, it's Ruby.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #4
IBethune Wrote:Has anyone yet come up with a decent way to display a dialod box (for example to accept input text, or for control configuration) using SDL and OpenGL. As I understand it, SDL is written in Cocoa, so I would hope to be able to design the windows using IB, but how to connect that up to my SDL event loop I don't know.

Has anyone ever done or seen anything like this. Especially if you had any example code that would be great. Did any of the uDG 04 entries with SDL use dialog boxes (or any Aqua widgets for that matter)?

My SDL-based uDG 04 entry (Okugai) had one dialog box, accessible only while in windowed mode: the about box Rasp , as well as a working menu bar & menu bar items.

IBethune Wrote:I posted this up a while back, but have eventually got around to solving my own problem. IIRC there were a few other people interested in the solution,so I'll outline it here. [...]

Very interesting, I've got to try that!

@Nayr: I think you are missing the point Wink
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #5
Yup, the point is that you can design your own custom windows in IB, rather than jsut use a standard alert dialog.

- Iain
Quote this message in a reply
Member
Posts: 144
Joined: 2004.07
Post: #6
Are you talking about something along these lines?

[Image: SDLwindow.png]

This was taken from a game I'm working on that uses SDL. A few months ago I went ahead and hacked SDLMain to allow for me to do such a thing. If you'd like for me to post the code and a sample project I would gladly do so.

Derek.

EDIT: just read your second post, we probably are taking similar approaches. Let me know if you still want me to jump in.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #7
I suspect I did Rasp
I only read the second post

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #8
*BUMPS 4 YEARS LATER*

I'd be very grateful if someone could share how to do this. I'd need a dialogue box at the start of my application so user can chose the graphics options (resolution, windowed mode, quality) before the SDL game runs. Sorry, I'm terrible at Cocoa Sad

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Member
Posts: 45
Joined: 2008.04
Post: #9
For sauerbraten we cheated - we made a pure cocoa app which acted as a launcher with all the options, and that then exited and fed command line args to the SDL app... Means we didn't have to tweak SDL, and the win/linux ports were none the wiser.
Quote this message in a reply
Member
Posts: 35
Joined: 2009.01
Post: #10
Hello,

I expect the reason dialog boxes aren't working by default is because you are "capturing" the main display, thus not allowing windows to exist on this display. Instead, you can try putting a non-movable window (panel) without a title bar underneath the menu bar, and hiding the menu bar. Relevant code shown:

Code:
@implementation GameWindow

// note this must be an NSPanel subclass

// by default, NSPanels do not accept keystrokes.  You probably want this
-(BOOL) canBecomeKeyWindow { return YES; }

-(id) initWithContentRect:(NSRect)contentRect {
    
    if (self = [super initWithContentRect:contentRect
        styleMask:NSBorderlessWindowMask
          backing:NSBackingStoreBuffered
            defer:NO]) {
                                  
        [self setHasShadow:NO];
        
        return self;
    }
    
    return nil;
}

-(void) awakeFromNib {
    
    NSRect fullScreenRect = [[NSScreen mainScreen] frame];
        
    self = [self initWithContentRect:fullScreenRect];
    
    [myGameView setFrame:[self frame]];
    [[self contentView] addSubview:myGameView];
    
    [self makeFirstResponder:myGameView];
    
    [NSMenu setMenuBarVisible:NO];
    
    [self setAcceptsMouseMovedEvents:YES];
}

@end

A window which covers the entire screen shouldn't have a shadow in case the use has a second screen (which I expect many developers do). The way I implemented this is with the window and openGLView in the nib file, so the window needs to be re-initialized and its (outlet) view matched to its own size.

By using this approach instead of using something like CGCaptureDisplay(), you allow other windows to enter the screen, you can hide the game window, make use of the menu bar, etc. In addition, you can also display dialog boxes over top of the game window.
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #11
Thanks very much, my lack of cocoa knowledge shows but i think I got it working mostly. Man Cocoa is weird Rasp

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #12
Najdorf Wrote:Man Cocoa is weird Rasp

I think you mean awesome! Smile

- Lincoln Green
http://www.binkworks.com/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Tricks with dialog boxes in fullscreen mode causing permanent framerate drops. Sea Manky 2 3,070 Aug 7, 2007 06:20 AM
Last Post: Sea Manky
  Game preference type dialog nalenb 2 2,131 Dec 22, 2005 03:05 PM
Last Post: AnotherJake