Ho scritto uno screensaver OpenGL per Mac OS X 10.5 e versioni successive che mostra un cuore rotante costruito utilizzando cubi in marcia. Funziona bene sul mio nero 13.3" sviluppo Macbook in esecuzione Snow Leopard (10.6), bella e lucida.Oggetto OpenGL lucido/lucido in Mac OS X 10.6, ma non 10.5. Perché?
Ma quando provo su un più nuovo MacBook Pro, ma in esecuzione di leopardo (10.5), l'isn cuore È come se fosse illuminato solo con luce ambiente/diffusa, ma senza luce speculare: è come se avessi impostato il componente speculare della luce su 0. Il più recente Macbook ha una scheda grafica Nvidia. esecuzione 10.6 ha un processore Intel XMA3100.
suo e è il mio codice di inizializzazione OpenGL. Il cuore è creato usando cubi in marcia e sto calcolando anche i normali vettori.
- (void)setUpOpenGL { [[glView openGLContext] makeCurrentContext]; // Synchronize buffer swaps with vertical refresh rate GLint swapInterval = 1; [[glView openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; glShadeModel(GL_SMOOTH); glClearDepth(1.0); glClearColor (0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); // Light GLfloat ambient_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat diffuse_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat specular_light[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat position_light[] = { 0.0f, 0.0f, -1.0f, 0.0f }; glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); glLightfv(GL_LIGHT0, GL_POSITION, position_light); // Material glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); GLfloat mat_ambient[] = {0.7, 0.0, 0.0, 1.0}; GLfloat mat_diffuse[] = { 0.7, 0.0, 0.0, 1.0 }; GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 0.0 }; GLfloat mat_shininess[] = { 100.0 }; glColor3f(1.0, 0.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // Copy isosurface vertices to graphics array glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, [marchingCubes vertices]); glNormalPointer(GL_FLOAT, 0, [marchingCubes normals]); }
Il codice di disegno attuale si presenta così:
- (void)drawRect:(NSRect)rect { [super drawRect:rect]; [[glView openGLContext] makeCurrentContext]; glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Adjust viewpoint to give heart beat effect glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, radius, 2*radius/3, 0, 0, 0, 0, 0, 1); // Adjust rotation to make heart spin glRotatef(rotation, 0.0f, 0.0f, 1.0f); // Draw heart glDrawArrays(GL_TRIANGLES, 0, [marchingCubes vertexCount]/3); glFlush(); [[glView openGLContext] flushBuffer]; // Rotate and scale a bit rotation += 1.0f; radius = 4.0 + 0.25*sin(rotation/4); }
Tutte le idee perché la differenza di illuminazione speculare? L'illuminazione speculare semplicemente non è supportata su alcune schede grafiche? Qualsiasi suggerimento è molto apprezzato.
Mai capito questo, ma open source del progetto: https://github.com/thinkski/ValentineGL –