PDA

View Full Version : Problem with glMap2f and Nvida GeForce



gpeterpan
07-20-2010, 02:21 AM
Hi!

I have a little problem. Im creating a surface 3D with glMap2f, glMapGrid2f, glEvalMesh2 openGL functions and they are not working fine with nvidia GeForce cads. Im using the superbible example but I have changed the control points. This example works with other graphics cads. Can you help me, please? Maybe I have a error code and I cant see it.

This is the modificated example:




// Bez3d.c
// OpenGL SuperBible
// Program by Richard S. Wright Jr.

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "glut.h"

// The number of control points for this curve
GLint nFilas = 16;
GLint nCol = 11;

GLfloat ctrlPoints[528] =
{
//Fila 1
-6.8508f, 2.0688f, 12.1213f,
-7.2908f, 2.0688f, 10.5821f,
-7.6555f, 2.0688f, 9.0233f,
-7.9439f, 2.0688f, 7.4486f,
-8.1556f, 2.0688f, 5.8618f,
-8.0966f, 2.0688f, 4.2856f,
-7.4271f, 2.0688f, 2.8358f,
-6.4226f, 2.0688f, 1.5943f,
-5.1444f, 2.0688f, 0.6370f,
-3.6705f, 2.0688f, 0.0223f,
-2.0724f, 2.0688f, 0.0000f,
//Fila 2
-6.8508f, -0.1440f, 12.1213f,
-7.2832f, -0.0825f, 10.5676f,
-7.6377f, 0.0729f, 9.0040f,
-7.9144f, 0.2898f, 7.4259f,
-8.1135f, 0.5497f, 5.8398f,
-8.0446f, 0.8306f, 4.2663f,
-7.3730f, 1.1149f, 2.8257f,
-6.3714f, 1.3792f, 1.5917f,
-5.1014f, 1.6038f, 0.6399f,
-3.6408f, 1.7685f, 0.0273f,
-2.0611f, 1.8526f, 0.0000f,
//Fila 3
-6.8508f, -2.3565f, 12.1213f,
-7.2616f, -2.2234f, 10.5268f,
-7.5875f, -1.9056f, 8.9498f,
-7.8309f, -1.4837f, 7.3619f,
-7.9945f, -0.9845f, 5.7780f,
-7.8973f, -0.4490f, 4.2118f,
-7.2193f, 0.0998f, 2.7975f,
-6.2258f, 0.6159f, 1.5842f,
-4.9787f, 1.0669f, 0.6478f,
-3.5553f, 1.4190f, 0.0413f,
-2.0271f, 1.6385f, 0.0000f,
//Fila 4
-6.8508f, -4.5690f, 12.1213f,
-7.2283f, -4.3556f, 10.4637f,
-7.5095f, -3.8695f, 8.8659f,
-7.7010f, -3.2523f, 7.2630f,
-7.8092f, -2.5309f, 5.6824f,
-7.6679f, -1.7623f, 4.1277f,
-6.9794f, -0.9656f, 2.7538f,
-5.9980f, -0.2080f, 1.5726f,
-4.7857f, 0.4715f, 0.6602f,
-3.4196f, 1.0311f, 0.0631f,
-1.9710f, 1.4293f, 0.0000f,
//Fila 5
-6.8508f, -6.7815f, 12.1213f,
-7.1851f, -6.4806f, 10.3824f,
-7.4085f, -5.8209f, 8.7579f,
-7.5324f, -5.0161f, 7.1355f,
-7.5686f, -4.0862f, 5.5592f,
-7.3694f, -3.1018f, 4.0193f,
-6.6668f, -2.0701f, 2.6975f,
-5.7001f, -1.0790f, 1.5577f,
-4.5321f, -0.1690f, 0.6760f,
-3.2395f, 0.6146f, 0.0910f,
-1.8933f, 1.2272f, 0.0000f,
//Fila 6
-6.8508f, -8.9941f, 12.1213f,
-7.1342f, -8.5999f, 10.2869f,
-7.2891f, -7.7623f, 8.6310f,
-7.3329f, -6.7753f, 6.9858f,
-7.2834f, -5.6469f, 5.4145f,
-7.0153f, -4.4597f, 3.8919f,
-6.2950f, -3.2024f, 2.6314f,
-5.3446f, -1.9837f, 1.5401f,
-4.2280f, -0.8412f, 0.6947f,
-3.0209f, 0.1795f, 0.1239f,
-1.7948f, 1.0343f, 0.0000f,
//Fila 7
-6.8508f, -11.2066f, 12.1213f,
-7.0777f, -10.7150f, 10.1813f,
-7.1561f, -9.6960f, 8.4907f,
-7.1103f, -8.5304f, 6.8202f,
-6.9648f, -7.2099f, 5.2545f,
-6.6191f, -5.8283f, 3.7511f,
-5.8778f, -4.3517f, 2.5583f,
-4.9443f, -2.9087f, 1.5208f,
-3.8833f, -1.5318f, 0.7153f,
-2.7703f, -0.2642f, 0.1602f,
-1.6766f, 0.8527f, 0.0000f,
//Fila 8
-6.8508f, -13.4191f, 12.1213f,
-7.0175f, -12.8274f, 10.0696f,
-7.0142f, -11.6245f, 8.3423f,
-6.8723f, -10.2814f, 6.6452f,
-6.6238f, -8.7720f, 5.0853f,
-6.1943f, -7.2002f, 3.6022f,
-5.4291f, -5.5069f, 2.4810f,
-4.5118f, -3.8407f, 1.5003f,
-3.5084f, -2.2276f, 0.7371f,
-2.4940f, -0.7068f, 0.1987f,
-1.5401f, 0.6844f, 0.0000f,
//Fila 9
-6.8508f, -15.6316f, 12.1213f,
-6.9559f, -14.9385f, 9.9559f,
-6.8682f, -13.5501f, 8.1912f,
-6.6270f, -12.0289f, 6.4669f,
-6.2716f, -10.3300f, 4.9130f,
-5.7547f, -8.5678f, 3.4506f,
-4.9629f, -6.6571f, 2.4023f,
-4.0602f, -4.7667f, 1.4794f,
-3.1138f, -2.9155f, 0.7593f,
-2.1986f, -1.1387f, 0.2378f,
-1.3867f, 0.5313f, 0.0000f,
//Fila 10
-6.8508f, -17.8441f, 12.1213f,
-6.8949f, -17.0500f, 9.8442f,
-6.7230f, -15.4753f, 8.0429f,
-6.3821f, -13.7730f, 6.2918f,
-5.9193f, -11.8808f, 4.7438f,
-5.3138f, -9.9237f, 3.3017f,
-4.4935f, -7.7916f, 2.3250f,
-3.6026f, -5.6737f, 1.4589f,
-2.7102f, -3.5826f, 0.7811f,
-1.8912f, -1.5502f, 0.2762f,
-1.2181f, 0.3951f, 0.0000f,
//Fila 11
-6.8508f, -20.0567f, 12.1213f,
-6.8366f, -19.1633f, 9.7386f,
-6.5834f, -17.4024f, 7.9025f,
-6.1457f, -15.5143f, 6.1263f,
-5.5782f, -13.4214f, 4.5838f,
-4.8857f, -11.2605f, 3.1608f,
-4.0350f, -8.8996f, 2.2518f,
-3.1522f, -6.5488f, 1.4395f,
-2.3083f, -4.2162f, 0.8017f,
-1.5785f, -1.9320f, 0.3126f,
-1.0362f, 0.2771f, 0.0000f,
//Fila 12
-6.8508f, -22.2692f, 12.1213f,
-6.7831f, -21.2800f, 9.6432f,
-6.4541f, -19.3340f, 7.7757f,
-5.9257f, -17.2531f, 5.9766f,
-5.2597f, -14.9489f, 4.4391f,
-4.4843f, -12.5711f, 3.0335f,
-3.6017f, -9.9707f, 2.1857f,
-2.7224f, -7.3793f, 1.4220f,
-1.9192f, -4.8036f, 0.8203f,
-1.2678f, -2.2752f, 0.3455f,
-0.8429f, 0.1788f, 0.0000f,
//Fila 13
-6.3771f, -24.3740f, 12.1213f,
-6.2760f, -23.2968f, 9.5619f,
-5.9157f, -21.1760f, 7.6676f,
-5.3588f, -18.9056f, 5.8491f,
-4.6682f, -16.3905f, 4.3159f,
-3.8866f, -13.7944f, 2.9251f,
-3.0415f, -10.9565f, 2.1295f,
-2.2244f, -8.1294f, 1.4071f,
-1.5046f, -5.3213f, 0.8362f,
-0.9531f, -2.5676f, 0.3734f,
-0.6404f, 0.1012f, 0.0000f,
//Fila 14
-4.4334f, -25.2463f, 12.1213f,
-4.3490f, -24.1220f, 9.4988f,
-4.0801f, -21.9230f, 7.5838f,
-3.6719f, -19.5903f, 5.7502f,
-3.1694f, -17.0145f, 4.2203f,
-2.6085f, -14.3611f, 2.8409f,
-2.0180f, -11.4509f, 2.0858f,
-1.4564f, -8.5438f, 1.3955f,
-0.9720f, -5.6402f, 0.8485f,
-0.6139f, -2.7692f, 0.3951f,
-0.4309f, 0.0452f, 0.0000f,
//Fila 15
-2.2167f, -25.2463f, 12.1213f,
-2.1678f, -24.1073f, 9.4579f,
-2.0250f, -21.9005f, 7.5295f,
-1.8115f, -19.5903f, 5.6862f,
-1.5505f, -17.0517f, 4.1585f,
-1.2627f, -14.4444f, 2.7865f,
-0.9672f, -11.5706f, 2.0575f,
-0.6907f, -8.6881f, 1.3880f,
-0.4572f, -5.7857f, 0.8565f,
-0.2911f, -2.8814f, 0.4092f,
-0.2166f, 0.0113f, 0.0000f,
//Fila 16
-0.0000f, -25.2463f, 12.1213f,
0.0002f, -24.1020f, 9.4434f,
0.0002f, -21.8923f, 7.5103f,
0.0002f, -19.5902f, 5.6635f,
0.0002f, -17.0647f, 4.1365f,
0.0002f, -14.4736f, 2.7672f,
0.0002f, -11.6127f, 2.0475f,
0.0002f, -8.7389f, 1.3853f,
0.0002f, -5.8367f, 0.8593f,
0.0002f, -2.9207f, 0.4142f,
0.0000f, 0.0000f, 0.0000f
};

// This function is used to superimpose the control points over the curve
void DrawPoints(void)
{
int i,j; // Counting variables

// Set point size larger to make more visible
glPointSize(5.0f);

// Loop through all control points for this example
glBegin(GL_POINTS);
for(i = 0; i < nFilas; i++)
for(j = 0; j < nCol; j++)
{
float *point;
unsigned long ind;

ind = 3 * j + i * 3 * nCol;

point = &amp;ctrlPoints[ind];

glVertex3fv(point);
}
glEnd();
}



// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);

// Save the modelview matrix stack
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

// Rotate the mesh around to make it easier to see
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
glRotatef(60.0f, 1.0f, 0.0f, 0.0f);

// Sets up the Bezier
// This actually only needs to be called once and could go in
// the setup function
glMap2f(GL_MAP2_VERTEX_3, // Type of data generated
0.0f, // Lower u range
1.0f, // Upper u range
3, // Distance between points in the data
nCol, // Dimension in u direction (order)
0.0f, // Lover v range
1.0f, // Upper v range
3 * nCol, // Distance between points in the data
nFilas, // Dimension in v direction (order)
ctrlPoints); // array of control points

// Enable the evaluator
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_AUTO_NORMAL);

// Use higher level functions to map to a grid, then evaluate the
// entire thing.

// Map a grid of 10 points from 0 to 10
glColor3f(1.0f, 0.0f, 0.0f);
glMapGrid2f(nCol,0.0f,1.0f,nFilas,0.0f,1.0f);

// Evaluate the grid, using lines
glEvalMesh2(GL_FILL,0,nCol,0,nFilas);

glDisable(GL_MAP2_VERTEX_3);
glDisable(GL_AUTO_NORMAL);

// Draw the Control Points
glColor3f(0.0f, 0.0f, 1.0f);
DrawPoints();

// Restore the modelview matrix
glPopMatrix();

// Dispalay the image
glutSwapBuffers();
}

// This function does any needed initialization on the rendering
// context.
void SetupRC()
{
// Clear Window to white
glClearColor(1.0f, 1.0f, 1.0f, 1.0f );

// Draw in Blue
glColor3f(0.0f, 0.0f, 1.0f);
}


void ChangeSize(int w, int h)
{
// Prevent a divide by zero
if(h == 0)
h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-50.0f, 50.0f, -50.0f, 50.0f, -50.0f, 50.0f);

// Modelview matrix reset
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int main(int argc, char* argv[])
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("3D Bezier Surface");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();

return 0;
}