Problem mit gluCylinder



  • Hallo zusammen,
    noch ein anderes Problem plagt mich und zwar habe ich eine View aufgebaut mit einer Pyramide und einem Zylinder. Der Code basiert auch auf dem Tutorial von NeHe
    http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=05

    Nur habe ich den Würfel/Quader durch einen Zylinder ausgetauscht.
    Der Funktion sieht dann so aus:

    void DrawGLScene()
    {
    	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    	glLoadIdentity();				// Reset The View
    
    	glTranslatef(-1.5f,0.0f,-6.0f);		// Move Left 1.5 Units And Into The Screen 6.0
    
    	glRotatef(rtri,0.0f,1.0f,0.0f);		// Rotate The Pyramid On The Y axis 
    
    	// draw a pyramid (in smooth coloring mode)
    	glBegin(GL_POLYGON);				// start drawing a pyramid
    
    	// front face of pyramid
    	glColor3f(1.0f,0.0f,0.0f);			// Set The Color To Red
    	glVertex3f(0.0f, 1.0f, 0.0f);		        // Top of triangle (front)
    	glColor3f(0.0f,1.0f,0.0f);			// Set The Color To Green
    	glVertex3f(-1.0f,-1.0f, 1.0f);		// left of triangle (front)
    	glColor3f(0.0f,0.0f,1.0f);			// Set The Color To Blue
    	glVertex3f(1.0f,-1.0f, 1.0f);		        // right of traingle (front)	
    
    	// right face of pyramid
    	glColor3f(1.0f,0.0f,0.0f);			// Red
    	glVertex3f( 0.0f, 1.0f, 0.0f);		// Top Of Triangle (Right)
    	glColor3f(0.0f,0.0f,1.0f);			// Blue
    	glVertex3f( 1.0f,-1.0f, 1.0f);		// Left Of Triangle (Right)
    	glColor3f(0.0f,1.0f,0.0f);			// Green
    	glVertex3f( 1.0f,-1.0f, -1.0f);		// Right Of Triangle (Right)
    
    	// back face of pyramid
    	glColor3f(1.0f,0.0f,0.0f);			// Red
    	glVertex3f( 0.0f, 1.0f, 0.0f);		// Top Of Triangle (Back)
    	glColor3f(0.0f,1.0f,0.0f);			// Green
    	glVertex3f( 1.0f,-1.0f, -1.0f);		// Left Of Triangle (Back)
    	glColor3f(0.0f,0.0f,1.0f);			// Blue
    	glVertex3f(-1.0f,-1.0f, -1.0f);		// Right Of Triangle (Back)
    
    	// left face of pyramid.
    	glColor3f(1.0f,0.0f,0.0f);			// Red
    	glVertex3f( 0.0f, 1.0f, 0.0f);		// Top Of Triangle (Left)
    	glColor3f(0.0f,0.0f,1.0f);			// Blue
    	glVertex3f(-1.0f,-1.0f,-1.0f);		// Left Of Triangle (Left)
    	glColor3f(0.0f,1.0f,0.0f);			// Green
    	glVertex3f(-1.0f,-1.0f, 1.0f);		// Right Of Triangle (Left)
    
    	glEnd();					// Done Drawing The Pyramid
    
    	glLoadIdentity();				// make sure we're no longer rotated.
    
    	glTranslatef(1.5f,0.0f,-7.0f);		// Move Right 3 Units, and back into the screen 7
            rtri+=7.0f;				// Increase The Rotation Variable For The Pyramid
    
    	//glTranslatef(0.0f,0.0f,-1.5f);// Center The Cylinder
        	gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32);// Draw Our Cylinder
    
      	// swap the buffers to display, since double buffering is used.
      	glutSwapBuffers();
    }
    

    Der Code lässt sich ohne warnings o.ä. übersetzten, aber wenn ich das Programm aufrufe bekomme ich einen Speicherzugriffsfehler (unter Linux)

    Woran könnte das liegen. Muss ich noch irgend etwas initialisieren/anlegen, wenn ich GLU-Funktion aufrufe?

    Danke vorab

    Gruss Christian



  • wo kommt dein quadratic in

    gluCylinder(quadratic,1.0f,1.0f,3.0f,32,32);
    

    her? hast du es mit

    GLUquadric* quadratic;
    quadratic = gluNewQuadric();
    

    irgendwo initialisiert? wenn nicht - machen 🙂



  • Ich hatte die Variable global angelegt:

    GLUquadricObj *quadratic;
    

    aber nicht initialisiert.

    Ich habe die Deklaration so gelassen (global) aber in der DrawGLScene-Funktion die Variable (Objekt, wie man es sehen mag) eine die Initialisierung, die Du mir gezeigt hast eingefügt.

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glLoadIdentity();					
    quadratic = gluNewQuadric();	// hier ist es passiert
    

    und jetzt habe ich einen Zylinder, der liegt zwar noch auf dem Rücken, aber das bekomme ich schon hin 😃

    Vielen Dank nochmaa 🙂

    Gruss Christian

    P.S. Leider fand ich in dieser Doku nichts darüber, daß die Variable initialisiert werden muss:
    http://wiki.delphigl.com/index.php/gluCylinder
    Aber ich hatte es mir schon gedacht. [Korretur] da wird doch darauf hingewiesen daß man das gluNewQuadric anlegt. Naja wer lesen kann... Vorteil...[/Korrektur]


Anmelden zum Antworten