Results 1 to 4 of 4

Thread: Bug: rendered objects turning black.

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    17

    Bug: rendered objects turning black.

    I am rendering a NURBS patch and some control points. As soon as I render the control points the NURBS patch goes completely dark.

    Code :
    void drawNURB() {
     
    	glPushMatrix();
     
    	GLfloat diffuseColor[] = {0.8, 0.8, 1.0, 1.0};
     
    	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
    	glMatrixMode(GL_MODELVIEW);
     
    	gluBeginSurface(nurbRenderer);
     
    		gluNurbsSurface(nurbRenderer,
     
    				sKnotCount, sKnot,
     
    				tKnotCount, tKnot,
     
    				sStride, tStride,
     
    				ctlArray,
     
    				sOrder, tOrder,
     
    				GL_MAP2_VERTEX_3);
     
    	gluEndSurface(nurbRenderer);
    	glPopMatrix();
     
    }
     
    void drawCtl() {
    	glPushMatrix();
     
    	GLfloat diffuseColor[] = {0.8, 0.8, 1.0, 1.0};
     
    	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
    	glMatrixMode(GL_MODELVIEW);
     
    	int i; 
     
     
    	for (i = 0; i < ctlNum; i++) {
     
    		glPushMatrix();
     
    			glTranslatef(ctlArray[(3*i)], ctlArray[(3*i)+1], ctlArray[(3*i)+2]);
    			glutSolidSphere(.5, 4, 4);
     
    		glPopMatrix();	
     
    	}
    	glPopMatrix();
    }
     
    void display (void) {
     
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glMatrixMode(GL_MODELVIEW);
     
    	setUpLight();
     
    	setUpView();
     
     
    	drawNURB();
    	drawCtl();	
     
     
    	glutSwapBuffers();
     
    }

    Am I doing anything bad in these calls? Thanks in advance for the help.

  2. #2
    Senior Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: Bug: rendered objects turning black.

    Do you call glEnable(GL_AUTO_NORMAL) somewhere to enable the generation of normal vectors for the NURBS? I have tried something similar to your code and it work well.

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Bug: rendered objects turning black.

    Or you can also specify precomputed normals with gluNurbsSurface using GL_MAP2_NORMAL as surface type according to the end of this page.

    You got a black surface, because with lighting is enabled and when you call glutSolidSphere, this one set the sphere normals. Then when you draw the nurb surface without specifying vertex normals, the last specified normal (from the sphere) is used and could lead to unexpected results.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    17

    Re: Bug: rendered objects turning black.

    Thanks. This solved my problem.

Similar Threads

  1. Depth buffer rendered over objects
    By dr4cula in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-29-2013, 01:35 PM
  2. Showing subset of currently rendered objects
    By jas511 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-06-2012, 06:03 AM
  3. testing objects if they were rendered
    By Iblues76 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-13-2011, 08:43 AM
  4. Merging two rendered objects
    By rrankene in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-13-2005, 09:40 PM
  5. Replies: 0
    Last Post: 09-30-2003, 08:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean