Use matrix manager for OpenGL matrices

This commit is contained in:
Kevin Anthoney 2014-07-05 20:30:14 +01:00
parent 36a0522e86
commit 91d583ae22
17 changed files with 337 additions and 147 deletions

View File

@ -30,6 +30,7 @@ MA 02110-1301, USA.
#import "Universe.h"
#import "OOMacroOpenGL.h"
#import "PlayerEntity.h"
#import "OOOpenGLMatrixManager.h"
#import "OOTexture.h"
#import "OOGraphicsResetManager.h"
@ -331,6 +332,7 @@ static GLfloat pA[6] = { 0.01, 0.0, 2.0, 4.0, 6.0, 10.0 }; // phase adjustments
- (void) drawSubEntityImmediate:(bool)immediate translucent:(bool)translucent
{
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (!translucent) return;
ShipEntity *ship = [self owner];
@ -339,8 +341,9 @@ static GLfloat pA[6] = { 0.01, 0.0, 2.0, 4.0, 6.0, 10.0 }; // phase adjustments
OO_ENTER_OPENGL();
OOSetOpenGLState(OPENGL_STATE_ADDITIVE_BLENDING);
OOGL(glPopMatrix()); // restore absolute positioning
OOGL(glPushMatrix()); // avoid stack underflow
[matrixManager popModelView];
[matrixManager pushModelView];
[matrixManager syncModelView];
// GLTranslateOOVector(vector_flip([self cameraRelativePosition]));
HPVector cam = [PLAYER viewpointPosition];
for (unsigned n=0;n<34*3;n++)

View File

@ -31,6 +31,8 @@ MA 02110-1301, USA.
#import "OOTexture.h"
#import "OOGraphicsResetManager.h"
#import "OOOpenGLMatrixManager.h"
#define kLaserDuration (0.09) // seconds
@ -190,7 +192,8 @@ static const GLfloat kLaserVertices[] =
- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
{
if (!translucent || [UNIVERSE breakPatternHide]) return;
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OO_ENTER_OPENGL();
OOSetOpenGLState(OPENGL_STATE_ADDITIVE_BLENDING);
@ -201,7 +204,7 @@ static const GLfloat kLaserVertices[] =
*/
OOGL(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
OOGL(glEnable(GL_TEXTURE_2D));
OOGL(glPushMatrix());
[matrixManager pushModelView];
[[self texture1] apply];
GLfloat s = sin([UNIVERSE getTime]);
@ -239,7 +242,8 @@ static const GLfloat kLaserVertices[] =
glTexCoordPointer(2, GL_FLOAT, 0, laserTexCoords);
glDrawArrays(GL_QUADS, 0, 8);
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
OOGL(glDisableClientState(GL_TEXTURE_COORD_ARRAY));
OOGL(glDisable(GL_TEXTURE_2D));

View File

@ -32,6 +32,7 @@ MA 02110-1301, USA.
#import "OOFunctionAttributes.h"
#import "OOMacroOpenGL.h"
#import "OOGraphicsResetManager.h"
#import "OOOpenGLMatrixManager.h"
#define PARTICLE_DISTANCE_SCALE_LOW 12.0
@ -112,6 +113,7 @@ static OOTexture *sBlobTexture = nil;
Entity *father = [self owner];
Entity *last = nil;
HPVector abspos = position;
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
while (father != nil && father != last && father != NO_TARGET)
{
@ -123,13 +125,15 @@ static OOTexture *sBlobTexture = nil;
father = [father owner];
}
OOMatrix temp_matrix = OOMatrixLoadGLMatrix(GL_MODELVIEW_MATRIX);
OOGL(glPopMatrix()); OOGL(glPushMatrix()); // restore zero!
OOMatrix temp_matrix = [matrixManager getModelView];
[matrixManager popModelView];
[matrixManager pushModelView];
GLTranslateOOVector(HPVectorToVector(HPvector_subtract(abspos,[PLAYER viewpointPosition]))); // move to camera-relative position
[matrixManager translateModelView:HPVectorToVector(HPvector_subtract(abspos,[PLAYER viewpointPosition]))]; // move to camera-relative position
GLLoadOOMatrix([matrixManager getModelView]);
[self drawImmediate:immediate translucent:translucent];
GLLoadOOMatrix(temp_matrix);
[matrixManager loadModelView: temp_matrix];
}

View File

@ -29,6 +29,7 @@ MA 02110-1301, USA.
#import "PlayerEntity.h"
#import "OOLightParticleEntity.h"
#import "OOMacroOpenGL.h"
#import "OOOpenGLMatrixManager.h"
// Testing toy: cause particle systems to stop after half a second.
@ -160,11 +161,14 @@ do { \
GLfloat (*particleColor)[4] = _particleColor;
GLfloat *particleSize = _particleSize;
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if ([UNIVERSE reducedDetail])
{
// Quick rendering - particle cloud is effectively a 2D billboard.
OOGL(glPushMatrix());
GLMultOOMatrix(OOMatrixForBillboard(selfPosition, viewPosition));
[matrixManager pushModelView];
[matrixManager multModelView: OOMatrixForBillboard(selfPosition, viewPosition)];
[matrixManager syncModelView];
OOGLBEGIN(GL_QUADS);
for (i = 0; i < count; i++)
@ -174,7 +178,8 @@ do { \
}
OOGLEND();
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
else
{
@ -192,16 +197,18 @@ do { \
for (i = 0; i < count; i++)
{
OOGL(glPushMatrix());
GLTranslateOOVector(particlePosition[i]);
GLMultOOMatrix(bbMatrix);
[matrixManager pushModelView];
[matrixManager translateModelView: particlePosition[i]];
[matrixManager multModelView: bbMatrix];
[matrixManager syncModelView];
glColor4fv(particleColor[i]);
OOGLBEGIN(GL_QUADS);
DrawQuadForView(0, 0, 0, particleSize[i]);
OOGLEND();
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
}
else
@ -215,16 +222,17 @@ do { \
for (i = 0; i < count; i++)
{
OOGL(glPushMatrix());
GLTranslateOOVector(particlePosition[i]);
GLMultOOMatrix(OOMatrixForBillboard(HPvector_add(selfPosition, vectorToHPVector(vector_multiply_scalar(particlePosition[i], individuality))), viewPosition));
[matrixManager pushModelView];
[matrixManager translateModelView: particlePosition[i]];
[matrixManager multModelView: OOMatrixForBillboard(HPvector_add(selfPosition, vectorToHPVector(vector_multiply_scalar(particlePosition[i], individuality))), viewPosition)];
glColor4fv(particleColor[i]);
OOGLBEGIN(GL_QUADS);
DrawQuadForView(0, 0, 0, particleSize[i]);
OOGLEND();
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
}

View File

@ -51,6 +51,8 @@ MA 02110-1301, USA.
#import "OOFilteringEnumerator.h"
#import "OOOpenGLMatrixManager.h"
@interface OOVisualEffectEntity (Private)
- (void) drawSubEntityImmediate:(bool)immediate translucent:(bool)translucent;
@ -389,17 +391,20 @@ MA 02110-1301, USA.
- (void) drawSubEntityImmediate:(bool)immediate translucent:(bool)translucent
{
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (cam_zero_distance > no_draw_distance) // this test provides an opportunity to do simple LoD culling
{
return; // TOO FAR AWAY
}
OOGL(glPushMatrix());
[matrixManager pushModelView];
// HPVect: camera position
GLTranslateOOVector(HPVectorToVector(position));
GLMultOOMatrix(rotMatrix);
[matrixManager translateModelView: HPVectorToVector(position)];
[matrixManager multModelView: rotMatrix];
[matrixManager syncModelView];
[self drawImmediate:immediate translucent:translucent];
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
@ -640,18 +645,21 @@ static GLfloat scripted_color[4] = { 0.0, 0.0, 0.0, 0.0};
- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
{
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (no_draw_distance < cam_zero_distance)
{
return; // too far away to draw
}
OOGL(glPushMatrix());
OOGL(glScalef(scaleX,scaleY,scaleZ));
[matrixManager pushModelView];
[matrixManager scaleModelView: make_vector(scaleX,scaleY,scaleZ)];
[matrixManager syncModelView];
if ([self mesh] != nil)
{
[super drawImmediate:immediate translucent:translucent];
}
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
// Draw subentities.
if (!immediate) // TODO: is this relevant any longer?

View File

@ -43,6 +43,7 @@ MA 02110-1301, USA.
#import "OOCollectionExtractors.h"
#import "OODebugFlags.h"
#import "OOGraphicsResetManager.h"
#import "OOOpenGLMatrixManager.h"
#if !OOLITE_MAC_OS_X
@ -786,6 +787,7 @@ static const BaseFace kTexturedFaces[][3] =
double drawFactor = [[UNIVERSE gameView] viewSize].width / 100.0;
double drawRatio2 = drawFactor * collision_radius / sqrt_zero_distance; // equivalent to size on screen in pixels
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (cam_zero_distance > 0.0)
{
@ -835,7 +837,8 @@ static const BaseFace kTexturedFaces[][3] =
{
subdivideLevel = root_planet->lastSubdivideLevel; // copy it from the planet (stops jerky LOD and such)
}
GLMultOOMatrix(rotMatrix); // rotate the clouds!
[matrixManager multModelVew: rotMatrix]; // rotate the clouds!
[matrixManager syncModelView];
OOGL(glEnable(GL_BLEND));
// OOGL(glDisable(GL_LIGHTING));
// Fall through.
@ -977,8 +980,11 @@ static const BaseFace kTexturedFaces[][3] =
if (atmosphere)
{
OOGL(glPopMatrix()); // get old draw matrix back
OOGL(glPushMatrix()); // and store it again
[matrixManager popModelView];
[matrixManager pushModelView];
[matrixManager syncModelView];
//OOGL(glPopMatrix()); // get old draw matrix back
//OOGL(glPushMatrix()); // and store it again
OOGL(glTranslatef(cameraRelativePosition.x,cameraRelativePosition.y,cameraRelativePosition.z)); // centre on the planet
// rotate
// GLMultOOMatrix([atmosphere rotationMatrix]);

View File

@ -91,6 +91,8 @@ MA 02110-1301, USA.
#import "OOJSVector.h"
#import "OOJSEngineTimeManagement.h"
#import "OOOpenGLMatrixManager.h"
#define USEMASC 1
@ -5872,8 +5874,9 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
{
return; // TOO FAR AWAY
}
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OOGL(glPushMatrix());
[matrixManager pushModelView];
if ([self status] == STATUS_ACTIVE)
{
@ -5892,17 +5895,18 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
} */
HPVector abspos = [self absolutePositionForSubentity];
GLLoadOOMatrix([UNIVERSE viewMatrix]);
[matrixManager loadModelView: [UNIVERSE viewMatrix]];
// HPVect: need to make camera-relative
GLTranslateOOVector(HPVectorToVector(abspos));
[matrixManager translateModelView:HPVectorToVector(abspos)];
}
else
{
// HPVect: need to make camera-relative
GLTranslateOOVector(HPVectorToVector(position));
[matrixManager translateModelView: HPVectorToVector(position)];
}
GLMultOOMatrix(rotMatrix);
[matrixManager multModelView: rotMatrix];
[matrixManager syncModelView];
[self drawImmediate:immediate translucent:translucent];
#ifndef NDEBUG
@ -5912,7 +5916,8 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
#endif
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
OOVerifyOpenGLState();
}

View File

@ -42,6 +42,7 @@ MA 02110-1301, USA.
#import "OODebugSupport.h"
#import "legacy_random.h"
#import "OOOXZManager.h"
#import "OOOpenGLMatrixManager.h"
#if OOLITE_MAC_OS_X
#import "JAPersistentFileReference.h"
@ -901,6 +902,7 @@ static NSMutableArray *sMessageStack;
- (void)setUpBasicOpenGLStateWithSize:(NSSize)viewSize
{
OOOpenGLExtensionManager *extMgr = [OOOpenGLExtensionManager sharedManager];
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
float ratio = 0.5;
float aspect = viewSize.height/viewSize.width;
@ -911,12 +913,18 @@ static NSMutableArray *sMessageStack;
OOGL(glClearDepth(MAX_CLEAR_DEPTH));
OOGL(glViewport(0, 0, viewSize.width, viewSize.height));
OOGL(glMatrixMode(GL_PROJECTION));
OOGL(glLoadIdentity()); // reset matrix
OOGL(glFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, 1.0, MAX_CLEAR_DEPTH)); // set projection matrix
OOGL(glMatrixMode(GL_MODELVIEW));
[matrixManager resetProjection];
[matrixManager syncProjection];
OOGL(glLoadIdentity());
OOGL(glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -1.0f, 1.0f));
[matrixManager orthoLeft: 0.0 right: 640 bottom: 480.0f top: 0.0 near: -1.0 far: 1.0];
OOLog(@"kja", @"Projection matrix: %@", OOMatrixDescription([matrixManager getProjection]));
OOLog(@"kja", @"OpenGL Projection matrix: %@", OOMatrixDescription(OOMatrixLoadGLMatrix(GL_PROJECTION_MATRIX)));
[matrixManager resetProjection]; // reset matrix
[matrixManager frustumLeft:-ratio right:ratio bottom: -aspect*ratio top: aspect*ratio near: 1.0 far: MAX_CLEAR_DEPTH]; // set projection matrix
[matrixManager syncProjection];
OOGL(glDepthFunc(GL_LESS)); // depth buffer
if (UNIVERSE)

View File

@ -45,6 +45,7 @@ MA 02110-1301, USA.
#import "OOStringParsing.h"
#import "OOJoystickManager.h"
#import "OOJavaScriptEngine.h"
#import "OOOpenGLMatrixManager.h"
#define ONE_SIXTEENTH 0.0625
@ -1777,9 +1778,11 @@ OOINLINE void SetCompassBlipColor(GLfloat relativeZ, GLfloat alpha)
}
OOGLEND();
#else
OOGL(glPushMatrix());
OOGL(glTranslatef(x, y, z1));
OOGL(glScalef(w, -h, 1.0f));
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(x, y, z1)];
[matrixManager scaleModelView: make_vector(w, -h, 1.0f)];
[matrixManager syncModelView];
OOGL(glColor4f(0.0f, 1.0f, 0.0f, alpha));
OOGL(glVertexPointer(2, GL_FLOAT, 0, strip));
@ -1788,8 +1791,9 @@ OOINLINE void SetCompassBlipColor(GLfloat relativeZ, GLfloat alpha)
OOGL(glDrawArrays(GL_QUAD_STRIP, 0, sizeof strip / sizeof *strip / 2));
OOGL(glDisableClientState(GL_VERTEX_ARRAY));
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
#endif
}
@ -2334,24 +2338,27 @@ static OOPolygonSprite *IconForMissileRole(NSString *role)
width:(GLfloat)width height:(GLfloat)height alpha:(GLfloat)alpha
{
OOPolygonSprite *sprite = IconForMissileRole([missile primaryRole]);
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (selected)
{
// Draw yellow outline.
OOGL(glPushMatrix());
OOGL(glTranslatef(x - width * 2.0f, y - height * 2.0f, z1));
OOGL(glScalef(width, height, 1.0f));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(x - width * 2.0f, y - height * 2.0f, z1)];
[matrixManager scaleModelView: make_vector(width, height, 1.0f)];
[matrixManager syncModelView];
GLColorWithOverallAlpha(yellow_color, alpha);
[sprite drawOutline];
OOGL(glPopMatrix());
[matrixManager popModelView];
// Draw black backing, so outline colour isnt blended into missile colour.
OOGL(glPushMatrix());
OOGL(glTranslatef(x - width * 2.0f, y - height * 2.0f, z1));
OOGL(glScalef(width, height, 1.0f));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(x - width * 2.0f, y - height * 2.0f, z1)];
[matrixManager scaleModelView: make_vector(width, height, 1.0f)];
[matrixManager syncModelView];
GLColorWithOverallAlpha(black_color, alpha);
[sprite drawFilled];
OOGL(glPopMatrix());
[matrixManager popModelView];
switch (status)
{
@ -2369,11 +2376,13 @@ static OOPolygonSprite *IconForMissileRole(NSString *role)
else GLColorWithOverallAlpha(red_color, alpha);
}
OOGL(glPushMatrix());
OOGL(glTranslatef(x - width * 2.0f, y - height * 2.0f, z1));
OOGL(glScalef(width, height, 1.0f));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(x - width * 2.0f, y - height * 2.0f, z1)];
[matrixManager scaleModelView: make_vector(width, height, 1.0f)];
[matrixManager syncModelView];
[sprite drawFilled];
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
@ -2382,14 +2391,17 @@ static OOPolygonSprite *IconForMissileRole(NSString *role)
width:(GLfloat)width height:(GLfloat)height alpha:(GLfloat)alpha
{
OOPolygonSprite *sprite = IconForMissileRole(kDefaultMissileIconKey);
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
// Draw gray outline.
OOGL(glPushMatrix());
OOGL(glTranslatef(x - width * 2.0f, y - height * 2.0f, z1));
OOGL(glScalef(width, height, 1.0f));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(x - width * 2.0f, y - height * 2.0f, z1)];
[matrixManager scaleModelView: make_vector(width, height, 1.0f)];
[matrixManager syncModelView];
GLColorWithOverallAlpha(lightgray_color, alpha);
[sprite drawOutline];
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
@ -3247,6 +3259,8 @@ static void hudDrawReticleOnTarget(Entity *target, PlayerEntity *player1, GLfloa
NSString *legal_desc = nil;
GLfloat scale = [info oo_floatForKey:@"reticle_scale" defaultValue:ONE_SIXTYFOURTH];
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (target == nil || player1 == nil) return;
@ -3456,7 +3470,8 @@ static void hudDrawReticleOnTarget(Entity *target, PlayerEntity *player1, GLfloa
}
}
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
@ -3466,6 +3481,8 @@ static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, G
{
return;
}
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
Vector p1 = HPVectorToVector(HPvector_subtract([waypoint position], [player1 viewpointPosition]));
@ -3516,7 +3533,8 @@ static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, G
OODrawString(infoline, rs0 * 0.5, -rs2 - line_height, 0, textsize);
}
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
static void hudRotateViewpointForVirtualDepth(PlayerEntity * player1, Vector p1)
@ -3525,8 +3543,9 @@ static void hudRotateViewpointForVirtualDepth(PlayerEntity * player1, Vector p1)
Quaternion back_q = [player1 orientation];
back_q.w = -back_q.w; // invert
Vector v1 = vector_up_from_quaternion(back_q);
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OOGL(glPushMatrix());
[matrixManager pushModelView];
// deal with view directions
Vector view_dir, view_up = kBasisYVector;
@ -3558,17 +3577,18 @@ static void hudRotateViewpointForVirtualDepth(PlayerEntity * player1, Vector p1)
back_q = quaternion_multiply([player1 customViewQuaternion], back_q);
break;
}
OOGL(gluLookAt(view_dir.x, view_dir.y, view_dir.z, 0.0, 0.0, 0.0, view_up.x, view_up.y, view_up.z));
[matrixManager lookAtWithEye: view_dir center: kZeroVector up: view_up];
back_mat = OOMatrixForQuaternionRotation(back_q);
// rotate the view
GLMultOOMatrix([player1 rotationMatrix]);
[matrixManager multModelView: [player1 rotationMatrix]];
// translate the view
OOGL(glTranslatef(p1.x, p1.y, p1.z));
[matrixManager translateModelView: p1];
//rotate to face player1
GLMultOOMatrix(back_mat);
[matrixManager multModelView: back_mat];
// draw the waypoint
[matrixManager syncModelView];
}
@ -4103,14 +4123,17 @@ static void DrawSpecialOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat
GLfloat oy = y - size.height * 0.5;
GLfloat width = size.width * (1.0f / 6.0f);
GLfloat height = size.height * (1.0f / 6.0f);
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OOGL(glPushMatrix());
OOGL(glTranslatef(ox, oy, z));
OOGL(glScalef(width, height, 1.0f));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(ox, oy, z)];
[matrixManager scaleModelView: make_vector(width, height, 1.0f)];
[matrixManager syncModelView];
[self drawFilled];
glColor4f(0.0, 0.0, 0.0, 0.5 * alpha);
[self drawOutline];
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
}
@end

View File

@ -32,6 +32,7 @@ SOFTWARE.
#import "Universe.h"
#import "MyOpenGLView.h"
#import "OOMacroOpenGL.h"
#import "OOOpenGLMatrixManager.h"
@interface OOCrosshairs (Private)
@ -83,12 +84,14 @@ SOFTWARE.
{
OO_ENTER_OPENGL();
OOSetOpenGLState(OPENGL_STATE_OVERLAY);
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OOGL(glPushAttrib(GL_ENABLE_BIT));
OOGL(glDisable(GL_LIGHTING));
OOGL(glDisable(GL_TEXTURE_2D));
OOGL(glPushMatrix());
OOGL(glTranslatef(0, 0, [[UNIVERSE gameView] display_z]));
[matrixManager pushModelView];
[matrixManager translateModelView: make_vector(0.0, 0.0, [[UNIVERSE gameView] display_z])];
[matrixManager syncModelView];
OOGL(glVertexPointer(2, GL_FLOAT, sizeof (GLfloat) * 6, _data));
OOGL(glColorPointer(4, GL_FLOAT, sizeof (GLfloat) * 6, _data + 2));
@ -101,7 +104,8 @@ SOFTWARE.
OOGL(glDisableClientState(GL_VERTEX_ARRAY));
OOGL(glDisableClientState(GL_COLOR_ARRAY));
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
OOGL(glPopAttrib());
OOVerifyOpenGLState();

View File

@ -39,6 +39,7 @@ SOFTWARE.
#import "OOPlanetEntity.h"
#import "OODrawable.h"
#import "OOEntityFilterPredicate.h"
#import "OOOpenGLMatrixManager"
#if OO_USE_FBO && OO_TEXTURE_CUBE_MAP
@ -81,19 +82,19 @@ SOFTWARE.
- (void) render
{
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
if (_textureName == 0) [self setUp];
OO_ENTER_OPENGL();
// Save stuff.
OOGL(glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT));
OOGL(glMatrixMode(GL_MODELVIEW));
OOGL(glPushMatrix());
OOGL(glMatrixMode(GL_PROJECTION));
OOGL(glPushMatrix());
[matrixManager pushModelView];
[matrixManager pushProjection];
OOGL(glViewport(0, 0, _size, _size));
[matrixManager scaleProjection: make_vector(-1.0, 1.0, 1.0)];
OOGL(glScalef(-1.0, 1.0, 1.0)); // flip left and right
/* TODO: once confirmed working (and rendering everything in the right
@ -106,8 +107,12 @@ SOFTWARE.
...and appropriate rotations thereof.
*/
[matrixManager resetProjection];
OOGL(glLoadIdentity());
OOGL(gluPerspective(90.0, 1.0, 1.0, MAX_CLEAR_DEPTH));
[matrixManager perspectiveFovy: 90.0 aspect: 1.0 zNear: 1.0 zFar: MAX_CLEAR_DEPTH];
OOLog(@"kja", @"Projection matrix: %@", OOMatrixDescription([matrixManager getProjection]));
OOLog(@"kja", @"OpenGL Projection matrix: %@", OOMatrixDescription(OOMatrixLoadGLMatrix(GL_PROJECTION_MATRIX)));
OODrawable *sky = [[UNIVERSE nearestEntityMatchingPredicate:HasClassPredicate parameter:[SkyEntity class] relativeToEntity:nil] drawable];
OOSunEntity *sun = [UNIVERSE sun];
@ -119,26 +124,23 @@ SOFTWARE.
for (i = 0; i < 6; i++)
{
OOGL(glPushMatrix());
[matrixManager pushProjection];
Vector center = centers[i];
Vector up = ups[i];
OOGL(gluLookAt(0, 0, 0, center.x, center.y, center.z, up.x, up.y, up.z));
OOGL(glMatrixMode(GL_MODELVIEW));
OOGL(glPushMatrix());
[matrixManager lookAtWithEye: kZeroVector, center: center up: up];
[matrixManager syncProjection];
OOGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _fbos[i]));
[self renderOnePassWithSky:sky sun:sun planets:planets];
OOGL(glPopMatrix());
OOGL(glMatrixMode(GL_PROJECTION));
OOGL(glPopMatrix());
[matrixManager popProjection];
[matrixManager syncProjection];
}
OOGL(glMatrixMode(GL_PROJECTION));
OOGL(glPopMatrix());
OOGL(glMatrixMode(GL_MODELVIEW));
OOGL(glPopMatrix());
[matrixManager popProjection];
[matrixManager syncProjection];
[matrixManager popModelView];
[matrixManager syncModelView];
OOGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
OOGL(glPopAttrib());
}
@ -146,6 +148,7 @@ SOFTWARE.
- (void) renderOnePassWithSky:(OODrawable *)sky sun:(OOSunEntity *)sun planets:(NSArray *)planets
{
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OO_ENTER_OPENGL();
OOGL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
@ -156,27 +159,32 @@ SOFTWARE.
[sky renderOpaqueParts];
OOGL(glDepthMask(GL_TRUE));
OOGL(glLoadIdentity());
GLTranslateOOVector(vector_flip([PLAYER position]));
[matrixManager pushModelView];
[matrixManager resetModelView];
[matrixManager translateModelView: vector_flip([PLAYER position])];
NSEnumerator *planetEnum = nil;
OOPlanetEntity *planet = nil;
for (planetEnum = [planets objectEnumerator]; (planet = [planetEnum nextObject]); )
{
OOGL(glPushMatrix());
GLTranslateOOVector([planet position]);
[matrixManager pushModelView];
[matrixManager translateModelView: [planet position]];
[matrixManager syncModelView];
#if NEW_PLANETS
[[planet drawable] renderOpaqueParts];
#else
[planet drawUnconditionally];
#endif
OOGL(glPopMatrix());
[matrixManager popModelView];
}
OOGL(glPushMatrix());
GLTranslateOOVector([sun position]);
[matrixManager pushModelView];
[matrixManager translateModelView: [sun position]];
[matrixManager syncModelView];
[sun drawUnconditionally];
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager popModelView];
[matrixManager syncModelView];
}
- (void) setUp

View File

@ -34,6 +34,15 @@ enum
OOLITE_GL_MATRIX_PROJECTION,
OOLITE_GL_MATRIX_MODELVIEW_PROJECTION,
OOLITE_GL_MATRIX_NORMAL,
OOLITE_GL_MATRIX_MODELVIEW_INVERSE,
OOLITE_GL_MATRIX_PROJECTION_INVERSE,
OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE,
OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE,
OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE,
OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE,
OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE,
OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE,
OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE,
OOLITE_GL_MATRIX_END
};
@ -72,16 +81,20 @@ enum
- (void) pushModelView;
- (OOMatrix) popModelView;
- (OOMatrix) getModelView;
- (void) syncModelView;
- (void) loadProjection: (OOMatrix) matrix;
- (void) multProjection: (OOMatrix) matrix;
- (void) translateProjection: (Vector) vector;
- (void) rotateProjection: (GLfloat) angle axis: (Vector) axis;
- (void) scaleProjection: (Vector) scale;
- (void) frustumLeft: (double) l right: (double) r top: (double) t bottom: (double) b near: (double) n far: (double) f;
- (void) frustumLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f;
- (void) orthoLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f;
- (void) perspectiveFovy: (double) fovy aspect: (double) aspect zNear: (double) zNear zFar: (double) zFar;
- (void) resetProjection;
- (void) pushProjection;
- (OOMatrix) popProjection;
- (OOMatrix) getProjection;
- (void) syncProjection;
- (OOMatrix) getMatrix: (int) which;
@end

View File

@ -85,11 +85,26 @@ static OOOpenGLMatrixManager * sharedMatrixManager = nil;
{
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION] = NO;
valid[OOLITE_GL_MATRIX_NORMAL] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_INVERSE] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE] = NO;
}
- (void) updateProjection
{
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE] = NO;
valid[OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE] = NO;
}
@end
@ -218,6 +233,13 @@ static OOOpenGLMatrixManager * sharedMatrixManager = nil;
return matrices[OOLITE_GL_MATRIX_MODELVIEW];
}
- (void) syncModelView
{
OOGL(glMatrixMode(GL_MODELVIEW));
GLLoadOOMatrix([self getModelView]);
return;
}
- (void) loadProjection: (OOMatrix) matrix
{
matrices[OOLITE_GL_MATRIX_PROJECTION] = matrix;
@ -250,18 +272,43 @@ static OOOpenGLMatrixManager * sharedMatrixManager = nil;
[self multProjection: OOMatrixForScale(scale.x, scale.y, scale.z)];
}
- (void) frustumLeft: (double) l right: (double) r top: (double) t bottom: (double) b near: (double) n far: (double) f
- (void) frustumLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f
{
if (l == r || t == b || n == f || n <= 0 || f <= 0 ) return;
if (l == r || t == b || n == f || n <= 0 || f <= 0) return;
[self multProjection: OOMatrixConstruct
(
2*n/(l+f), 0.0, 0.0, 0.0,
0.0, 2*n/(t+b), 0.0, 0.0,
2*n/(r-l), 0.0, 0.0, 0.0,
0.0, 2*n/(t-b), 0.0, 0.0,
(r+l)/(r-l), (t+b)/(t-b), -(f+n)/(f-n), -1.0,
0.0, 0.0, -2*f*n/(f-n), 0.0
)];
}
- (void) orthoLeft: (double) l right: (double) r bottom: (double) b top: (double) t near: (double) n far: (double) f
{
if (l == r || t == b || n == f) return;
[self multProjection: OOMatrixConstruct
(
2/(r-l), 0.0, 0.0, 0.0,
0.0, 2/(t-b), 0.0, 0.0,
0.0, 0.0, 2/(n-f), 0.0,
(l+r)/(l-r), (b+t)/(b-t), (n+f)/(n-f), 1.0
)];
}
- (void) perspectiveFovy: (double) fovy aspect: (double) aspect zNear: (double) zNear zFar: (double) zFar
{
if (aspect == 0.0 || zNear == zFar) return;
double f = 1.0/tan(M_PI * fovy / 360);
[self multProjection: OOMatrixConstruct
(
f/aspect, 0.0, 0.0, 0.0,
0.0, f, 0.0, 0.0,
0.0, 0.0, (zFar + zNear)/(zNear - zFar), -1.0,
0.0, 0.0, 2*zFar*zNear/(zNear - zFar), 0.0
)];
}
- (void) resetProjection
{
matrices[OOLITE_GL_MATRIX_PROJECTION] = kIdentityMatrix;
@ -285,6 +332,13 @@ static OOOpenGLMatrixManager * sharedMatrixManager = nil;
return matrices[OOLITE_GL_MATRIX_PROJECTION];
}
- (void) syncProjection
{
OOGL(glMatrixMode(GL_PROJECTION));
GLLoadOOMatrix([self getProjection]);
return;
}
- (OOMatrix) getMatrix: (int) which
{
if (which < 0 || which >= OOLITE_GL_MATRIX_END) return kIdentityMatrix;
@ -305,6 +359,33 @@ static OOOpenGLMatrixManager * sharedMatrixManager = nil;
matrices[which].m[3][3] = 1.0;
matrices[which] = OOMatrixTranspose(OOMatrixInverse(matrices[which]));
break;
case OOLITE_GL_MATRIX_MODELVIEW_INVERSE:
matrices[which] = OOMatrixInverse(matrices[OOLITE_GL_MATRIX_MODELVIEW]);
break;
case OOLITE_GL_MATRIX_PROJECTION_INVERSE:
matrices[which] = OOMatrixInverse(matrices[OOLITE_GL_MATRIX_PROJECTION]);
break;
case OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE:
matrices[which] = OOMatrixInverse([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_PROJECTION]);
break;
case OOLITE_GL_MATRIX_MODELVIEW_TRANSPOSE:
matrices[which] = OOMatrixTranspose(matrices[OOLITE_GL_MATRIX_MODELVIEW]);
break;
case OOLITE_GL_MATRIX_PROJECTION_TRANSPOSE:
matrices[which] = OOMatrixTranspose(matrices[OOLITE_GL_MATRIX_PROJECTION]);
break;
case OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_TRANSPOSE:
matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_PROJECTION]);
break;
case OOLITE_GL_MATRIX_MODELVIEW_INVERSE_TRANSPOSE:
matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_INVERSE]);
break;
case OOLITE_GL_MATRIX_PROJECTION_INVERSE_TRANSPOSE:
matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_PROJECTION_INVERSE]);
break;
case OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE_TRANSPOSE:
matrices[which] = OOMatrixTranspose([self getMatrix: OOLITE_GL_MATRIX_MODELVIEW_PROJECTION_INVERSE]);
break;
}
valid[which] = YES;
return matrices[which];

View File

@ -33,6 +33,7 @@
#import "OOMacroOpenGL.h"
#import "Universe.h"
#import "MyOpenGLView.h"
#import "OOOpenGLMatrixManager.h"
#ifndef NDEBUG
#import "Entity.h"
@ -195,6 +196,7 @@
assert(_lod < kOOPlanetDataLevels);
const OOPlanetDataLevel *data = &kPlanetData[_lod];
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OO_ENTER_OPENGL();
@ -217,8 +219,9 @@
[_material apply];
// Scale the ball.
OOGL(glPushMatrix());
GLMultOOMatrix(_transform);
[matrixManager pushModelView];
[matrixManager multModelView: _transform];
[matrixManager syncModelView];
OOGL(glEnable(GL_LIGHTING));
OOGL(glEnable(GL_TEXTURE_2D));
@ -267,7 +270,8 @@
#endif
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
#ifndef NDEBUG
if (gDebugFlags & DEBUG_DRAW_NORMALS) [self debugDrawNormals];
#endif

View File

@ -30,6 +30,7 @@ MA 02110-1301, USA.
#import "OOSound.h"
#import "OOStringParsing.h"
#import "OOMaths.h"
#import "OOOpenGLMatrixManager.h"
static void InitTrumbleSounds(void);
@ -383,11 +384,13 @@ static void PlayTrumbleSqueal(void);
OOGL(glShadeModel(GL_SMOOTH));
OOGL(glEnable(GL_TEXTURE_2D));
[texture apply];
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
OOGL(glPushMatrix());
[matrixManager pushModelView];
OOGL(glTranslatef( position.x, position.y, z));
OOGL(glRotatef( rotation, 0.0, 0.0, 1.0));
[matrixManager translateModelView: make_vector(position.x, position.y, z)];
[matrixManager multModelView: OOMatrixForRotationZ(rotation)];
[matrixManager syncModelView];
//
// Body..
@ -433,7 +436,8 @@ static void PlayTrumbleSqueal(void);
eyeTextureOffset = 0.5; break;
}
OOGL(glTranslatef( eye_position.x * wd, eye_position.y * ht, 0.0));
[matrixManager translateModelView: make_vector(eye_position.x * wd, eye_position.y * ht, 0.0)];
[matrixManager syncModelView];
OOGL(glColor4fv(colorEyes));
OOGLBEGIN(GL_QUADS);
@ -467,7 +471,7 @@ static void PlayTrumbleSqueal(void);
mouthTextureOffset = 0.875; break;
}
OOGL(glTranslatef( mouth_position.x * wd, mouth_position.y * ht, 0.0));
[matrixManager translateModelView: make_vector(mouth_position.x * wd, mouth_position.y * ht, 0.0)];
OOGL(glColor4fv(colorBase));
OOGLBEGIN(GL_QUADS);
@ -485,7 +489,8 @@ static void PlayTrumbleSqueal(void);
OOGLEND();
// finally..
OOGL(glPopMatrix());
[matrixManager popModelView];
[matrixManager syncModelView];
OOGL(glDisable(GL_TEXTURE_2D));
}

View File

@ -4107,16 +4107,13 @@ static const OOMatrix starboard_matrix =
}
OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
OOGL(glLoadIdentity()); // reset matrix
OOGL(gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0));
[matrixManager resetModelView];
[matrixManager lookAtWithEye: make_vector(1.0,0.0,1.0) center: make_vector(0.0,0.0,1.0) up: make_vector(0.0,1.0,0.0)];
OOLog(@"kja", @"Projection matrix: %@", OOMatrixDescription([matrixManager getModelView]));
[matrixManager lookAtWithEye: make_vector(0.0,0.0,0.0) center: make_vector(0.0,0.0,1.0) up: make_vector(0.0,1.0,0.0)];
// HACK BUSTED
OOGL(glScalef(-1.0, 1.0, 1.0)); // flip left and right
OOGL(glPushMatrix()); // save this flat viewpoint
[matrixManager multModelView: OOMatrixForScale(-1.0,1.0,1.0)]; // flip left and right
[matrixManager pushModelView]; // save this flat viewpoint
/* OpenGL viewpoints:
*
@ -4148,14 +4145,16 @@ static const OOMatrix starboard_matrix =
view_matrix = OOMatrixMultiply(view_matrix, flipMatrix);
Vector viewOffset = [player viewpointOffset];
OOGL(gluLookAt(view_dir.x, view_dir.y, view_dir.z, 0.0, 0.0, 0.0, view_up.x, view_up.y, view_up.z));
[matrixManager lookAtWithEye: view_dir center: make_vector(0.0, 0.0, 0.0) up: view_up];
[matrixManager syncModelView];
if (EXPECT(!displayGUI || demoShipMode))
{
if (EXPECT(!demoShipMode)) // we're in flight
{
// rotate the view
OOGL(GLMultOOMatrix([player rotationMatrix]));
[matrixManager multModelView: [player rotationMatrix]];
[matrixManager syncModelView];
// translate the view
// HPVect: camera-relative position
// OOGL(GLTranslateOOVector(vector_flip(position)));
@ -4180,7 +4179,7 @@ static const OOMatrix starboard_matrix =
OOGL([self useGUILightSource:demoShipMode]);
// HACK: store view matrix for absolute drawing of active subentities (i.e., turrets).
OOGL(viewMatrix = OOMatrixLoadGLMatrix(GL_MODELVIEW_MATRIX));
viewMatrix = [matrixManager getModelView];
int furthest = draw_count - 1;
int nearest = 0;
@ -4215,22 +4214,27 @@ static const OOMatrix starboard_matrix =
OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, flat_ambdiff));
OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_no));
OOGL(glPushMatrix());
[matrixManager pushModelView];
if (EXPECT(drawthing != player))
{
//translate the object
// HPVect: camera relative
GLTranslateOOVector([drawthing cameraRelativePosition]);
//GLTranslateOOVector([drawthing cameraRelativePosition]);
[matrixManager translateModelView: [drawthing cameraRelativePosition]];
//rotate the object
GLMultOOMatrix([drawthing drawRotationMatrix]);
//GLMultOOMatrix([drawthing drawRotationMatrix]);
[matrixManager multModelView: [drawthing drawRotationMatrix]];
}
else
{
// Load transformation matrix
GLLoadOOMatrix(view_matrix);
//GLLoadOOMatrix(view_matrix);
[matrixManager loadModelView: view_matrix];
//translate the object from the viewpoint
GLTranslateOOVector(vector_flip(viewOffset));
//GLTranslateOOVector(vector_flip(viewOffset));
[matrixManager translateModelView: vector_flip(viewOffset)];
}
[matrixManager syncModelView];
// atmospheric fog
fogging = (inAtmosphere && ![drawthing isStellarObject]);
@ -4257,7 +4261,7 @@ static const OOMatrix starboard_matrix =
OOGL(glDisable(GL_FOG));
}
OOGL(glPopMatrix());
[matrixManager popModelView];
}
}
@ -4277,21 +4281,21 @@ static const OOMatrix starboard_matrix =
if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode)) // either in flight or in demo ship mode
{
OOGL(glPushMatrix());
[matrixManager pushModelView];
if (EXPECT(drawthing != player))
{
//translate the object
// HPVect: camera relative positions
GLTranslateOOVector([drawthing cameraRelativePosition]);
[matrixManager translateModelView: [drawthing cameraRelativePosition]];
//rotate the object
GLMultOOMatrix([drawthing drawRotationMatrix]);
[matrixManager multModelView: [drawthing drawRotationMatrix]];
}
else
{
// Load transformation matrix
GLLoadOOMatrix(view_matrix);
[matrixManager loadModelView: view_matrix];
//translate the object from the viewpoint
GLTranslateOOVector(vector_flip(viewOffset));
[matrixManager translateModelView: vector_flip(viewOffset)];
}
// experimental - atmospheric fog
@ -4309,6 +4313,7 @@ static const OOMatrix starboard_matrix =
}
// draw the thing
[matrixManager syncModelView];
[drawthing drawImmediate:false translucent:true];
// atmospheric fog
@ -4317,12 +4322,13 @@ static const OOMatrix starboard_matrix =
OOGL(glDisable(GL_FOG));
}
OOGL(glPopMatrix());
[matrixManager popModelView];
}
}
}
OOGL(glPopMatrix()); //restore saved flat viewpoint
[matrixManager popModelView];
[matrixManager syncModelView];
if (EXPECT(!displayGUI || demoShipMode))
{

View File

@ -37,6 +37,7 @@ MA 02110-1301, USA.
#import "OOGraphicsResetManager.h"
#import "OOCollectionExtractors.h" // for splash screen settings
#import "OOFullScreenController.h"
#import "OOOpenGLMatrixManager.h"
#define kOOLogUnconvertedNSLog @"unclassified.MyOpenGLView"
@ -610,6 +611,7 @@ MA 02110-1301, USA.
SDL_Rect dest;
NSString *imagesDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"];
OOOpenGLMatrixManager *matrixManager = [OOOpenGLMatrixManager sharedOpenGLMatrixManager];
image = SDL_LoadBMP([[imagesDir stringByAppendingPathComponent:@"splash.bmp"] UTF8String]);
@ -656,15 +658,12 @@ MA 02110-1301, USA.
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
[matrixManager resetProjection];
[matrixManager orthoLeft: 0.0f right: dest.w bottom: dest.h top: 0.0 near: -1.0 far: 1.0];
[matrixManager syncProjection];
glOrtho(0.0f, dest.w , dest.h, 0.0f, -1.0f, 1.0f);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
[matrixManager resetModelView];
[matrixManager syncModelView];
GLuint texture;
GLenum texture_format;
@ -718,7 +717,8 @@ MA 02110-1301, USA.
glEnd();
SDL_GL_SwapBuffers();
glLoadIdentity(); // reset matrix
[matrixManager resetModelView];
[matrixManager syncModelView];
if ( image ) {
SDL_FreeSurface( image );