Salut,

Qu'est ce qu'il manque dans le code suivant pour avoir une fenêtre cocoa avec contexte OpenGL ? Ce code je l'ai trouvé sur internet :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#import <Cocoa/Cocoa.h>
#import  <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
 
@interface MyView : NSOpenGLView 
{
 
}
@end
@implementation MyView
- (id)initWithFrame:(NSRect)frame
{
	const NSOpenGLPixelFormatAttribute attrs[] = { 0 };
	return [super initWithFrame:frame pixelFormat:[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]];
}
- (void)drawRect:(NSRect)rect 
{
	// your OpenGL commands here
}
@end
 
MyView *createWindow(float x, float y, float width, float height) 
{
	NSWindow *w = [[NSWindow alloc] initWithContentRect:NSMakeRect(x,y,width,height)
											  styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
												backing:NSBackingStoreRetained
												  defer:NO];
	MyView *view = [[MyView alloc] initWithFrame:[w frame]];
	[w makeKeyAndOrderFront:nil];
	return view;
}
 
int main( int argc, char **argv)
{
	createWindow(30,40,300,400);
}
Si par chance, une personne ayant expérimenté avec cocoa et objective-c pourrait me dire comment faire pour ne pas avoir à utiliser obj-c à part pour initialiser la fenêtre. L'affichage opengl je voudrait le faire en pur C++ plus bas dans une boucle.

Un grand merci