1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
15 static void Init(void)
20 static const char *prog1
=
22 "PARAM Emission = state.material.emission; \n"
23 "PARAM Ambient = state.material.ambient; \n"
24 "PARAM Diffuse = state.material.diffuse; \n"
25 "PARAM Specular = state.material.specular; \n"
26 "DP4 result.position.x, Ambient, vertex.position;\n"
27 "DP4 result.position.y, Diffuse, vertex.position;\n"
28 "DP4 result.position.z, Specular, vertex.position;\n"
29 "DP4 result.position.w, Emission, vertex.position;\n"
30 "MOV result.texcoord[0], vertex.texcoord[0];\n"
33 const float Ambient
[4] = { 0.0, 1.0, 0.0, 0.0 };
34 const float Diffuse
[4] = { 1.0, 0.0, 0.0, 0.0 };
35 const float Specular
[4] = { 0.0, 0.0, 1.0, 0.0 };
36 const float Emission
[4] = { 0.0, 0.0, 0.0, 1.0 };
37 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT
, Ambient
);
38 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, Diffuse
);
39 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, Specular
);
40 glMaterialfv(GL_FRONT_AND_BACK
, GL_EMISSION
, Emission
);
43 glGenProgramsARB(1, &prognum
);
45 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, prognum
);
46 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
47 strlen(prog1
), (const GLubyte
*) prog1
);
49 assert(glIsProgramARB(prognum
));
50 errnum
= glGetError();
51 printf("glGetError = %d\n", errnum
);
52 if (errnum
!= GL_NO_ERROR
)
56 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorpos
);
57 printf("errorpos: %d\n", errorpos
);
58 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
61 glEnable(GL_VERTEX_PROGRAM_NV
);
65 GLubyte tex2d
[SIZE
][SIZE
][3];
68 for (s
= 0; s
< SIZE
; s
++) {
69 for (t
= 0; t
< SIZE
; t
++) {
71 tex2d
[t
][s
][0] = (s
< SIZE
/2) ? 0 : 255;
72 tex2d
[t
][s
][1] = (t
< SIZE
/2) ? 0 : 255;
75 tex2d
[t
][s
][0] = s
*255/(SIZE
-1);
76 tex2d
[t
][s
][1] = t
*255/(SIZE
-1);
82 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
84 glTexImage2D(GL_TEXTURE_2D
, 0, 3, SIZE
, SIZE
, 0,
85 GL_RGB
, GL_UNSIGNED_BYTE
, tex2d
);
87 glEnable(GL_TEXTURE_2D
);
88 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
89 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_REPEAT
);
90 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
91 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
93 glPixelStorei(GL_UNPACK_ALIGNMENT
, 4);
99 static void Reshape(int width
, int height
)
102 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
104 glMatrixMode(GL_PROJECTION
);
106 /* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
107 glMatrixMode(GL_MODELVIEW
);
110 static void Key(unsigned char key
, int x
, int y
)
123 static void Draw(void)
125 glClear(GL_COLOR_BUFFER_BIT
);
127 glBegin(GL_TRIANGLES
);
129 glVertex3f( 0.9, -0.9, -0.0);
131 glVertex3f( 0.9, 0.9, -0.0);
133 glVertex3f(-0.9, 0.0, -0.0);
143 static GLenum
Args(int argc
, char **argv
)
147 doubleBuffer
= GL_FALSE
;
149 for (i
= 1; i
< argc
; i
++) {
150 if (strcmp(argv
[i
], "-sb") == 0) {
151 doubleBuffer
= GL_FALSE
;
152 } else if (strcmp(argv
[i
], "-db") == 0) {
153 doubleBuffer
= GL_TRUE
;
155 fprintf(stderr
, "%s (Bad option).\n", argv
[i
]);
162 int main(int argc
, char **argv
)
166 glutInit(&argc
, argv
);
168 if (Args(argc
, argv
) == GL_FALSE
) {
172 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
174 type
= GLUT_RGB
| GLUT_ALPHA
;
175 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
176 glutInitDisplayMode(type
);
178 if (glutCreateWindow(*argv
) == GL_FALSE
) {
186 glutReshapeFunc(Reshape
);
187 glutKeyboardFunc(Key
);
188 glutDisplayFunc(Draw
);