Jump to content
  • Advertisement
Sign in to follow this  
fjj

OpenGL Is any body using GLU_NURBS_TESSELLATOR and callback functions?

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
Advertisement
Are u sure the call back is not being invoked ?
Try putting printf inside the callback
I have used nurbs call backs for nurbs surfaces .. seems to work fine ..

I think i see the error . in the BEGIN call back .. u should pass the variable type to the glBegin call ....
So it should be like this ::

void CALLBACK beginCallback(GLenum type)
{

// type=GL_LINES;
glBegin( type );
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!