2d Texture



  • Hallo zusammen,

    ich quäle mich hier, wahrscheinlich mit etwas einfachem, ich habe das folgende Programm aus dem Internet :

    #include <stdlib.h>
    #include <GL/glut.h>
    
    GLuint CubeList;
    GLfloat angle = 0;
    
    void display() {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Puffer Leeren
        glLoadIdentity(); //Modelviewmatrix auf Identität setzen
    
        //"lokales Koordinatensystem" in den Raum schieben
        glTranslatef( 0.0, 0.0,-3.0);
    
        //Um den Winkel angle um Achse 1,1,0 rotieren
        glRotatef(angle, 1.0, 1.0, 0.0);
    
        //Würfel zeichnen
        glCallList(CubeList);
    
        glutSwapBuffers();
    }
    
    void buildCube() {
        //Initialisieren der Listen-Variable
        CubeList = glGenLists(1);
    
        //Liste bauen
        glNewList(CubeList, GL_COMPILE);
    
            //Front Face
            glColor3f( 0.0, 0.8, 0.0);
            glBegin(GL_QUADS);
                    glVertex3f( 1.0, 1.0, 1.0);
                    glVertex3f(-1.0, 1.0, 1.0);
                    glVertex3f(-1.0,-1.0, 1.0);
                    glVertex3f( 1.0,-1.0, 1.0);
            glEnd();
    
            //Back Face
            glColor3f( 0.8, 0.0, 0.0);
            glBegin(GL_QUADS);
                    glVertex3f(-1.0, 1.0,-1.0);
                    glVertex3f( 1.0, 1.0,-1.0);
                    glVertex3f( 1.0,-1.0,-1.0);
                    glVertex3f(-1.0,-1.0,-1.0);
            glEnd();
    
            //Left Face
            glColor3f( 0.0, 0.0, 8.0);
            glBegin(GL_QUADS);
                    glVertex3f(-1.0, 1.0, 1.0);
                    glVertex3f(-1.0, 1.0,-1.0);
                    glVertex3f(-1.0,-1.0,-1.0);
                    glVertex3f(-1.0,-1.0, 1.0);
            glEnd();
    
            //Right Face
            glColor3f( 0.0, 8.0, 8.0);
            glBegin(GL_QUADS);
                    glVertex3f( 1.0, 1.0,-1.0);
                    glVertex3f( 1.0, 1.0, 1.0);
                    glVertex3f( 1.0,-1.0, 1.0);
                    glVertex3f( 1.0,-1.0,-1.0);
            glEnd();
    
            //Top Face
            glColor3f( 8.0, 8.0, 0.0);
            glBegin(GL_QUADS);
                    glVertex3f( 1.0, 1.0,-1.0);
                    glVertex3f(-1.0, 1.0,-1.0);
                    glVertex3f(-1.0, 1.0, 1.0);
                    glVertex3f( 1.0, 1.0, 1.0);
            glEnd();
    
            //Bottom Face
            glColor3f( 8.0, 0.0, 8.0);
            glBegin(GL_QUADS);
                    glVertex3f( 1.0,-1.0,-1.0);
                    glVertex3f( 1.0,-1.0, 1.0);
                    glVertex3f(-1.0,-1.0, 1.0);
                    glVertex3f(-1.0,-1.0,-1.0);
            glEnd();
    
        glEndList();
    }
    
    void idle() {
        //Den Winkel ein wenig erhöhen
        angle = (angle + 0.1);
        if (angle > 360) {
            angle -= 360;
        }
    
        //und Neuzeichnen anfordern
        glutPostRedisplay();
    }
    
    void keyboard(unsigned char key,int w, int h)
    {
        switch(key)
        {
            case 'a':
             angle = angle + 1;
             glutPostRedisplay();
             break;
            case 'd':
             angle = angle- 1;
             glutPostRedisplay();
             break;
        }
    }
    
    void initOpenGL() {
        //Depth testing
        glEnable(GL_DEPTH_TEST);
    
        //Festlegen des Viewing Volume
        glMatrixMode(GL_PROJECTION);
        glFrustum(-1.0, 1.0,-1.0, 1.0, 1.0, 5.0);
        glMatrixMode(GL_MODELVIEW);
    }
    
    int main(int argc, char** argv) {
        glutInit(&argc, argv);
    
        //Double Buffering im RGB-Modus aktivieren
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    
        //Fenster erstellen
        glutInitWindowSize(500, 500);
        glutCreateWindow ("Spinning Cube OpenGL-Demo");
    
        //OpenGL-Initialisierung
        initOpenGL();
    
        //Display List erstellen
        buildCube();
    
        //Callbacks registrieren
        glutDisplayFunc(display);
        glutKeyboardFunc(keyboard);
    
        //Ausführung starten
        glutMainLoop();
    
        return 0;
    }
    

    Ich möchte jetzt nur für eine Seite des Würfels, eine Bild laden und als Texture benutzen, wie muss ich hier vorgehen ?



  • Du bedienst dich einfach wieder dem Internet. Weil ich heut gut drauf bin gibts sogar noch nen link:http://nehe.gamedev.net/



  • nur mal so, ich würde lieber bei gl_ und glu_ bleiben


Anmelden zum Antworten