mesa-demos: NOTE! Default branch is now main
[mesa-demos.git] / src / trivial / vp-tri-cb-pos.c
blob49fe7a85569b782e610321f1bb6e76e657cd9b56
1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
3 #include <stdio.h>
4 #include <assert.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <glad/glad.h>
9 #include "glut_wrap.h"
13 GLenum doubleBuffer;
15 static void Init(void)
17 GLint errnum;
18 GLuint prognum;
20 static const char *prog1 =
21 "!!ARBvp1.0\n"
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.color, vertex.color;\n"
31 "END\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)
54 GLint errorpos;
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);
66 static void Reshape(int width, int height)
69 glViewport(0, 0, (GLint)width, (GLint)height);
71 glMatrixMode(GL_PROJECTION);
72 glLoadIdentity();
73 /* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
74 glMatrixMode(GL_MODELVIEW);
77 static void Key(unsigned char key, int x, int y)
80 switch (key) {
81 case 27:
82 exit(1);
83 default:
84 break;
87 glutPostRedisplay();
90 static void Draw(void)
92 glClear(GL_COLOR_BUFFER_BIT);
94 glBegin(GL_TRIANGLES);
95 glColor3f(0,0,.7);
96 glVertex3f( 0.9, -0.9, -0.0);
97 glColor3f(.8,0,0);
98 glVertex3f( 0.9, 0.9, -0.0);
99 glColor3f(0,.9,0);
100 glVertex3f(-0.9, 0.0, -0.0);
101 glEnd();
103 glFlush();
105 if (doubleBuffer) {
106 glutSwapBuffers();
110 static GLenum Args(int argc, char **argv)
112 GLint i;
114 doubleBuffer = GL_FALSE;
116 for (i = 1; i < argc; i++) {
117 if (strcmp(argv[i], "-sb") == 0) {
118 doubleBuffer = GL_FALSE;
119 } else if (strcmp(argv[i], "-db") == 0) {
120 doubleBuffer = GL_TRUE;
121 } else {
122 fprintf(stderr, "%s (Bad option).\n", argv[i]);
123 return GL_FALSE;
126 return GL_TRUE;
129 int main(int argc, char **argv)
131 GLenum type;
133 glutInit(&argc, argv);
135 if (Args(argc, argv) == GL_FALSE) {
136 exit(1);
139 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
141 type = GLUT_RGB | GLUT_ALPHA;
142 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
143 glutInitDisplayMode(type);
145 if (glutCreateWindow(*argv) == GL_FALSE) {
146 exit(1);
149 gladLoadGL();
151 Init();
153 glutReshapeFunc(Reshape);
154 glutKeyboardFunc(Key);
155 glutDisplayFunc(Draw);
156 glutMainLoop();
157 return 0;