Sign in to follow this  
mc3

OpenGL big troubles with nurbs

Recommended Posts

hi all i've just finished my second program in openGL and at the last moment when i ive just hoped everything is set up a terrible bug just occured the main purpose of my program is to draw several nurbs objects and to implement some kind of movement aka "walk" and "examine" you see when i try to walk (using W/S/A/D keys forw/back/left/right) the program just hangs up (processor up to 100%), however when i don't draw nurbs (//draw_nurbs();) everything is fine and works really fast and one more thing when i switch from perspective to ortho projection everything is fine aswell even with the nurbs turned on i've already tried almost everything but that bug just seems to appear from nowhere - only few days left when i have to give the program to my teacher so i would really appreciate if you would help me with that i compile under dev-c++ 4.9.9.2 winxp sp2 en here comes the link to archive with source and exe (no trojans or viruses u can check thats vilnius univercity homepage http://mif.vu.lt) http://www.mif.vu.lt/~much1973/nurbs.zip //display function void display () { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /*clear the window */ glLoadIdentity(); glLightfv(GL_LIGHT0, GL_POSITION, lpos0); gluLookAt(moveX, moveY, moveZ, moveX - sin(moveTurn), moveY, moveZ - cos(moveTurn), 0, 1, 0); glRotatef(-stheta, 1.0, 0.0, 0.0); glRotatef(sphi, 0.0, 1.0, 0.0); glPushMatrix(); isColored = true; glTranslatef(0, 1.1, 0); draw_nurbs(); draw_poly(); glPopMatrix(); glPushMatrix(); glColor4f(0.1, 0.1, 0.1, 0.1); draw_shadow(); glTranslatef(0, 1.1, 0); glDisable(GL_LIGHTING); isColored = false; draw_nurbs(); draw_poly(); glPopMatrix(); glEnable(GL_LIGHTING); draw_room(); draw_sun(); //gluDeleteNurbsRenderer(nurb); //glFlush(); /* clear buffers */ glutSwapBuffers(); } //init function void OpenGLinit(void) { glClearColor(0.0, 0.0, 0.0, 1.0); /* black background */ glClearDepth( 1.0 ); glEnable( GL_DEPTH_TEST ); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_AUTO_NORMAL); glEnable( GL_MAP2_VERTEX_3 ); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glLightfv(GL_LIGHT0, GL_AMBIENT, lamb0); glLightfv(GL_LIGHT0, GL_DIFFUSE, ldiff0); glLightfv(GL_LIGHT0, GL_SPECULAR, lspec0); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT1, GL_DIFFUSE, ldiff1); glLightfv(GL_LIGHT1, GL_SPECULAR, lspec1); glLightfv(GL_LIGHT1, GL_POSITION, lpos1); glEnable(GL_LIGHT1); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gl_ambient); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT, GL_SPECULAR, matspec0); glMaterialf(GL_FRONT, GL_SHININESS, 95.0); nurb = gluNewNurbsRenderer(); gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 25.0); gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL); } //reshape func void resize(int w, int h) { float aspectRatio; h = (h == 0) ? 1 : h; w = (w == 0) ? 1 : w; glViewport( 0, 0, w, h ); // View port uses whole window aspectRatio = (float)w/(float)h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (isOrtho) glOrtho(-width/height*5, width/height*5, -5, 5, 0, 100);//glOrtho(-20, 20, -20, 20, -20, 20); //(z looks at us) else gluPerspective(angle, aspectRatio, 1, 50); glMatrixMode(GL_MODELVIEW); } //nurbzzzzzzzzzzzzzzzzzzzzz void draw_nurbs() { float rad = r; float tmp = rad*sqrt(2.0)/2.0; GLfloat ctrlPoints[51][3] = { {1, 1-rad, 0-rad}, {1, 1-rad, 0-rad}, {1, 1-rad, 0-rad}, {1, 1, 0-rad}, {1, 1, 0}, {1, 1-rad, 0}, {1, 1, 0-rad}, {1, 1, 0}, {1, 1-rad, 0}, {0+tmp, 1, 1-tmp-rad}, {0+tmp, 1, 1-tmp}, {0+tmp, 1-rad, 1-tmp}, {0-rad, 1, 1-rad}, {0-rad, 1, 1}, {0-rad, 1-rad, 1}, {-1, 1, 1-rad}, {-1, 1, 1}, {-1, 1-rad, 1}, {-1, 1, 1-rad}, {-1, 1, 1}, {-1, 1-rad, 1}, {-1, 1-rad, 1-rad}, {-1, 1-rad, 1-rad}, {-1, 1-rad, 1-rad}, {0+tmp, 1, 1-tmp-rad}, {0+tmp, 1, 1-tmp}, {0+tmp, 1-rad, 1-tmp}, {0, 1, 1-rad}, {0, 1, 1}, {0, 1-rad, 1}, {0-rad, 1, 1-rad}, {0-rad, 1, 1}, {0-rad, 1-rad, 1}, {0, 1, 1-2*rad}, {0+tmp, 1, 1-tmp-rad}, {0, 1, 1-2*rad}, {0, 1, 1-rad}, {0, 1, 1-2*rad}, {0-rad, 1, 1-rad}, {0+tmp, 1-rad, 1-tmp}, {0+tmp, -1, 1-tmp}, {0, 1-rad, 1}, {0, -1, 1}, {0-rad, 1-rad, 1}, {0-rad, -1, 1}, {0+tmp, -1, 1-tmp}, {0, -1, 1-rad}, {0, -1, 1}, {0, -1, 1-rad}, {0-rad, -1, 1}, {0, -1, 1-rad} }; //glMaterialfv(GL_FRONT, GL_SPECULAR, matspec0); //glMateriali(GL_FRONT, GL_SHININESS, 90); for (int step = 0; step < 4; step++) { gluBeginSurface(nurb); gluNurbsSurface(nurb, 4, knots4, 6, knots6, 3 * 3, 3, &ctrlPoints[step*6][0], 2, 3, GL_MAP2_VERTEX_3); if(isColored) gluNurbsSurface(nurb, 4, knots4, 6, knots6, 3 * 3, 3, &colorPoints[step*6][0], 2, 3, GL_MAP2_COLOR_4); gluEndSurface(nurb); } gluBeginSurface(nurb); gluNurbsSurface(nurb, 6, knots6, 6, knots6, 3 * 3, 3, &ctrlPoints[24][0], 3, 3, GL_MAP2_VERTEX_3); if(isColored) gluNurbsSurface(nurb, 6, knots6, 6, knots6, 3 * 3, 3, &colorPoints[24][0], 3, 3, GL_MAP2_COLOR_4); gluEndSurface(nurb); for (int step = 0; step < 3; step++) { gluBeginSurface(nurb); gluNurbsSurface(nurb, 6, knots6, 4, knots4, 2 * 3, 3, &ctrlPoints[33+step*6][0], 3, 2, GL_MAP2_VERTEX_3); if(isColored) gluNurbsSurface(nurb, 6, knots6, 4, knots4, 2 * 3, 3, &colorPoints[33+step*6][0], 3, 2, GL_MAP2_COLOR_4); gluEndSurface(nurb); } }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this