blob: 7e490fa61ca75049037f8792620c21d9b83ac0d6 [file] [log] [blame]
Keith Whitwella90909e2005-10-20 21:40:23 +00001
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
José Fonsecae3f14f22009-06-11 13:19:34 +01005#include <GL/glew.h>
Keith Whitwella90909e2005-10-20 21:40:23 +00006#include <GL/glut.h>
7
8
Keith Whitwella90909e2005-10-20 21:40:23 +00009
10static void Init( void )
11{
12 static const char *modulate2D =
13 "!!ARBfp1.0\n"
14 "TEMP R0;\n"
15 "INV result.color, fragment.color; \n"
16 "END"
17 ;
18 GLuint modulateProg;
19
José Fonsecae3f14f22009-06-11 13:19:34 +010020 if (!GLEW_ARB_fragment_program) {
Keith Whitwella90909e2005-10-20 21:40:23 +000021 printf("Error: GL_ARB_fragment_program not supported!\n");
22 exit(1);
23 }
24 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
25
26 /* Setup the fragment program */
27 glGenProgramsARB(1, &modulateProg);
28 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
29 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
30 strlen(modulate2D), (const GLubyte *)modulate2D);
31
32 printf("glGetError = 0x%x\n", (int) glGetError());
33 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
34 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
35
36 glEnable(GL_FRAGMENT_PROGRAM_ARB);
37
38 glClearColor(.3, .3, .3, 0);
39}
40
41static void Reshape(int width, int height)
42{
43
44 glViewport(0, 0, (GLint)width, (GLint)height);
45
46 glMatrixMode(GL_PROJECTION);
47 glLoadIdentity();
48 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
49 glMatrixMode(GL_MODELVIEW);
50}
51
52static void Key(unsigned char key, int x, int y)
53{
54
55 switch (key) {
56 case 27:
57 exit(1);
58 default:
Vinson Lee8d2f3432009-12-04 23:31:39 -080059 break;
Keith Whitwella90909e2005-10-20 21:40:23 +000060 }
61
62 glutPostRedisplay();
63}
64
65static void Draw(void)
66{
67 glClear(GL_COLOR_BUFFER_BIT);
68
69 glBegin(GL_TRIANGLES);
70 glColor3f(0,0,1);
71 glVertex3f( 0.9, -0.9, -30.0);
72 glColor3f(1,0,0);
73 glVertex3f( 0.9, 0.9, -30.0);
74 glColor3f(0,1,0);
75 glVertex3f(-0.9, 0.0, -30.0);
76 glEnd();
77
78 glFlush();
79
Keith Whitwellf28cbb62005-10-21 18:33:53 +000080
Keith Whitwella90909e2005-10-20 21:40:23 +000081}
82
Keith Whitwella90909e2005-10-20 21:40:23 +000083
84int main(int argc, char **argv)
85{
86 GLenum type;
87
88 glutInit(&argc, argv);
89
Keith Whitwellf28cbb62005-10-21 18:33:53 +000090
Keith Whitwella90909e2005-10-20 21:40:23 +000091
92 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
93
94 type = GLUT_RGB;
Keith Whitwellf28cbb62005-10-21 18:33:53 +000095 type |= GLUT_SINGLE;
Keith Whitwella90909e2005-10-20 21:40:23 +000096 glutInitDisplayMode(type);
97
98 if (glutCreateWindow("First Tri") == GL_FALSE) {
99 exit(1);
100 }
101
José Fonsecae3f14f22009-06-11 13:19:34 +0100102 glewInit();
103
Keith Whitwella90909e2005-10-20 21:40:23 +0000104 Init();
105
106 glutReshapeFunc(Reshape);
107 glutKeyboardFunc(Key);
108 glutDisplayFunc(Draw);
109 glutMainLoop();
110 return 0;
111}