glut / OpenGL / failed to open display



  • Hallo,

    Ich habe hier ein Testprogramm, welches ein OpenGL Beispiel sein sollte.. Nachdem ich nun endlich es hinbekommen habe dass auch die Header gefunden werden wird auch erfogreich kompiliert, nur in der Konsole steht was von freeglut ... failed to open display .

    Ich verwende Windows/Cygwin/Netbeans/c++

    Weis jemand wie sich das Problem lösen lässt?

    Gruß
    Geddon



  • Hallo Geddon,

    nachdem ich deinen Code nicht kenne, tippe ich mal, dass du vergessen hast GLUT zu initialisieren. Das kannst du mit folgender Zeile nachholen:

    glutInit(&argc, argv);
    

    wobei argc und argv die Parameter deiner main sind.

    Viele Grüße,
    MaBa



  • Nein, das hab ich schon im Code



  • Darf jeder einen Tipp abgeben? 😃

    Zeig uns doch deinen Code, dann finden wir den Fehler bestimmt schneller 🙂

    Viele Grüße,
    MaBa



  • #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    #include <GL/glu.h> 
    #include <GL/gl.h>  
    #include <GL/glut.h>
    #include <iostream> 
    
    using namespace std;
    
    // These variables set the dimensions of the rectanglar region we wish to view.
    const double Xmin = 0.0, Xmax = 10.0;
    const double Ymin = 0.0, Ymax = 10.0;
    
    // glutKeyboardFunc is called below to set this function to handle
    //		all "normal" ascii key presses.
    // Only space bar and escape key have an effect.
    
    void myKeyboardFunc(unsigned char key, int x, int y) {
        switch (key) {
            case ' ': // Space bar
                // Increment the current mode, and tell operating system screen needs redrawing
                glutPostRedisplay();
                break;
            case 27: // "27" is theEscape key
                exit(1);
        }
    }
    
    // Initialize OpenGL's rendering modes
    
    void initRendering() {
        glEnable(GL_DEPTH_TEST);
        // The following commands should cause points be drawn larger
        //	than a single pixel width.
        glPointSize(3);
    
        // The following commands should induce OpenGL to create round points and
        glEnable(GL_POINT_SMOOTH);
        glEnable(GL_LINE_SMOOTH);
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); // Make round points, not square points
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    
    // Called when the window is resized
    //		w, h - width and height of the window in pixels.
    
    void resizeWindow(int w, int h) {
        double scale, center;
        double windowXmin, windowXmax, windowYmin, windowYmax;
        // Define the portion of the window used for OpenGL rendering.
        glViewport(0, 0, w, h); // View port uses whole window
        // Set up the projection view matrix: orthographic projection
        // Determine the min and max values for x and y that should appear in the window.
        // The complication is that the aspect ratio of the window may not match the
        //		aspect ratio of the scene we want to view.
        w = (w == 0) ? 1 : w;
        h = (h == 0) ? 1 : h;
        if ((Xmax - Xmin) / w < (Ymax - Ymin) / h) {
            scale = ((Ymax - Ymin) / h) / ((Xmax - Xmin) / w);
            center = (Xmax + Xmin) / 2;
            windowXmin = center - (center - Xmin) * scale;
            windowXmax = center + (Xmax - center) * scale;
            windowYmin = Ymin;
            windowYmax = Ymax;
        } else {
            scale = ((Xmax - Xmin) / w) / ((Ymax - Ymin) / h);
            center = (Ymax + Ymin) / 2;
            windowYmin = center - (center - Ymin) * scale;
            windowYmax = center + (Ymax - center) * scale;
            windowXmin = Xmin;
            windowXmax = Xmax;
        }
        // Now that we know the max & min values for x & y that should be visible in the window,
        //		we set up the orthographic projection.
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(windowXmin, windowXmax, windowYmin, windowYmax, -1, 1);
    }
    
    /*
     * drawScene() handles the animation and the redrawing of the
     *	       graphics window contents.
     */
    void drawScene() {
        const float resolution = 0.05;
        // Clear the rendering window
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // Set drawing color to white
        glColor3f(1.0, 1.0, 1.0);
    
        // Draw three points
        glBegin(GL_POINTS);
        // ab hier aendern
        for (int i = 0; i < 400; i++)
            glVertex2f(i * resolution, 4 * sqrt(i) * resolution);
        // bis hierhin aendern
        glEnd();
    
        // Flush the pipeline.  (Not usually necessary.)
        glFlush();
    
    }
    
    int main(int argc, char** argv) {
        glutInit(&argc, argv);
        // Set up OpenGL, define the callbacks and start the main loop
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    
        // Window position (from top corner), and size (width and hieght)
        glutInitWindowPosition(20, 60);
        glutInitWindowSize(500, 500);
        glutCreateWindow("Zeichenbrett");
    
        // Initialize OpenGL as we like it..
        initRendering();
    
        // Set up callback functions for key presses
        glutKeyboardFunc(myKeyboardFunc); // Handles "normal" ascii symbols
    
        // Set up the callback function for resizing windows
        glutReshapeFunc(resizeWindow);
    
        // Call this for background processing
        // glutIdleFunc( myIdleFunction );
    
        // call this whenever window needs redrawing
        glutDisplayFunc(drawScene);
    
        // Clear the rendering window
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        fprintf(stdout, "Press escape button to quit.\n");
    
        // Start the main loop.  glutMainLoop never returns.
        glutMainLoop();
    
        return (0); // This line is never reached.
    }
    

    bproject/Makefile-NewConfiguration.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory /cygdrive/c/Users/Stefan/Documents/NetBeansProjects/OpenGL' /usr/bin/make -f nbproject/Makefile-NewConfiguration.mk dist/NewConfiguration/Cygwin-Windows/opengl.exe make[2]: Entering directory/cygdrive/c/Users/Stefan/Documents/NetBeansProjects/OpenGL'
    mkdir -p build/NewConfiguration/Cygwin-Windows
    rm -f build/NewConfiguration/Cygwin-Windows/main.o.d
    g++.exe -c -g -I/cygdrive/C/cygwin/usr/include/GL -MMD -MP -MF build/NewConfiguration/Cygwin-Windows/main.o.d -o build/NewConfiguration/Cygwin-Windows/main.o main.cpp
    mkdir -p dist/NewConfiguration/Cygwin-Windows
    g++.exe -o dist/NewConfiguration/Cygwin-Windows/opengl build/NewConfiguration/Cygwin-Windows/main.o -lglut -glu32 -glut32 -glut -lGL -OpenGL32 -GLaux
    g++: unrecognized option '-GLaux'
    make[2]: Leaving directory /cygdrive/c/Users/Stefan/Documents/NetBeansProjects/OpenGL' make[1]: Leaving directory/cygdrive/c/Users/Stefan/Documents/NetBeansProjects/OpenGL'
    BUILD SUCCESSFUL (total time: 2s)



  • Hallo Geddon,

    der Code sieht o.k. aus. Das

    #include <GL/gl.h>
    

    kannst du dir sparen, wenn du GLUT verwendest.

    Ich habs eben mal unter Windows mit Visual Studio getestet: Funktioniert ohne Probleme.

    Evtl. hilft das hier:
    http://www.listware.net/201007/netbeans-cnd-users/44645-trouble-running-openglfreeglutwindows-program-that-compiles-fine-failed-to-open-display.html

    Viele Grüße,
    MaBa


Anmelden zum Antworten