[DEV] first open GL display on MACOSX ==> simple triangle...

This commit is contained in:
Edouard DUPIN 2013-04-07 23:42:23 +02:00
parent 09ef9c8a19
commit b3465bcf44
6 changed files with 144 additions and 104 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit 516f0df12fa172d39a7de30e2c4eb9ec5275634c
Subproject commit 64812713c7bfa87ab1f3368cf58cca7d6d996007

View File

@ -29,7 +29,7 @@ endif
LOCAL_C_INCLUDES :=
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
LOCAL_EXPORT_LDLIBS := -framework Cocoa -framework OpenGL
LOCAL_EXPORT_LDLIBS := -framework Cocoa -framework OpenGL -framework QuartzCore -framework AppKit
LOCAL_CFLAGS := -Wno-write-strings \
-DEWOL_VERSION_TAG_NAME="\"$(LOCAL_VERSION_TAG)-$(BUILD_DIRECTORY_MODE)\"" \
@ -44,10 +44,8 @@ LOCAL_SRC_FILES := $(FILE_LIST)
LOCAL_SRC_FILES += ewol/renderer/os/gui.MacOs.cpp \
ewol/renderer/os/gui.MacOs.Interface.mm \
#DFGSDFGSFDGDSFGSDFG := \
# ewol/renderer/os/gui.MacOs.AppDelegate.mm \
# ewol/renderer/os/gui.MacOs.OpenglView.mm
ewol/renderer/os/gui.MacOs.AppDelegate.mm \
ewol/renderer/os/gui.MacOs.OpenglView.mm
# xcode compilation exemple sources :
## basic truchage

View File

@ -3,35 +3,21 @@
#import <ewol/renderer/os/gui.MacOs.AppDelegate.h>
#import <ewol/renderer/os/gui.MacOs.OpenglView.h>
@implementation MacOsAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
@end
#if 0
@implementation MacOsAppDelegate
@synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (BOOL)application:(MacOsAppDelegate *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
OpenglView *view=[[OpenglView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
OpenGLView *view=[[OpenGLView alloc]initWithFrame:[[NSScreen mainScreen] bounds]];
// Override point for customization after application launch.
[self.window addSubview:view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationWillResignActive:(MacOsAppDelegate *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
@ -39,7 +25,7 @@
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationDidEnterBackground:(MacOsAppDelegate *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
@ -47,21 +33,21 @@
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationWillEnterForeground:(MacOsAppDelegate *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
- (void)applicationDidBecomeActive:(MacOsAppDelegate *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
- (void)applicationWillTerminate:(MacOsAppDelegate *)application
{
/*
Called when the application is about to terminate.
@ -77,4 +63,6 @@
}
@end
#endif

View File

@ -1,37 +1,135 @@
/*
#import <Cocoa/Cocoa.h>
#import <ewol/renderer/os/gui.MacOs.Interface.h>
#include <ewol/renderer/os/gui.MacOs.AppDelegate.h>
int mm_main(int argc, const char *argv[])
{
return NSApplicationMain(argc, (const char **)argv);
}
*/
#import <Cocoa/Cocoa.h>
#include "ewol/renderer/os/gui.MacOs.Interface.h"
#include "ewol/renderer/os/gui.MacOs.Interface.h"
#import <ewol/renderer/os/gui.MacOs.OpenglView.h>
int mm_main(int argc, const char *argv[])
//int main(int argc, const char *argv[])
{
[NSAutoreleasePool new];
[NSApplication sharedApplication];
// set the quit policy and all stadard for Mac
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
// ---------------------------------------------------------------
// -- basic menu bar creation :
// ---------------------------------------------------------------
// set the basic menu bar (stadard on Mac OSX)
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
//add an item
id appMenuItem = [[NSMenuItem new] autorelease];
// add the item to the menu bar:
[menubar addItem:appMenuItem];
// set the main menu in the menu bar ...
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id appName = [[NSProcessInfo processInfo] processName];
// create the label to qui the application :
id quitTitle = [@"Quit " stringByAppendingString:appName];
// create the item to quit the appllication with META+q at shortCut
id quitMenuItem = [ [ [NSMenuItem alloc] initWithTitle:quitTitle
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
// add the item to the menu:
[appMenu addItem:quitMenuItem];
// set the application menu to the main app menu ...
[appMenuItem setSubmenu:appMenu];
id window = [ [ [NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 340, 480)
// ---------------------------------------------------------------
// -- basic windows creation :
// ---------------------------------------------------------------
// create a windows of size 800/600
id window = [ [ [NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]
autorelease];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
// set the windows at a specific position :
[window cascadeTopLeftFromPoint:NSMakePoint(50,50)];
// set the title
[window setTitle:appName];
// ???
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
NSRect window_frame = [window frame];
OpenGLView* view=[[OpenGLView alloc]initWithFrame:window_frame]; //NSMakeRect(0, 0, 800, 600)];
[window setContentView:view];
[view setAutoresizesSubviews:YES];
// Override point for customization after application launch.
//[window addSubview:view];
//[window addChildWindow:view];
//[window makeKeyAndVisible];
// start application :
[NSApp run];
// return no error
return 0;
}
// gcc -framework Cocoa -x objective-c -o testApplDirectMinimal sources/ewol/renderer/os/gui.MacOs.Interface.mm
/*
NSView* view0 = ...; // a view made with IB
NSView* view1 = ... ;// another view made with IB
NSWindow* window = [self window];
NSRect window_frame = [window frame];
NSView* cv = [[[NSView alloc] initWithFrame:window_frame] autorelease];
[window setContentView:cv];
[cv setAutoresizesSubviews:YES];
// add subview so it fits within the contentview frame
{
NSView* v = view0;
NSRect vframe = [v frame];
[v setHidden:YES];
[v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
NSView* tmp_superview = [[[NSView alloc] initWithFrame:vframe] autorelease];
[tmp_superview addSubview:v];
[tmp_superview setAutoresizesSubviews:YES];
[tmp_superview setFrame:window_frame];
[v removeFromSuperview];
[cv addSubview:v];
}
// add subview so it fits within the contentview frame
{
NSView* v = view1;
NSRect vframe = [v frame];
[v setHidden:YES];
[v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
NSView* tmp_superview = [[[NSView alloc] initWithFrame:vframe] autorelease];
[tmp_superview addSubview:v];
[tmp_superview setAutoresizesSubviews:YES];
[tmp_superview setFrame:window_frame];
[v removeFromSuperview];
[cv addSubview:v];
}
[view0 setHidden:NO];
*/

View File

@ -1,17 +1,12 @@
#import <Cocoa/Cocoa.h>
#if 0
#import <OpenGLES/ES2/gl.h>
#import <QuartzCore/QuartzCore.h>
@interface OpenglView : UIView {
EAGLContext *mimContext;
@private
GLuint framebuffer;
GLuint renderbuffer;
@interface OpenGLView : NSOpenGLView
{
}
- (void)drawView;
- (void) drawRect: (NSRect) bounds;
@end
#endif

View File

@ -1,70 +1,31 @@
#import <ewol/renderer/os/gui.MacOs.OpenglView.h>
#if 0
@implementation OpenglView
+ (Class) layerClass
#include <OpenGL/gl.h>
static void drawAnObject (void)
{
return [CAEAGLLayer class];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
eaglLayer.opaque = YES;
mimContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
BOOL setContext=[EAGLContext setCurrentContext:mimContext];
if (!mimContext || !setContext)
{
[self release];
return nil;
}
//Lets init and bind render buffer with current context
glGenRenderbuffers(1, &renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
[mimContext renderbufferStorage:GL_RENDERBUFFER fromDrawable: eaglLayer];
//Frame buffer- which is a collection of render buffers and other kind of buffers like depth etc.
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
//Setting the dimensions of your view area.
glViewport(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
[self drawView];
glColor3f(1.0f, 0.85f, 0.35f);
glBegin(GL_TRIANGLES);
{
glVertex3f( 0.0, 0.6, 0.0);
glVertex3f( -0.2, -0.3, 0.0);
glVertex3f( 0.2, -0.3 ,0.0);
}
return self;
glEnd();
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawView
@implementation OpenGLView
-(void) drawRect: (NSRect) bounds
{
// Drawing code
glClearColor(1.0f, 0.0f, 1.0f, 1);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
[mimContext presentRenderbuffer:GL_RENDERBUFFER];
drawAnObject();
glFlush();
}
- (void)dealloc
{
[super dealloc];
}
@end
#endif