Problem with glunurbsCallback

Damien Bastid <[email protected]> Tue, 29 Apr 2008 06:40:37 -0800
Newsgroups gmane.games.devel.opengl
Organization Fat City Network Services, San Diego, California
Message-ID <[email protected]>
I'm trying to get the OpenGL polygon primitives resulting from the  
tessellation of a Nurbs. For that I use GLU and GLUT and  
gluNurbsCallback. Here is my code :


/**************** start of Code *********************/

#include <windows.h>
#include <GL/glut.h>
#include <GL/GL.h>
#include <GL/GLU.h>
#include <stdio.h>
#include <iostream>
using namespace std;

#ifndef CALLBACK
#define CALLBACK
#endif


GLfloat ctrlpoints[4][4][3];
int showPoints=0;
GLUnurbsObj *theNurb;

void init_surface()
{
	int u,v;
	for (u=0;u<4;u++)
	{
		for(v=0;v<4;v++)
		{
			ctrlpoints[u][v][0]=2.0*((GLfloat)u-1.5);
			ctrlpoints[u][v][1]=2.0*((GLfloat)v-1.5);

			if((u==1||u==2)&&(v==1||v==2))
				ctrlpoints[u][v][2]=3.0;
			else
				ctrlpoints[u][v][2]=-3.0;
		}
	}
}

void display()
{
	GLfloat knots[8]={0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
	glRotatef(330.0,1.0,0.0,0.0);
	glScalef(0.5,0.5,0.5);

	gluBeginSurface(theNurb);
	gluNurbsSurface(theNurb,8,knots,8,knots,4*3,3,&ctrlpoints[0][0][0],4,4,GL_MAP2_VERTEX_3);
	gluEndSurface(theNurb);

	glPopMatrix();
	glFlush();
}

void CALLBACK nurbsError(GLenum errorCode)
{
	char message[100];
	cout << "toto" << endl;
	sprintf(message,"%s",gluErrorString(errorCode));
	MessageBox(NULL,message,"NURBS Surface",MB_OK);
	exit(0);
}

void beginCallback(GLenum whichType)
{
	glBegin(whichType);

	cout << "titi" << endl;
	printf("glBegin(");
	switch(whichType)
	{
		case GL_LINES:
			printf("GL_LINES)\n");
			break;
		case GL_LINE_LOOP:
			printf("GL_LINE_LOOP)\n");
			break;
		case GL_LINE_STRIP:
			printf("GL_LINE_STRIP)\n");
			break;
		case GL_TRIANGLES:
			printf("GL_TRIANGLES)\n");
			break;
		case GL_TRIANGLE_STRIP:
			printf("GL_TRIANGLE_STRIP)\n");
			break;
		case GL_TRIANGLE_FAN:
			printf("GL_TRIANGLE_FUN)\n");
			break;
		case GL_QUADS:
			printf("GL_QUADS)\n");
			break;
		case GL_QUAD_STRIP:
			printf("GL_QUAD_STRIP)\n");
			break;
		case GL_POLYGON:
			printf("GL_POLYGON)\n");
			break;
		default:
			break;
	}

}

void CALLBACK endCallback()
{
	glEnd();
	printf("glEnd()\n");
}

void CALLBACK vertexCallback(GLfloat* vertex)
{
	glVertex3fv(vertex);
	printf("glVertex3f (%5.3f, %5.3f, %5.3f)\n",vertex[0],vertex[1],vertex[2]);
}

void CALLBACK normalCallback(GLfloat* normal)
{
	glNormal3fv(normal);
	printf("glNormal3f (%5.3f, %5.3f, %5.3f)\n",normal[0], normal[1], normal[2]);
}

void init()
{
	GLfloat mat_diffuse[]={0.7,0.7,0.7,1.0};
	GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
	GLfloat mat_shininess[]={100.0};

	glClearColor(1.0,1.0,1.0,1.0);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
	glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_AUTO_NORMAL);
	glEnable(GL_NORMALIZE);
	init_surface();

	theNurb=gluNewNurbsRenderer();
	gluNurbsProperty(theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR);
	gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,50.0);
	gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL);

	gluNurbsCallback(theNurb,GLU_NURBS_ERROR,(void(__stdcall  
*)(void))nurbsError);
	gluNurbsCallback(theNurb,GLU_NURBS_BEGIN,(void(__stdcall  
*)(void))beginCallback);
	gluNurbsCallback(theNurb,GLU_NURBS_VERTEX,(void(__stdcall  
*)(void))vertexCallback);
	gluNurbsCallback(theNurb,GLU_NURBS_NORMAL,(void(__stdcall  
*)(void))normalCallback);
	gluNurbsCallback(theNurb,GLU_NURBS_END,(void(__stdcall *)(void))endCallback);
}

void reshape(int w, int h)
{
	glViewport(0,0,(GLsizei) w, (GLsizei) h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0,(GLdouble)w/(GLdouble)h,3.0,8.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.0,0.0,-5.0);
}

int main (int argc, char** argv)
{

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
	glutInitWindowSize(350,350);
	glutInitWindowPosition(100,100);
	glutCreateWindow("NURBS callback interface");
	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutMainLoop();
	return 0;
}

/************* End of code *****************/


The result of the execution is an errorcode catch by the  
NurbsErrorCallBack which is : "invalid enum".

I use VC++ and GLUT v1.3.

Thanks for your answer.


----- 
FAQ and OpenGL Resources at:
  http://www.geocities.com/SiliconValley/Hills/9956/OpenGL

-- 
Author: Damien Bastid
  INET: [email protected]

Fat City Hosting, San Diego, California -- http://www.fatcity.com
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [email protected] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).