2 * Just compile ARB vert/frag program from named file(s).
10 #include <glad/glad.h>
11 #include "glut_wrap.h"
14 static GLuint FragProg
;
15 static GLuint VertProg
;
19 static void Redisplay( void )
21 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
27 static void Reshape( int width
, int height
)
29 glViewport( 0, 0, width
, height
);
30 glMatrixMode( GL_PROJECTION
);
32 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
33 glMatrixMode( GL_MODELVIEW
);
35 glTranslatef( 0.0, 0.0, -15.0 );
39 static void Key( unsigned char key
, int x
, int y
)
45 glDeleteProgramsARB(1, &VertProg
);
46 glDeleteProgramsARB(1, &FragProg
);
47 glutDestroyWindow(Win
);
55 /* A helper for finding errors in program strings */
56 static int FindLine( const char *program
, int position
)
59 for (i
= 0; i
< position
; i
++) {
60 if (program
[i
] == '\n')
67 static void Init( const char *vertProgFile
,
68 const char *fragProgFile
)
73 if (!glutExtensionSupported("GL_ARB_vertex_program")) {
74 printf("Sorry, this demo requires GL_ARB_vertex_program\n");
77 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
78 printf("Sorry, this demo requires GL_ARB_fragment_program\n");
82 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
91 glGenProgramsARB(1, &VertProg
);
93 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, VertProg
);
95 f
= fopen(vertProgFile
, "r");
97 printf("Unable to open %s\n", fragProgFile
);
101 len
= fread(buf
, 1, 10*1000,f
);
104 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
,
105 GL_PROGRAM_FORMAT_ASCII_ARB
,
107 (const GLubyte
*) buf
);
109 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorPos
);
110 if (glGetError() != GL_NO_ERROR
|| errorPos
!= -1) {
111 int l
= FindLine(buf
, errorPos
);
112 printf("Vertex Program Error (pos=%d line=%d): %s\n", errorPos
, l
,
113 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
117 glEnable(GL_VERTEX_PROGRAM_ARB
);
118 printf("Vertex Program OK\n");
129 glGenProgramsARB(1, &FragProg
);
130 assert(FragProg
> 0);
131 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
);
133 f
= fopen(fragProgFile
, "r");
135 printf("Unable to open %s\n", fragProgFile
);
139 len
= fread(buf
, 1, 10*1000,f
);
142 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
,
143 GL_PROGRAM_FORMAT_ASCII_ARB
,
145 (const GLubyte
*) buf
);
147 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorPos
);
148 if (glGetError() != GL_NO_ERROR
|| errorPos
!= -1) {
149 int l
= FindLine(buf
, errorPos
);
150 printf("Fragment Program Error (pos=%d line=%d): %s\n", errorPos
, l
,
151 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
155 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
156 printf("Fragment Program OK\n");
162 int main( int argc
, char *argv
[] )
164 const char *vertProgFile
= NULL
, *fragProgFile
= NULL
;
167 glutInit( &argc
, argv
);
168 glutInitWindowPosition( 0, 0 );
169 glutInitWindowSize( 200, 200 );
170 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
171 Win
= glutCreateWindow(argv
[0]);
173 glutReshapeFunc( Reshape
);
174 glutKeyboardFunc( Key
);
175 glutDisplayFunc( Redisplay
);
178 printf("arbgpuprog:\n");
179 printf(" Compile GL_ARB_vertex/fragment_programs, report any errors.\n");
181 printf(" arbgpuprog [--vp vertprogfile] [--fp fragprogfile]\n");
185 for (i
= 1; i
< argc
; i
++) {
186 if (strcmp(argv
[i
], "--vp") == 0) {
187 vertProgFile
= argv
[i
+1];
190 else if (strcmp(argv
[i
], "--fp") == 0) {
191 fragProgFile
= argv
[i
+1];
196 Init(vertProgFile
, fragProgFile
);