Original Post
Is any body using gluNurbsProperty(nobj,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR) and gluNurbsCallback(nobj,GLU_NURBS_VERTEX, vertexCallback) to retrieve the coordinate on the nurbs curve? these features require glu1.3 When I using the functions to do the job, the callback functions doesnot invoked. the geometry could be drawn.
// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "gl/gl.h"
#include "gl/glu.h"
#include "gl/glut.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
typedef void (__stdcall *GluCallbackType)();
GLsizei winWidth = 200, winHeight = 150;
GLUnurbsObj *parabola;
float **array;
int i=0;
#ifndef CALLBACK
#define CALLBACK
#endif
void CALLBACK beginCallback(GLenum type)
{
type=GL_LINES;
glBegin(GL_LINES);
}
void CALLBACK endCallback()
{
glEnd();
}
void CALLBACK nurbsError (GLenum errorCode)
{
const GLubyte *estring;
estring = gluErrorString(errorCode);
fprintf(stderr, "Nurbs Error: %s\n", estring);
exit(0);
}
void CALLBACK vertexCallback(GLfloat *vertex)
{
glVertex3fv(vertex);
array[0]=vertex[0];
array[1]=vertex[1];
array[2]=vertex[2];
i++;
printf("%d", i);
printf("glVertex3f (%5.3f, %5.3f, %5.3f\n)", vertex[0],vertex[1],vertex[2]);
}
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200.0, 0.0, 150.0);
parabola = gluNewNurbsRenderer();
gluNurbsProperty(parabola,GLU_NURBS_MODE,GLU_NURBS_TESSELLATOR);
gluNurbsProperty(parabola,GLU_SAMPLING_TOLERANCE,100.0);
gluNurbsProperty(parabola,GLU_DISPLAY_MODE,GLU_FILL);
gluNurbsCallback(parabola,GLU_NURBS_BEGIN,(_GLUfuncptr) beginCallback);
gluNurbsCallback(parabola,GLU_NURBS_VERTEX,(_GLUfuncptr) vertexCallback);
gluNurbsCallback(parabola,GLU_NURBS_END,(_GLUfuncptr) endCallback);
gluNurbsCallback(parabola,GLU_NURBS_ERROR,(_GLUfuncptr) nurbsError);
}
void winReshapeFcn(int newWidth, int newHeight)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble) newWidth, 0.0, (GLdouble) newHeight);
glClear(GL_COLOR_BUFFER_BIT);
}
void curves(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
GLfloat knotVector [6] = {0.0,0.0,0.0,1.0,1.0,1.0};
GLfloat ctrlPts [3][3] = {{145.0,140.0,1.0},{105.0,60.0,1.0}, {55.0,140.0,1.0}};
gluBeginCurve(parabola);
gluNurbsCurve (parabola,6,knotVector,3,&ctrlPts[0][0],3,GL_MAP1_VERTEX_3);
gluEndCurve(parabola);
glBegin(GL_LINES);
glVertex2i(190,10);
glVertex2i(190,140);
glVertex2i(190,140);
glVertex2i(145,140);
glVertex2i(55,140);
glVertex2i(10,140);
glVertex2i(10,140);
glVertex2i(10,10);
glVertex2i(10,10);
glVertex2i(190,10);
glEnd();
glFlush();
}
int _tmain(int argc, char** argv)
{
int j=0;
FILE *fp;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(50,100);
glutInitWindowSize(400,300);
glutCreateWindow("An Example OpenGL Program");
init();
glutDisplayFunc(curves);
printf("%d", i);
fp = fopen("dataforvetex.txt","w");
for(j=0;j<i;j++)
{
fprintf(fp, "%5.3f, %5.3f, %5.3f \n",array[j][0], array[j][1], array[j][2]);
}
fclose(fp);
glutMainLoop();
return 0;
}