Moved platform-independent OpenGL setup code into GameController instead of duplicating it. Enabled GL_SEPARATE_SPECULAR_COLOR, making specular highlights reasonably consistent between default shader and non-shader mode.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3172 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-04-17 11:06:34 +00:00
parent 731fae187f
commit f1e5e1d19a
5 changed files with 77 additions and 114 deletions

View File

@ -223,12 +223,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
- (void) initialiseGLWithSize:(NSSize) v_size
{
GLfloat sun_ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat sun_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat sun_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat sun_center_position[] = {0.0, 0.0, 0.0, 1.0};
GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};
viewSize = v_size;
if (viewSize.width/viewSize.height > 4.0/3.0) {
display_z = 480.0 * viewSize.width/viewSize.height;
@ -240,59 +234,10 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
y_offset = 320.0 * viewSize.height/viewSize.width;
}
float ratio = 0.5;
float aspect = viewSize.height/viewSize.width;
glShadeModel(GL_FLAT);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
[self openGLContext];
[[self gameController] setUpBasicOpenGLStateWithSize:viewSize];
[[self openGLContext] flushBuffer];
glClearDepth(MAX_CLEAR_DEPTH);
glViewport( 0, 0, viewSize.width, viewSize.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset matrix
glFrustum( -ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix
glMatrixMode( GL_MODELVIEW);
glEnable( GL_DEPTH_TEST); // depth buffer
glDepthFunc( GL_LESS); // depth buffer
glFrontFace( GL_CCW); // face culling - front faces are AntiClockwise!
glCullFace( GL_BACK); // face culling
glEnable( GL_CULL_FACE); // face culling
glEnable( GL_BLEND); // alpha blending
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha blending
if (UNIVERSE)
{
[UNIVERSE setLighting];
}
else
{
glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient);
glLightfv(GL_LIGHT1, GL_SPECULAR, sun_specular);
glLightfv(GL_LIGHT1, GL_DIFFUSE, sun_diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, sun_center_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient);
glEnable(GL_LIGHT1); // lighting
}
glEnable(GL_LIGHTING); // lighting
// world's simplest OpenGL optimisations...
#if GL_APPLE_transform_hint
glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST);
#endif
glDisable(GL_NORMALIZE);
glDisable(GL_RESCALE_NORMAL);
m_glContextInitialized = YES;
}

View File

@ -162,5 +162,6 @@ MA 02110-1301, USA.
- (void)windowDidResize:(NSNotification *)aNotification;
@end
- (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize;
@end

View File

@ -1046,6 +1046,72 @@ static NSComparisonResult CompareDisplayModes(id arg1, id arg2, void *context)
#endif
}
- (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize
{
float ratio = 0.5;
float aspect = viewSize.height/viewSize.width;
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_FLAT);
glClearDepth(MAX_CLEAR_DEPTH);
glViewport(0, 0, viewSize.width, viewSize.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset matrix
glFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST); // depth buffer
glDepthFunc(GL_LESS); // depth buffer
glFrontFace(GL_CCW); // face culling - front faces are AntiClockwise!
glCullFace(GL_BACK); // face culling
glEnable(GL_CULL_FACE); // face culling
glEnable(GL_BLEND); // alpha blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha blending
if (UNIVERSE)
{
[UNIVERSE setLighting];
}
else
{
GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};
glLightfv(GL_LIGHT1, GL_AMBIENT, black);
glLightfv(GL_LIGHT1, GL_SPECULAR, white);
glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
glLightfv(GL_LIGHT1, GL_POSITION, black);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient);
glEnable(GL_LIGHT1); // lighting
}
glEnable(GL_LIGHTING); // lighting
// world's simplest OpenGL optimisations...
#if GL_APPLE_transform_hint
glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST);
#endif
glDisable(GL_NORMALIZE);
glDisable(GL_RESCALE_NORMAL);
#if GL_VERSION_1_2
// For OpenGL 1.2 or later, we want GL_SEPARATE_SPECULAR_COLOR all the time.
if ([[OOOpenGLExtensionManager sharedManager] majorVersionNumber] > 1 || [[OOOpenGLExtensionManager sharedManager] minorVersionNumber] >= 2)
{
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
}
#endif
}
@end

View File

@ -8,6 +8,7 @@ This is thread safe, except for initialization; that is, +sharedManager should
be called from the main thread at an early point. The OpenGL context must be
set up by then.
Oolite
Copyright (C) 2004-2008 Giles C Williams and contributors

View File

@ -766,64 +766,14 @@ if (!showSplashScreen) return;
float ratio = 0.5;
float aspect = bounds.size.height/bounds.size.width;
if (surface != 0)
SDL_FreeSurface(surface);
if (surface != 0) SDL_FreeSurface(surface);
[self autoShowMouse];
glShadeModel(GL_FLAT);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
[[self gameController] setUpBasicOpenGLStateWithSize:viewSize];
SDL_GL_SwapBuffers();
glClearDepth(MAX_CLEAR_DEPTH);
glViewport( 0, 0, bounds.size.width, bounds.size.height);
squareX = 0.0f;
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset matrix
glFrustum( -ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH); // set projection matrix
glMatrixMode( GL_MODELVIEW);
glEnable( GL_DEPTH_TEST); // depth buffer
glDepthFunc( GL_LESS); // depth buffer
glFrontFace( GL_CCW); // face culling - front faces are AntiClockwise!
glCullFace( GL_BACK); // face culling
glEnable( GL_CULL_FACE); // face culling
glEnable( GL_BLEND); // alpha blending
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // alpha blending
if (UNIVERSE)
{
[UNIVERSE setLighting];
}
else
{
// At startup only...
GLfloat sun_ambient[] = {0.1, 0.1, 0.1, 1.0};
GLfloat sun_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat sun_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat sun_position[] = {0.0, 0.0, 0.0, 1.0};
GLfloat stars_ambient[] = {0.25, 0.2, 0.25, 1.0};
glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient);
glLightfv(GL_LIGHT1, GL_SPECULAR, sun_specular);
glLightfv(GL_LIGHT1, GL_DIFFUSE, sun_diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, sun_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, stars_ambient);
glEnable(GL_LIGHT1); // lighting
}
glEnable(GL_LIGHTING); // lighting
// world's simplest OpenGL optimisations...
//glHint(GL_TRANSFORM_HINT_APPLE, GL_FASTEST);
glDisable(GL_NORMALIZE);
glDisable(GL_RESCALE_NORMAL);
m_glContextInitialized = YES;
}