2 * Vertex program evaluators test.
3 * Based on book/bezmesh.c
14 #include "glut_wrap.h"
18 * Transform position by modelview/projection.
19 * Square incoming color.
21 static const char prog
[] =
24 "# Typical modelview/projection\n"
25 "DP4 o[HPOS].x, c[0], v[OPOS] ; # object x MVP -> clip\n"
26 "DP4 o[HPOS].y, c[1], v[OPOS] ;\n"
27 "DP4 o[HPOS].z, c[2], v[OPOS] ;\n"
28 "DP4 o[HPOS].w, c[3], v[OPOS] ;\n"
30 "MOV R0, v[COL0];\n # square the color\n"
32 "MOV o[COL0], R0;\n # store output color\n"
37 static int program
= 1;
40 GLfloat ctrlpoints
[4][4][4] =
43 {-1.5, -1.5, 4.0, 1.0},
44 {-0.5, -1.5, 2.0, 1.0},
45 {0.5, -1.5, -1.0, 1.0},
46 {1.5, -1.5, 2.0, 1.0}},
48 {-1.5, -0.5, 1.0, 1.0},
49 {-0.5, -0.5, 3.0, 1.0},
50 {0.5, -0.5, 0.0, 1.0},
51 {1.5, -0.5, -1.0, 1.0}},
53 {-1.5, 0.5, 4.0, 1.0},
54 {-0.5, 0.5, 0.0, 1.0},
56 {1.5, 0.5, 4.0, 1.0}},
58 {-1.5, 1.5, -2.0, 1.0},
59 {-0.5, 1.5, -2.0, 1.0},
61 {1.5, 1.5, -1.0, 1.0}}
72 GLfloat colorPoints
[4][4][4] =
78 {1.0, 0.0, 0.0, 1.0}},
83 {1.0, 0.3, 0.0, 1.0}},
88 {1.0, 0.6, 0.0, 1.0}},
100 #if 0 /* no lighting for now */
101 GLfloat ambient
[] = {0.2, 0.2, 0.2, 1.0};
102 GLfloat position
[] = {0.0, 0.0, 2.0, 1.0};
103 GLfloat mat_diffuse
[] = {0.6, 0.6, 0.6, 1.0};
104 GLfloat mat_specular
[] = {1.0, 1.0, 1.0, 1.0};
105 GLfloat mat_shininess
[] = {50.0};
107 glEnable(GL_LIGHTING
);
110 glLightfv(GL_LIGHT0
, GL_AMBIENT
, ambient
);
111 glLightfv(GL_LIGHT0
, GL_POSITION
, position
);
113 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, mat_diffuse
);
114 glMaterialfv(GL_FRONT
, GL_SPECULAR
, mat_specular
);
115 glMaterialfv(GL_FRONT
, GL_SHININESS
, mat_shininess
);
122 glClearColor(.3, .3, .3, 0);
123 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
126 glRotatef(85.0, 1.0, 1.0, 1.0);
128 glEvalMesh2(GL_FILL
, 0, 8, 0, 8);
134 myinit(int argc
, char *argv
[])
136 glClearColor(0.0, 0.0, 0.0, 1.0);
137 glEnable(GL_DEPTH_TEST
);
139 initlights(); /* for lighted version only */
141 glMapGrid2f(8, 0.0, 1.0, 8, 0.0, 1.0);
146 printf("Using vertex program attribs? %s\n", program
? "yes" : "no");
148 if (program
&& !glutExtensionSupported("GL_NV_vertex_program")) {
149 printf("Sorry, this requires GL_NV_vertex_program\n");
154 glMap2f(GL_MAP2_VERTEX_4
,
156 0.0, 1.0, 16, 4, &ctrlpoints
[0][0][0]);
157 glMap2f(GL_MAP2_COLOR_4
,
159 0.0, 1.0, 16, 4, &colorPoints
[0][0][0]);
160 glEnable(GL_MAP2_VERTEX_4
);
161 glEnable(GL_MAP2_COLOR_4
);
163 glEnable(GL_AUTO_NORMAL);
164 glEnable(GL_NORMALIZE);
168 glMap2f(GL_MAP2_VERTEX_ATTRIB0_4_NV
,
170 0.0, 1.0, 16, 4, &ctrlpoints
[0][0][0]);
171 glMap2f(GL_MAP2_VERTEX_ATTRIB3_4_NV
,
173 0.0, 1.0, 16, 4, &colorPoints
[0][0][0]);
174 glEnable(GL_MAP2_VERTEX_ATTRIB0_4_NV
);
175 glEnable(GL_MAP2_VERTEX_ATTRIB3_4_NV
);
178 glEnable(GL_AUTO_NORMAL);
179 glEnable(GL_NORMALIZE);
182 /* vertex program init */
183 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 1,
184 strlen(prog
), (const GLubyte
*) prog
);
185 assert(glIsProgramNV(1));
186 glBindProgramNV(GL_VERTEX_PROGRAM_NV
, 1);
189 glTrackMatrixNV(GL_VERTEX_PROGRAM_NV
, 0, GL_MODELVIEW_PROJECTION_NV
, GL_IDENTITY_NV
);
190 glEnable(GL_VERTEX_PROGRAM_NV
);
195 myReshape(int w
, int h
)
197 glViewport(0, 0, w
, h
);
198 glMatrixMode(GL_PROJECTION
);
201 glOrtho(-4.0, 4.0, -4.0 * (GLfloat
) h
/ (GLfloat
) w
,
202 4.0 * (GLfloat
) h
/ (GLfloat
) w
, -4.0, 4.0);
204 glOrtho(-4.0 * (GLfloat
) w
/ (GLfloat
) h
,
205 4.0 * (GLfloat
) w
/ (GLfloat
) h
, -4.0, 4.0, -4.0, 4.0);
206 glMatrixMode(GL_MODELVIEW
);
211 key(unsigned char k
, int x
, int y
)
214 case 27: /* Escape */
224 main(int argc
, char **argv
)
226 glutInit(&argc
, argv
);
227 glutInitDisplayMode(GLUT_SINGLE
| GLUT_RGB
| GLUT_DEPTH
);
228 glutInitWindowPosition(0, 0);
229 glutCreateWindow(argv
[0]);
232 glutReshapeFunc(myReshape
);
233 glutDisplayFunc(display
);
234 glutKeyboardFunc(key
);
236 return 0; /* ANSI C requires main to return int. */