mesa-demos: NOTE! Default branch is now main
[mesa-demos.git] / src / trivial / vp-tri-cb.c
blob19e1d2a240dcc5a45bc1e859186546c80428d673
1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
3 #include <assert.h>
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <glad/glad.h>
9 #include "glut_wrap.h"
11 static void Init( void )
13 GLint errnum;
14 GLuint prognum;
16 static const char *prog1 =
17 "!!ARBvp1.0\n"
18 "PARAM Diffuse = state.material.diffuse; \n"
19 "MOV result.color, Diffuse;\n"
20 "MOV result.position, vertex.position;\n"
21 "END\n";
23 const float Diffuse[4] = { 0.0, 1.0, 0.0, 1.0 };
24 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
27 glGenProgramsARB(1, &prognum);
29 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
30 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
31 strlen(prog1), (const GLubyte *) prog1);
33 assert(glIsProgramARB(prognum));
34 errnum = glGetError();
35 printf("glGetError = %d\n", errnum);
36 if (errnum != GL_NO_ERROR)
38 GLint errorpos;
40 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
41 printf("errorpos: %d\n", errorpos);
42 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
46 static void Display( void )
48 glClearColor(0.3, 0.3, 0.3, 1);
49 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
51 glEnable(GL_VERTEX_PROGRAM_NV);
53 glBegin(GL_TRIANGLES);
54 glColor3f(0,0,.7);
55 glVertex3f( 0.9, -0.9, -0.0);
56 glColor3f(.8,0,0);
57 glVertex3f( 0.9, 0.9, -0.0);
58 glColor3f(0,.9,0);
59 glVertex3f(-0.9, 0.0, -0.0);
60 glEnd();
63 glFlush();
67 static void Reshape( int width, int height )
69 glViewport( 0, 0, width, height );
70 glMatrixMode( GL_PROJECTION );
71 glLoadIdentity();
72 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
73 glMatrixMode( GL_MODELVIEW );
74 glLoadIdentity();
75 /*glTranslatef( 0.0, 0.0, -15.0 );*/
79 static void Key( unsigned char key, int x, int y )
81 (void) x;
82 (void) y;
83 switch (key) {
84 case 27:
85 exit(0);
86 break;
88 glutPostRedisplay();
94 int main( int argc, char *argv[] )
96 glutInit( &argc, argv );
97 glutInitWindowPosition( 0, 0 );
98 glutInitWindowSize( 250, 250 );
99 glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
100 glutCreateWindow(argv[0]);
101 gladLoadGL();
102 glutReshapeFunc( Reshape );
103 glutKeyboardFunc( Key );
104 glutDisplayFunc( Display );
105 Init();
106 glutMainLoop();
107 return 0;