blob: 1ae753c1d053b9a835ee574087bd26d15029e5f4 [file] [log] [blame]
Keith Whitwell28536e62006-08-24 17:48:53 +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 Whitwell28536e62006-08-24 17:48:53 +00006#include <GL/glut.h>
Keith Whitwell28536e62006-08-24 17:48:53 +00007
8
9
10static void Init( void )
11{
12 static const char *modulate2D =
13 "!!ARBfp1.0\n"
14 "MUL result.color, fragment.position, {.005}.x; \n"
15 "END"
16 ;
17 GLuint modulateProg;
18
José Fonsecae3f14f22009-06-11 13:19:34 +010019 if (!GLEW_ARB_fragment_program) {
Keith Whitwell28536e62006-08-24 17:48:53 +000020 printf("Error: GL_ARB_fragment_program not supported!\n");
21 exit(1);
22 }
23 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
24
25 /* Setup the fragment program */
26 glGenProgramsARB(1, &modulateProg);
27 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
28 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
29 strlen(modulate2D), (const GLubyte *)modulate2D);
30
31 printf("glGetError = 0x%x\n", (int) glGetError());
32 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
33 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
34
35 glEnable(GL_FRAGMENT_PROGRAM_ARB);
36
37 glClearColor(.3, .3, .3, 0);
38}
39
40static void Reshape(int width, int height)
41{
42
43 glViewport(0, 0, (GLint)width, (GLint)height);
44
45 glMatrixMode(GL_PROJECTION);
46 glLoadIdentity();
47 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
48 glMatrixMode(GL_MODELVIEW);
49}
50
51static void Key(unsigned char key, int x, int y)
52{
53
54 switch (key) {
55 case 27:
56 exit(1);
57 default:
Vinson Leecde66432009-11-18 14:41:40 -080058 break;
Keith Whitwell28536e62006-08-24 17:48:53 +000059 }
60
61 glutPostRedisplay();
62}
63
64static void Draw(void)
65{
66 glClear(GL_COLOR_BUFFER_BIT);
67
68#if 0
69 glBegin(GL_QUADS);
70 glTexCoord2f(1,0);
71 glVertex3f( 0.9, -0.9, -30.0);
72 glTexCoord2f(1,1);
73 glVertex3f( 0.9, 0.9, -30.0);
74 glTexCoord2f(0,1);
75 glVertex3f(-0.9, 0.9, -30.0);
76 glTexCoord2f(0,0);
77 glVertex3f(-0.9, -0.9, -30.0);
78 glEnd();
79#else
80 glPointSize(100);
81 glBegin(GL_POINTS);
82 glColor3f(0,0,1);
83 glVertex3f( 0, 0, -30.0);
84 glEnd();
85#endif
86
87 glFlush();
88
89
90}
91
92
93int main(int argc, char **argv)
94{
95 GLenum type;
96
97 glutInit(&argc, argv);
98
99
100
101 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
102
103 type = GLUT_RGB;
104 type |= GLUT_SINGLE;
105 glutInitDisplayMode(type);
106
107 if (glutCreateWindow("First Tri") == GL_FALSE) {
108 exit(1);
109 }
110
José Fonsecae3f14f22009-06-11 13:19:34 +0100111 glewInit();
112
Keith Whitwell28536e62006-08-24 17:48:53 +0000113 Init();
114
115 glutReshapeFunc(Reshape);
116 glutKeyboardFunc(Key);
117 glutDisplayFunc(Draw);
118 glutMainLoop();
119 return 0;
120}