blob: a1f0579c8e11d792ea86595c58115843d2b28af8 [file] [log] [blame]
Keith Whitwelle5166542005-10-21 18:34:22 +00001
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#define GL_GLEXT_PROTOTYPES
6#include <GL/glut.h>
7#include "GL/gl.h"
8
9
10
11static void Init( void )
12{
13 /* scale of 10.0 gives me a visible result on nv hardware.
14 */
15 static const char *modulate2D =
16 "!!ARBfp1.0\n"
17 "MUL result.color, fragment.position.z, {10.0}.x; \n"
18 "END"
19 ;
20 GLuint modulateProg;
21
22 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
23 printf("Error: GL_ARB_fragment_program not supported!\n");
24 exit(1);
25 }
26 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
27
28 /* Setup the fragment program */
29 glGenProgramsARB(1, &modulateProg);
30 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
31 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
32 strlen(modulate2D), (const GLubyte *)modulate2D);
33
34 printf("glGetError = 0x%x\n", (int) glGetError());
35 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
36 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
37
38 glEnable(GL_FRAGMENT_PROGRAM_ARB);
39
40 glClearColor(.3, .3, .3, 0);
41}
42
43static void Reshape(int width, int height)
44{
45
46 glViewport(0, 0, (GLint)width, (GLint)height);
47
48 glMatrixMode(GL_PROJECTION);
49 glLoadIdentity();
50 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
51 glMatrixMode(GL_MODELVIEW);
52}
53
54static void Key(unsigned char key, int x, int y)
55{
56
57 switch (key) {
58 case 27:
59 exit(1);
60 default:
61 return;
62 }
63
64 glutPostRedisplay();
65}
66
67static void Draw(void)
68{
69 glClear(GL_COLOR_BUFFER_BIT);
70
71 glBegin(GL_TRIANGLES);
72 glColor3f(0,0,1);
73 glVertex3f( 0.9, -0.9, -40.0);
74 glColor3f(1,0,0);
75 glVertex3f( 0.9, 0.9, -40.0);
76 glColor3f(0,1,0);
77 glVertex3f(-0.9, 0.0, -25.0);
78 glEnd();
79
80 glFlush();
81
82
83}
84
85
86int main(int argc, char **argv)
87{
88 GLenum type;
89
90 glutInit(&argc, argv);
91
92
93
94 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
95
96 type = GLUT_RGB;
97 type |= GLUT_SINGLE;
98 glutInitDisplayMode(type);
99
100 if (glutCreateWindow("First Tri") == GL_FALSE) {
101 exit(1);
102 }
103
104 Init();
105
106 glutReshapeFunc(Reshape);
107 glutKeyboardFunc(Key);
108 glutDisplayFunc(Draw);
109 glutMainLoop();
110 return 0;
111}