2

私の問題は、OpenGLを使用して 2 つのアトムを作成する必要がある Xcode のプロジェクトがあり、そのうちの 1 つはウィンドウの中央にあり、もう 1 つは最初のアトムの周りを回転していることです。私の問題は、深みがないように見えることです。回転している原子が他の原子の後ろを通過することはありません。

私はこのコードを持っています:

#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>

const int W_WIDTH = 500;
const int W_HEIGHT = 500;
GLfloat Rot = 0;

void Display(void) {
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW); // Se activa la matriz del modelador
    glLoadIdentity(); //Se pone a "0" realmente al 1

    // Boramos la pantalla
    glOrtho(-500.0f, 500.0f, -500.0f, 500.0f, -500.0f, 500.0f);

    //glPushMatrix();
    glTranslatef(0.0f, 0.0f, -100.0f); // Se traslada todo al -100

    // Red Nucleus
    glColor3f(255, 0, 0);
    glutSolidSphere(12.0f, 20, 20); // Se dibuja una esfera


    glPushMatrix();
    // First Electron Orbit
    // Se hace un push copiamos la traslacion de -100 a la Pila
    // Save viewing transformation
    // Rotate by angle of revolution
    //Sumamos a la translacion -100 una rotacion = -100 + rotacion

    glRotatef(Rot, 0.0f, 1.0f, 0.0f);
    // Translate out from origin to orbit distance
    glTranslatef(90.0f, 0.0f, 0.0f); //Sumamos a la -100 + rotacion una nueva traslacion  = -100 + rotacion + 90
    glColor3f(0, 00, 100);
    glutSolidSphere(8.0f, 20, 20); // Draw the electron
    // Se recupera la matriz de la pila quie era -100
    /* Se dibujan los siguiente electrone.*/

    glPopMatrix();

    /*
        glPushMatrix();
        glColor3f(0, 00, 100);
        glRotatef(fAngulo, 0.0f, 1.0f, 0.0f);
        glTranslatef(-90.0f, 0.0f, 0.0f);
        glutSolidSphere(6.0f, 20, 20);
        fAngulo = fAngulo + 0.03;
        glPopMatrix();
    */

    glutSwapBuffers();// Se limpian los buffers
    glFlush();
}

void idle(void) {
    Rot += 0.01;
    if(Rot > 360.0f)
        Rot = 0.0f;
    glutPostRedisplay();
}



int main(int argc, char **argv) {

    glutInit(&argc, argv);
    //Inicializa la ventana en una determinada posicion
    glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE); // Nombre de la ventana
    glutInitWindowPosition(0, 0);
    //Inicializa el tamano de la funcion
    glutInitWindowSize (W_WIDTH, W_HEIGHT); //Inicaliza el modeo de display, RGBA y Doble buffer

    glutCreateWindow("Ventana");

    glutDisplayFunc(Display);
    glutIdleFunc(idle);

    glutMainLoop();
    return 0;
}
4

1 に答える 1

3
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE);

深度バッファーなしで深度テストを行うことをどのように計画していましたか? その電車GLUT_DEPTHの後ろを平手打ち。OR

于 2013-03-02T20:32:26.647 に答える