All pastes #908403 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-18 12:40 UTC
rendered paste body
@implementation GameView

- (id)initWithFrame:(NSRect)frame
{
	GLuint attribs[] = 
	{
		NSOpenGLPFANoRecovery,
		NSOpenGLPFAWindow,
		NSOpenGLPFAAccelerated,
		NSOpenGLPFADoubleBuffer,
		NSOpenGLPFAColorSize, 24,
		NSOpenGLPFAAlphaSize, 8,
		NSOpenGLPFADepthSize, 24,
		NSOpenGLPFAStencilSize, 8,
		NSOpenGLPFAAccumSize, 0,
		0
	};
	
	NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute*)attribs]; 
	
	if (!fmt)
	{
		NSLog(@"No OpenGL pixel format");
	}
	
	self = [super initWithFrame:frame pixelFormat:[fmt autorelease]];
	if(self)
	{
		//turn on vsync
		GLint newSwapInterval=1;
		CGLSetParameter([[self openGLContext] CGLContextObj],kCGLCPSwapInterval,&newSwapInterval);
		
		world = [[World alloc] init];
		Background *bg = [[Background alloc] init];
		[bg setTexture:[NSImage imageNamed:@"Nebula 1"] tileSize:500 borders:1];
		world.bg = bg;
		
	}
	
	return self;
}

// Some other stuff here for initialising Open GL etc.

- (void)drawRect:(NSRect)rect
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glClearColor(0.0,0.0,0.0,1.0);
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	
	[world render];
	
	[[self openGLContext] flushBuffer];
}

@end

---

@interface World : Renderable
{
	Background *bg;
}

@property (retain, readwrite) Background *bg;

@end

---

#import "Renderables.h"

@implementation World

@synthesize bg;

- (void)render
{
	[bg render];
}

@end

---